diff options
Diffstat (limited to 'scripts/lib/wic/plugins/source/rootfs.py')
-rw-r--r-- | scripts/lib/wic/plugins/source/rootfs.py | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py index 9d959fa7d7..c57a4341d1 100644 --- a/scripts/lib/wic/plugins/source/rootfs.py +++ b/scripts/lib/wic/plugins/source/rootfs.py | |||
@@ -26,10 +26,13 @@ | |||
26 | # | 26 | # |
27 | 27 | ||
28 | import os | 28 | import os |
29 | import shutil | ||
30 | |||
31 | from oe.path import copyhardlinktree | ||
29 | 32 | ||
30 | from wic import msger | 33 | from wic import msger |
31 | from wic.pluginbase import SourcePlugin | 34 | from wic.pluginbase import SourcePlugin |
32 | from wic.utils.misc import get_bitbake_var | 35 | from wic.utils.misc import get_bitbake_var, exec_cmd |
33 | 36 | ||
34 | class RootfsPlugin(SourcePlugin): | 37 | class RootfsPlugin(SourcePlugin): |
35 | """ | 38 | """ |
@@ -78,6 +81,44 @@ class RootfsPlugin(SourcePlugin): | |||
78 | 81 | ||
79 | real_rootfs_dir = cls.__get_rootfs_dir(rootfs_dir) | 82 | real_rootfs_dir = cls.__get_rootfs_dir(rootfs_dir) |
80 | 83 | ||
84 | # Handle excluded paths. | ||
85 | if part.exclude_path is not None: | ||
86 | # We need a new rootfs directory we can delete files from. Copy to | ||
87 | # workdir. | ||
88 | new_rootfs = os.path.realpath(os.path.join(cr_workdir, "rootfs")) | ||
89 | |||
90 | if os.path.lexists(new_rootfs): | ||
91 | shutil.rmtree(os.path.join(new_rootfs)) | ||
92 | |||
93 | copyhardlinktree(real_rootfs_dir, new_rootfs) | ||
94 | |||
95 | real_rootfs_dir = new_rootfs | ||
96 | |||
97 | for orig_path in part.exclude_path: | ||
98 | path = orig_path | ||
99 | if os.path.isabs(path): | ||
100 | msger.error("Must be relative: --exclude-path=%s" % orig_path) | ||
101 | |||
102 | full_path = os.path.realpath(os.path.join(new_rootfs, path)) | ||
103 | |||
104 | # Disallow climbing outside of parent directory using '..', | ||
105 | # because doing so could be quite disastrous (we will delete the | ||
106 | # directory). | ||
107 | if not full_path.startswith(new_rootfs): | ||
108 | msger.error("'%s' points to a path outside the rootfs" % orig_path) | ||
109 | |||
110 | if path.endswith(os.sep): | ||
111 | # Delete content only. | ||
112 | for entry in os.listdir(full_path): | ||
113 | full_entry = os.path.join(full_path, entry) | ||
114 | if os.path.isdir(full_entry) and not os.path.islink(full_entry): | ||
115 | shutil.rmtree(full_entry) | ||
116 | else: | ||
117 | os.remove(full_entry) | ||
118 | else: | ||
119 | # Delete whole directory. | ||
120 | shutil.rmtree(full_path) | ||
121 | |||
81 | part.rootfs_dir = real_rootfs_dir | 122 | part.rootfs_dir = real_rootfs_dir |
82 | part.prepare_rootfs(cr_workdir, oe_builddir, | 123 | part.prepare_rootfs(cr_workdir, oe_builddir, |
83 | real_rootfs_dir, native_sysroot) | 124 | real_rootfs_dir, native_sysroot) |