All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] wic: Add --exclude-path option to rootfs source plugin.
@ 2016-11-25 10:15 Kristian Amlie
  2016-11-25 10:33 ` Patrick Ohly
                   ` (3 more replies)
  0 siblings, 4 replies; 48+ messages in thread
From: Kristian Amlie @ 2016-11-25 10:15 UTC (permalink / raw)
  To: openembedded-core

It will omit the given path from the resulting partition, and if the
given path ends in a slash, it will only delete the content, and keep
the directory.

Since mkfs only accepts whole directories as input, we need to copy
the rootfs directory to the workdir so that we can selectively delete
files from it.

Signed-off-by: Kristian Amlie <kristian.amlie@mender.io>
---
 scripts/lib/wic/help.py                  |  6 ++++
 scripts/lib/wic/ksparser.py              |  1 +
 scripts/lib/wic/partition.py             |  1 +
 scripts/lib/wic/plugins/source/rootfs.py | 51 +++++++++++++++++++++++++++++++-
 4 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/scripts/lib/wic/help.py b/scripts/lib/wic/help.py
index e5347ec..9dab670 100644
--- a/scripts/lib/wic/help.py
+++ b/scripts/lib/wic/help.py
@@ -715,6 +715,12 @@ DESCRIPTION
                      partition table. It may be useful for
                      bootloaders.
 
+         --exclude-path: This option is specific to wic. It excludes the given
+                         absolute path from the resulting image. If the path
+                         ends with a slash, only the content of the directory
+                         is omitted, not the directory itself. This option only
+                         has an effect with the rootfs source plugin.
+
          --extra-space: This option is specific to wic. It adds extra
                         space after the space filled by the content
                         of the partition. The final size can go
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
index 0894e2b..17b97fd0 100644
--- a/scripts/lib/wic/ksparser.py
+++ b/scripts/lib/wic/ksparser.py
@@ -127,6 +127,7 @@ class KickStart():
         part.add_argument('mountpoint', nargs='?')
         part.add_argument('--active', action='store_true')
         part.add_argument('--align', type=int)
+        part.add_argument('--exclude-path', nargs='+')
         part.add_argument("--extra-space", type=sizetype, default=10*1024)
         part.add_argument('--fsoptions', dest='fsopts')
         part.add_argument('--fstype')
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index ac4c836..cba78a5 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -45,6 +45,7 @@ class Partition():
         self.align = args.align
         self.disk = args.disk
         self.extra_space = args.extra_space
+        self.exclude_path = args.exclude_path
         self.fsopts = args.fsopts
         self.fstype = args.fstype
         self.label = args.label
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py
index 425da8b..d97d99c 100644
--- a/scripts/lib/wic/plugins/source/rootfs.py
+++ b/scripts/lib/wic/plugins/source/rootfs.py
@@ -26,10 +26,11 @@
 #
 
 import os
+import shutil
 
 from wic import msger
 from wic.pluginbase import SourcePlugin
-from wic.utils.oe.misc import get_bitbake_var
+from wic.utils.oe.misc import get_bitbake_var, exec_cmd
 
 class RootfsPlugin(SourcePlugin):
     """
@@ -78,6 +79,54 @@ class RootfsPlugin(SourcePlugin):
 
         real_rootfs_dir = cls.__get_rootfs_dir(rootfs_dir)
 
+        # Handle excluded paths.
+        if part.exclude_path is not None:
+            # We need a new rootfs directory we can delete files from. Copy to
+            # workdir.
+            new_rootfs = os.path.join(cr_workdir, "rootfs")
+
+            if os.path.lexists(new_rootfs):
+                shutil.rmtree(os.path.join(new_rootfs))
+
+            if os.stat(real_rootfs_dir).st_dev == os.stat(cr_workdir).st_dev:
+                # Optimization if both directories are on the same file system:
+                # copy using hardlinks.
+                cp_args = "-al"
+            else:
+                cp_args = "-a"
+            exec_cmd("cp %s %s %s" % (cp_args, real_rootfs_dir, new_rootfs))
+
+            real_rootfs_dir = new_rootfs
+
+            for orig_path in part.exclude_path:
+                path = orig_path
+                if not os.path.isabs(path):
+                    msger.error("Must be absolute: --exclude-path=%s" % orig_path)
+
+                while os.path.isabs(path):
+                    path = path[1:]
+
+                # Disallow '..', because doing so could be quite disastrous
+                # (we will delete the directory).
+                remaining = path
+                while True:
+                    (head, tail) = os.path.split(remaining)
+                    if tail == '..':
+                        msger.error("'..' not allowed: --exclude-path=%s" % orig_path)
+                    elif head == "":
+                        break
+                    remaining = head
+
+                full_path = os.path.join(new_rootfs, path)
+
+                if path.endswith(os.sep):
+                    # Delete content only.
+                    for entry in os.listdir(full_path):
+                        shutil.rmtree(os.path.join(full_path, entry))
+                else:
+                    # Delete whole directory.
+                    shutil.rmtree(full_path)
+
         part.rootfs_dir = real_rootfs_dir
         part.prepare_rootfs(cr_workdir, oe_builddir, real_rootfs_dir, native_sysroot)
 
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2017-02-07  7:23 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-25 10:15 [PATCH v1] wic: Add --exclude-path option to rootfs source plugin Kristian Amlie
2016-11-25 10:33 ` Patrick Ohly
2016-11-25 12:07   ` Kristian Amlie
2016-11-25 16:31     ` Ed Bartosh
2016-11-28  7:15       ` Kristian Amlie
2016-11-28 10:52         ` Ed Bartosh
2016-11-28 11:01           ` Kristian Amlie
2016-11-28 11:18             ` Ed Bartosh
2016-11-30 13:30               ` Kristian Amlie
2016-11-30 13:37                 ` Maciej Borzęcki
2016-11-30 15:29                 ` Ed Bartosh
2016-11-30 19:29                   ` Paul Eggleton
2016-12-02 14:36                   ` Kristian Amlie
2016-12-02 15:05                     ` Ed Bartosh
2016-12-05 10:23                       ` Kristian Amlie
2016-12-14 16:28               ` [PATCH v2] " Kristian Amlie
2016-12-14 16:28                 ` [PATCH v2 1/3] " Kristian Amlie
2016-12-14 16:28                 ` [PATCH v2 2/3] Add e2tools recipe, in order to test contents of images Kristian Amlie
2016-12-14 16:28                 ` [PATCH v2 3/3] selftest/wic: Add tests for --exclude-dir option Kristian Amlie
2016-12-16 14:44                   ` Ed Bartosh
2016-12-19  9:09                     ` Kristian Amlie
2016-12-19  9:09                       ` [PATCH v3 1/3] wic: Add --exclude-path option to rootfs source plugin Kristian Amlie
2016-12-19  9:09                       ` [PATCH v3 2/3] Add e2tools recipe, in order to test contents of images Kristian Amlie
2016-12-19  9:09                       ` [PATCH v3 3/3] selftest/wic: Add tests for --exclude-dir option Kristian Amlie
2016-12-19 20:49                         ` Burton, Ross
2016-12-20  9:20                           ` Kristian Amlie
2016-12-29 10:05                           ` Kristian Amlie
2016-12-29 10:05                             ` [PATCH v4 1/2] wic: Add --exclude-path option to rootfs source plugin Kristian Amlie
2016-12-29 10:05                             ` [PATCH v4 2/2] selftest/wic: Add tests for --exclude-dir option Kristian Amlie
2016-12-29 10:23                               ` Kristian Amlie
2016-12-29 14:03                                 ` Kristian Amlie
2016-12-29 14:03                                   ` [PATCH v5 1/2] wic: Add --exclude-path option to rootfs source plugin Kristian Amlie
2016-12-29 14:03                                   ` [PATCH v5 2/2] selftest/wic: Add tests for --exclude-dir option Kristian Amlie
2017-01-16  9:05                                   ` [PATCH v4 " Kristian Amlie
2017-02-06 16:16                                     ` Kristian Amlie
2017-02-06 16:16                                       ` [PATCH 1/2] wic: Add --exclude-path option to rootfs source plugin Kristian Amlie
2017-02-06 16:16                                       ` [PATCH 2/2] selftest/wic: Add tests for --exclude-dir option Kristian Amlie
2017-02-06 16:38                                       ` [PATCH v4 " Ed Bartosh
2016-12-19 11:57                       ` [PATCH v2 3/3] " Ed Bartosh
2016-11-25 12:28 ` [PATCH v1] wic: Add --exclude-path option to rootfs source plugin Maciej Borzęcki
2016-11-25 12:35   ` Kristian Amlie
2016-11-25 16:33     ` Ed Bartosh
2016-11-28  7:07       ` Kristian Amlie
2016-11-28 10:46         ` Ed Bartosh
2016-11-28 11:00           ` Kristian Amlie
2017-02-06 16:29 ` ✗ patchtest: failure for wic: Add --exclude-path option to rootfs source plugin. (rev10) Patchwork
2017-02-06 16:29 ` ✗ patchtest: failure for wic: Add --exclude-path option to rootfs source plugin. (rev11) Patchwork
2017-02-07  7:23   ` Kristian Amlie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.