Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wic ln command to create a symbolic link to a file #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions scripts/lib/wic/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,23 @@ def copy(self, src, dest):
exec_cmd(cmd, as_shell=True)
self._put_part_image(pnum)

def link(self, src, dest):
"""Create a symbolic link to a file in wic image."""
pnum = dest.part

if pnum not in self.partitions:
raise WicError("Partition %s is not in the image" % pnum)

if self.partitions[pnum].fstype.startswith('ext'):
cmd = "printf 'cd {}\nsymlink {} {}\n' | {} -w {}".\
format(os.path.dirname(dest.path), os.path.basename(src),
src, self.debugfs, self._get_part_image(pnum))
else: # fat
print("Not support the fat file system!")

exec_cmd(cmd, as_shell=True)
self._put_part_image(pnum)

def remove_ext(self, pnum, path, recursive):
"""
Remove files/dirs and their contents from the partition.
Expand Down Expand Up @@ -579,6 +596,13 @@ def wic_cp(args, native_sysroot):
disk = Disk(args.dest.image, native_sysroot)
disk.copy(args.src, args.dest)

def wic_ln(args, native_sysroot):
"""
Create file's Symbolic link in ext partition of
partitioned image.
"""
disk = Disk(args.dest.image, native_sysroot)
disk.link(args.src, args.dest)

def wic_rm(args, native_sysroot):
"""
Expand Down
44 changes: 44 additions & 0 deletions scripts/lib/wic/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,49 @@ def invoke_subcommand(args, parser, main_command_usage, subcommands):
details.
"""

wic_ln_usage = """

Create a symboilic link to a file or dir in partitioned image

usage: wic ln <path> <image>:<ext* partition><path>

This command a symbolic link to a file or dir in ext* partitions.

See 'wic help ls' for more detailed instructions.

"""

wic_ln_help = """

NAME
wic ln - Create a symboilic link to a file or dir in partitioned image

SYNOPSIS
wic ln <file> <image>:<ext* partition><path>
wic ln <file> <image>:<ext* partition><path> --native-sysroot <path>

DESCRIPTION
This command a symbolic link to a file or dir in ext* partitions.

For example:
$ wic ls test.rootfs.wic:2/bin/ | grep sdbus

$ wic ls test.rootfs.wic:2/usr/bin/ | grep sdbus
6224 100775 (1) 0 0 61536 30-Mar-2023 14:45 sdbus-service
6255 100775 (1) 0 0 42352 29-Mar-2023 13:42 sdbus-client
6269 100775 (1) 0 0 19848 29-Mar-2023 10:52 sdbus-demo

To create a symbolic link
$ wic ln /usr/bin/sdbus-service test.rootfs.wic:2/bin/

$ wic ls test.rootfs.wic:2/bin/ | grep sdbus
6254 120777 (7) 0 0 22 6-May-2023 10:44 sdbus-service

The -n option is used to specify the path to the native sysroot
containing the tools(parted and mtools) to use.

"""

wic_ls_usage = """

List content of a partitioned image
Expand Down Expand Up @@ -1108,6 +1151,7 @@ class (see the SourcePlugin source for details):

list - List available canned images and source plugins
ls - List contents of partitioned image or partition
ln - Create a symbolic link to a file in ext* partitions
rm - Remove files or directories from the vfat or ext* partitions
help - Show help for a wic COMMAND or TOPIC
write - Write an image to a device
Expand Down
26 changes: 26 additions & 0 deletions scripts/wic
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ def wic_list_subcommand(args, usage_str):
if not engine.wic_list(args, scripts_path):
raise WicError("Bad list arguments, exiting")

def wic_ln_subcommand(args, usage_str):
"""
Command-line handling for creating a symbilic link to a file/dir in images.
The real work is done by engine.wic_ln()
"""
engine.wic_ln(args, args.native_sysroot)

def wic_ls_subcommand(args, usage_str):
"""
Expand Down Expand Up @@ -292,6 +298,9 @@ helptopics = {
"create": [wic_help_topic_subcommand,
wic_help_topic_usage,
hlp.wic_create_help],
"ln": [wic_help_topic_subcommand,
wic_help_topic_usage,
hlp.wic_ln_help],
"ls": [wic_help_topic_subcommand,
wic_help_topic_usage,
hlp.wic_ls_help],
Expand Down Expand Up @@ -391,6 +400,14 @@ def wic_init_parser_ls(subparser):
subparser.add_argument("-n", "--native-sysroot",
help="path to the native sysroot containing the tools")

def wic_init_parser_ln(subparser):
subparser.add_argument("src",
help="<file>")
subparser.add_argument("dest",
help="image spec: <image>:<ext* partition>[<path>]")
subparser.add_argument("-n", "--native-sysroot",
help="path to the native sysroot containing the tools")

def imgpathtype(arg):
img = imgtype(arg)
if img.part is None:
Expand Down Expand Up @@ -471,6 +488,10 @@ subcommands = {
hlp.wic_list_usage,
hlp.wic_list_help,
wic_init_parser_list],
"ln": [wic_ln_subcommand,
hlp.wic_ln_usage,
hlp.wic_ln_help,
wic_init_parser_ln],
"ls": [wic_ls_subcommand,
hlp.wic_ls_usage,
hlp.wic_ls_help,
Expand Down Expand Up @@ -538,6 +559,11 @@ def main(argv):
args.src = imgtype(args.src)
else:
raise argparse.ArgumentTypeError("no image or partition number specified.")
elif args.command == "ln":
if ":" in args.dest:
args.dest = imgtype(args.dest)
else:
raise argparse.ArgumentTypeError("no image or partition number specified.")

return hlp.invoke_subcommand(args, parser, hlp.wic_help_usage, subcommands)

Expand Down