summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/plugins/source
diff options
context:
space:
mode:
authorRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>2020-04-19 08:35:31 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-04-26 13:58:45 +0100
commit2265d089a58e1f78f26d623ee667c420cb1c3bd4 (patch)
tree1626babdbc989184a17b54281fdde7a41856d2b7 /scripts/lib/wic/plugins/source
parentdde90a5dd2b22a539095d1bac82acc15c6380ac8 (diff)
downloadopenembedded-core-contrib-2265d089a58e1f78f26d623ee667c420cb1c3bd4.tar.gz
wic: Add --change-directory argument
This option allows to specify which part of a rootfs is going to be included, the same way the -C argument on tar. Thanks to this option we can make sure the permissions and usernames on the target partition are respected, and also simplify the creation of splitted partitons, not neeting to invoke external vars or using .wks.in files. Eg: part / --source rootfs --ondisk sda --fstype=ext4 --exclude-path=etc/    part /etc --source rootfs --fstype=ext4 --change-directory=etc Cc: Paul Barker <pbarker@konsulko.com> Signed-off-by: Ricardo Ribalda Delgado <ricardo@ribalda.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic/plugins/source')
-rw-r--r--scripts/lib/wic/plugins/source/rootfs.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py
index 8b2a067385..85c634f8a1 100644
--- a/scripts/lib/wic/plugins/source/rootfs.py
+++ b/scripts/lib/wic/plugins/source/rootfs.py
@@ -86,14 +86,29 @@ class RootfsPlugin(SourcePlugin):
new_rootfs = None
new_pseudo = None
# Handle excluded paths.
- if part.exclude_path or part.include_path:
+ if part.exclude_path or part.include_path or part.change_directory:
# We need a new rootfs directory we can delete files from. Copy to
# workdir.
new_rootfs = os.path.realpath(os.path.join(cr_workdir, "rootfs%d" % part.lineno))
if os.path.lexists(new_rootfs):
shutil.rmtree(os.path.join(new_rootfs))
- copyhardlinktree(part.rootfs_dir, new_rootfs)
+
+ if part.change_directory:
+ cd = part.change_directory
+ if cd[-1] == '/':
+ cd = cd[:-1]
+ if os.path.isabs(cd):
+ logger.error("Must be relative: --change-directory=%s" % cd)
+ sys.exit(1)
+ orig_dir = os.path.realpath(os.path.join(part.rootfs_dir, cd))
+ if not orig_dir.startswith(part.rootfs_dir):
+ logger.error("'%s' points to a path outside the rootfs" % orig_dir)
+ sys.exit(1)
+
+ else:
+ orig_dir = part.rootfs_dir
+ copyhardlinktree(orig_dir, new_rootfs)
# Convert the pseudo directory to its new location
if (pseudo_dir):
@@ -108,7 +123,7 @@ class RootfsPlugin(SourcePlugin):
pseudo_cmd = "%s -B -m %s -M %s" % (cls.__get_pseudo(native_sysroot,
new_rootfs,
new_pseudo),
- part.rootfs_dir, new_rootfs)
+ orig_dir, new_rootfs)
exec_native_cmd(pseudo_cmd, native_sysroot)
for path in part.include_path or []: