#11283: wic rm
cover #11283: wic rm
Hi,
This is an implementation of new wic subcommand 'wic rm'.
It removes files or directories from vfat partitions:
$ wic ls ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1 Volume in drive : is boot Volume Serial Number is 11D0-DE21 Directory for ::/
libcom32 c32 186500 2017-06-02 15:15 libutil c32 24148 2017-06-02 15:15 syslinux cfg 209 2017-06-02 15:15 vesamenu c32 27104 2017-06-02 15:15 vmlinuz 6926384 2017-06-02 15:15
5 files 7 164 345 bytes
16 582 656 bytes free
$ wic rm ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/libutil.c32
$ wic ls ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1 Volume in drive : is boot Volume Serial Number is 11D0-DE21 Directory for ::/
libcom32 c32 186500 2017-06-02 15:15 syslinux cfg 209 2017-06-02 15:15 vesamenu c32 27104 2017-06-02 15:15 vmlinuz 6926384 2017-06-02 15:15
4 files 7 140 197 bytes
16 607 232 bytes free
The patchset also contains test case for 'wic rm' functionality.
The following changes since commit 4cf2ac543ee3646332e8dac847d23429b492494c:
image_types_wic: schedule prepare_wic_build correctly (2017-06-02 11:21:49 +0300)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib ed/wic/wip
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=ed/wic/wip
Ed Bartosh (6):
wic: add wic_init_parser_rm
wic: add help and usage content for 'wic rm'
wic: add 'wic rm' command
wic: implement removing files
wic: implement removing directories
selftest: add test_wic_rm test case
meta/lib/oeqa/selftest/wic.py | 28 ++++++++++++++++++++ scripts/lib/wic/engine.py | 35 +++++++++++++++++++++++++ scripts/lib/wic/help.py | 59 ++++++++++++++++++++++++++++++++++++++++++- scripts/wic | 20 +++++++++++++++ 4 files changed, 141 insertions(+), 1 deletion(-)
Signature · 1 line
2.1.4
PATCH 1/6 wic: add wic_init_parser_rm
Add parser for 'wic rm' subcommand.
--- scripts/wic | 6 ++++++ 1 file changed, 6 insertions(+)
scripts/wic +6 -0
@@ -379,6 +379,12 @@ def wic_init_parser_cp(subparser): subparser.add_argument("-n", "--native-sysroot", help="path to the native sysroot containing the tools") +def wic_init_parser_rm(subparser): + subparser.add_argument("path", type=imgpathtype, + help="path: <image>:<vfat partition><path>") + subparser.add_argument("-n", "--native-sysroot", + help="path to the native sysroot containing the tools") + def wic_init_parser_help(subparser): helpparsers = subparser.add_subparsers(dest='help_topic', help=hlp.wic_usage) for helptopic in helptopics:
Signature · 1 line
2.1.4
PATCH 3/6 wic: add 'wic rm' command
In reply to Ed BartoshAdded empty 'wic rm' command that does nothing. The functionality will be added by the next commits.
[YOCTO #11283]
--- scripts/lib/wic/engine.py | 7 +++++++ scripts/wic | 14 ++++++++++++++ 2 files changed, 21 insertions(+)
scripts/lib/wic/engine.py +7 -0
@@ -340,6 +340,13 @@ def wic_cp(args, native_sysroot): disk = Disk(args.dest.image, native_sysroot) disk.copy(args.src, args.dest.part, args.dest.path) +def wic_rm(args, native_sysroot): + """ + Remove files or directories from the vfat partition of + partitioned image. + """ + pass + def find_canned(scripts_path, file_name): """ Find a file either by its path or by name in the canned files dir.
scripts/wic +14 -0
@@ -248,6 +248,13 @@ def wic_cp_subcommand(args, usage_str): """ engine.wic_cp(args, args.native_sysroot) +def wic_rm_subcommand(args, usage_str): + """ + Command-line handling for removing files/dirs from images. + The real work is done by engine.wic_rm() + """ + engine.wic_rm(args, args.native_sysroot) + def wic_help_subcommand(args, usage_str): """ Command-line handling for help subcommand to keep the current
@@ -286,6 +293,9 @@ helptopics = { "cp": [wic_help_topic_subcommand, wic_help_topic_usage, hlp.wic_cp_help], + "rm": [wic_help_topic_subcommand, + wic_help_topic_usage, + hlp.wic_rm_help], "list": [wic_help_topic_subcommand, wic_help_topic_usage, hlp.wic_list_help]
@@ -409,6 +419,10 @@ subcommands = { hlp.wic_cp_usage, hlp.wic_cp_help, wic_init_parser_cp], + "rm": [wic_rm_subcommand, + hlp.wic_rm_usage, + hlp.wic_rm_help, + wic_init_parser_rm], "help": [wic_help_subcommand, wic_help_topic_usage, hlp.wic_help_help,
Signature · 1 line
2.1.4
PATCH 5/6 wic: implement removing directories
In reply to Ed BartoshAdded support for removing directories using mdeltree utility to Disk.del method
[YOCTO #11283]
--- scripts/lib/wic/engine.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
scripts/lib/wic/engine.py +18 -4
@@ -239,6 +239,7 @@ class Disk: self._mdir = None self._mcopy = None self._mdel = None + self._mdeltree = None self._partimages = {} # find parted
@@ -290,6 +291,10 @@ class Disk: def mdel(self): return self._prop("mdel") + @property + def mdeltree(self): + return self._prop("mdeltree") + def _get_part_image(self, pnum): if pnum not in self.partitions: raise WicError("Partition %s is not in the image")
@@ -325,10 +330,19 @@ class Disk: def remove(self, pnum, path): """Remove files/dirs from the partition.""" - cmd = "{} -i {} ::{}".format(self.mdel, - self._get_part_image(pnum), - path) - exec_cmd(cmd) + partimg = self._get_part_image(pnum) + cmd = "{} -i {} ::{}".format(self.mdel, partimg, path) + try: + exec_cmd(cmd) + except WicError as err: + if "not found" in str(err) or "non empty" in str(err): + # mdel outputs 'File ... not found' or 'directory .. non empty" + # try to use mdeltree as path could be a directory + cmd = "{} -i {} ::{}".format(self.mdeltree, + partimg, path) + exec_cmd(cmd) + else: + raise err self._put_part_image(pnum) def wic_ls(args, native_sysroot):
Signature · 1 line
2.1.4
PATCH 6/6 selftest: add test_wic_rm test case
In reply to Ed BartoshAdded test case for "wic rm" functionality.
- remove file from vfat partition
- remove directory from vfat partition
--- meta/lib/oeqa/selftest/wic.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
meta/lib/oeqa/selftest/wic.py +28 -0
@@ -889,3 +889,31 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r self.assertEqual(0, result.status) self.assertEqual(8, len(result.output.split('\n'))) self.assertTrue(os.path.basename(testdir) in result.output) + + def test_wic_rm(self): + """Test removing files and directories from the the wic image.""" + self.assertEqual(0, runCmd("wic create mkefidisk " + "--image-name=core-image-minimal " + "-D -o %s" % self.resultdir).status) + images = glob(self.resultdir + "mkefidisk-*.direct") + self.assertEqual(1, len(images)) + + sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') + + # list directory content of the first partition + result = runCmd("wic ls %s:1 -n %s" % (images[0], sysroot)) + self.assertEqual(0, result.status) + self.assertEqual(8, len(result.output.split('\n'))) + + # remove file + result = runCmd("wic rm %s:1/bzimage -n %s" % (images[0], sysroot)) + self.assertEqual(0, result.status) + + # remove directory + result = runCmd("wic rm %s:1/efi -n %s" % (images[0], sysroot)) + self.assertEqual(0, result.status) + + # check if they're removed + result = runCmd("wic ls %s:1 -n %s" % (images[0], sysroot)) + self.assertEqual(0, result.status) + self.assertEqual(6, len(result.output.split('\n')))
Signature · 1 line
2.1.4
PATCH 2/6 wic: add help and usage content for 'wic rm'
In reply to Ed BartoshAdded wic_rm_help and wic_rm_usage variables to help.py. These variables contain help content that will be used in 'wic rm help' and 'wic rm --help' output.
--- scripts/lib/wic/help.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-)
scripts/lib/wic/help.py +58 -1
@@ -395,7 +395,7 @@ DESCRIPTION The second form of the command copies file or directory to the specified directory on the vfat partition: $ wic cp test tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/efi/ - $ wic ls tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/eti/ + $ wic ls tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/efi/ Volume in drive : is boot Volume Serial Number is DB4C-FD4C Directory for ::/efi
@@ -411,6 +411,63 @@ DESCRIPTION containing the tools(parted and mtools) to use. """ +wic_rm_usage = """ + + Remove files or directories from the vfat partitions + + usage: wic rm <image>:<vfat partition><path> [--native-sysroot <path>] + + This command removes files or directories from the vfat partitions of partitioned + image. + + See 'wic help rm' for more detailed instructions. + +""" + +wic_rm_help = """ + +NAME + wic rm - remove files or directories from the vfat partitions + +SYNOPSIS + wic rm <src> <image>:<vfat partition><path> + wic rm <src> <image>:<vfat partition><path> --native-sysroot <path> + +DESCRIPTION + This command removes files or directories from the vfat partition of the + wic image: + + $ wic ls ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1 + Volume in drive : is boot + Volume Serial Number is 11D0-DE21 + Directory for ::/ + + libcom32 c32 186500 2017-06-02 15:15 + libutil c32 24148 2017-06-02 15:15 + syslinux cfg 209 2017-06-02 15:15 + vesamenu c32 27104 2017-06-02 15:15 + vmlinuz 6926384 2017-06-02 15:15 + 5 files 7 164 345 bytes + 16 582 656 bytes free + + $ wic rm ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/libutil.c32 + + $ wic ls ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1 + Volume in drive : is boot + Volume Serial Number is 11D0-DE21 + Directory for ::/ + + libcom32 c32 186500 2017-06-02 15:15 + syslinux cfg 209 2017-06-02 15:15 + vesamenu c32 27104 2017-06-02 15:15 + vmlinuz 6926384 2017-06-02 15:15 + 4 files 7 140 197 bytes + 16 607 232 bytes free + + The -n option is used to specify the path to the native sysroot + containing the tools(parted and mtools) to use. +""" + wic_plugins_help = """ NAME
Signature · 1 line
2.1.4
PATCH 4/6 wic: implement removing files
In reply to Ed BartoshAdded implementation of Disk.del method and wic_r function that removes files from the vfat partition using mdel utility.
[YOCTO #11283]
--- scripts/lib/wic/engine.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
scripts/lib/wic/engine.py +15 -1
@@ -238,6 +238,7 @@ class Disk: self._partitions = None self._mdir = None self._mcopy = None + self._mdel = None self._partimages = {} # find parted
@@ -285,6 +286,10 @@ class Disk: def mcopy(self): return self._prop("mcopy") + @property + def mdel(self): + return self._prop("mdel") + def _get_part_image(self, pnum): if pnum not in self.partitions: raise WicError("Partition %s is not in the image")
@@ -318,6 +323,14 @@ class Disk: exec_cmd(cmd) self._put_part_image(pnum) + def remove(self, pnum, path): + """Remove files/dirs from the partition.""" + cmd = "{} -i {} ::{}".format(self.mdel, + self._get_part_image(pnum), + path) + exec_cmd(cmd) + self._put_part_image(pnum) + def wic_ls(args, native_sysroot): """List contents of partitioned image or vfat partition.""" disk = Disk(args.path.image, native_sysroot)
@@ -345,7 +358,8 @@ def wic_rm(args, native_sysroot): Remove files or directories from the vfat partition of partitioned image. """ - pass + disk = Disk(args.path.image, native_sysroot) + disk.remove(args.path.part, args.path.path) def find_canned(scripts_path, file_name): """
Signature · 1 line
2.1.4
✗ patchtest: failure for #11283: wic rm
In reply to Ed Bartosh== Series Details ==
Series: #11283: wic rm
Revision: 1
URL : https://patchwork.openembedded.org/series/7046/
State : failure
== Summary ==
Thank you for submitting this patch series to OpenEmbedded Core. This is an automated response. Several tests have been executed on the proposed series by patchtest resulting in the following failures:
* Issue Series does not apply on top of target branch [test_series_merge_on_head]
Suggested fix Rebase your series on top of targeted branch
Targeted branch master (currently at bafb7e221d)
If you believe any of these test results are incorrect, please reply to the mailing list ([email protected]) raising your concerns. Otherwise we would appreciate you correcting the issues and submitting a new version of the patchset if applicable. Please ensure you add/increment the version number when sending the new version (i.e. [PATCH] -> [PATCH v2] -> [PATCH v3] -> ...).
---
Test framework: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest Test suite: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest-oe