mirror of
https://git.yoctoproject.org/poky
synced 2026-06-04 14:09:47 +00:00
wic/engine: fix copying directories into wic image with ext* partition
wic uses debugfs to write on ext* partitions, but debugfs can only
write to the current working directory and it cannot copy complete
directory trees. Running 'wic ls' on a copied directory show this:
-l: Ext2 inode is not a directory
Fix this by creating a command list for debugfs (-f parameter) when
recursive parsing the host directory in order to create a similar
directory structure (mkdir) and copy files (write) on each level
into the destination directory from the wic's ext* partition.
(From OE-Core rev: 67f08884b98576c06db8db01b093ebeee760aba0)
Signed-off-by: Daniel Dragomir <daniel.dragomir@windriver.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 1ed38aff5f810d064c87aff9cbd310906833b6ba)
Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
Signed-off-by: Paul Barker <paul@pbarker.dev>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
df890007b4
commit
6c2a243d6c
+49
-14
@@ -327,29 +327,64 @@ class Disk:
|
|||||||
path))
|
path))
|
||||||
|
|
||||||
def copy(self, src, dest):
|
def copy(self, src, dest):
|
||||||
"""Copy partition image into wic image."""
|
"""Copy files or directories to/from the vfat or ext* partition."""
|
||||||
pnum = dest.part if isinstance(src, str) else src.part
|
pnum = dest.part if isinstance(src, str) else src.part
|
||||||
|
partimg = self._get_part_image(pnum)
|
||||||
|
|
||||||
if self.partitions[pnum].fstype.startswith('ext'):
|
if self.partitions[pnum].fstype.startswith('ext'):
|
||||||
if isinstance(src, str):
|
if isinstance(src, str): # host to image case
|
||||||
cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
|
if os.path.isdir(src):
|
||||||
format(os.path.dirname(dest.path), src, os.path.basename(src),
|
base = os.path.abspath(src)
|
||||||
self.debugfs, self._get_part_image(pnum))
|
base_parent = os.path.dirname(base)
|
||||||
else: # copy from wic
|
cmds = []
|
||||||
# run both dump and rdump to support both files and directory
|
made = set()
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(base):
|
||||||
|
for fname in files:
|
||||||
|
host_file = os.path.join(root, fname)
|
||||||
|
rel = os.path.relpath(host_file, base_parent)
|
||||||
|
dest_file = os.path.join(dest.path, rel)
|
||||||
|
dest_dir = os.path.dirname(dest_file)
|
||||||
|
|
||||||
|
# create dir structure (mkdir -p)
|
||||||
|
parts = dest_dir.strip('/').split('/')
|
||||||
|
cur = ''
|
||||||
|
for p in parts:
|
||||||
|
cur = cur + '/' + p
|
||||||
|
if cur not in made:
|
||||||
|
cmds.append(f'mkdir "{cur}"')
|
||||||
|
made.add(cur)
|
||||||
|
|
||||||
|
cmds.append(f'write "{host_file}" "{dest_file}"')
|
||||||
|
|
||||||
|
# write script to a temp file
|
||||||
|
with tempfile.NamedTemporaryFile(mode='w', delete=False,
|
||||||
|
prefix='wic-debugfs-') as tf:
|
||||||
|
for line in cmds:
|
||||||
|
tf.write(line + '\n')
|
||||||
|
scriptname = tf.name
|
||||||
|
|
||||||
|
cmd = f"{self.debugfs} -w -f {scriptname} {partimg}"
|
||||||
|
|
||||||
|
else: # single file
|
||||||
|
cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
|
||||||
|
format(os.path.dirname(dest.path), src,
|
||||||
|
os.path.basename(src), self.debugfs, partimg)
|
||||||
|
|
||||||
|
else: # image to host case
|
||||||
cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\
|
cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\
|
||||||
format(os.path.dirname(src.path), src.path,
|
format(os.path.dirname(src.path), src.path,
|
||||||
dest, src.path, dest, self.debugfs,
|
dest, src.path, dest, self.debugfs, partimg)
|
||||||
self._get_part_image(pnum))
|
|
||||||
else: # fat
|
else: # fat
|
||||||
if isinstance(src, str):
|
if isinstance(src, str):
|
||||||
cmd = "{} -i {} -snop {} ::{}".format(self.mcopy,
|
cmd = "{} -i {} -snop {} ::{}".format(self.mcopy,
|
||||||
self._get_part_image(pnum),
|
partimg,
|
||||||
src, dest.path)
|
src, dest.path)
|
||||||
else:
|
else:
|
||||||
cmd = "{} -i {} -snop ::{} {}".format(self.mcopy,
|
cmd = "{} -i {} -snop ::{} {}".format(self.mcopy,
|
||||||
self._get_part_image(pnum),
|
partimg,
|
||||||
src.path, dest)
|
src.path, dest)
|
||||||
|
|
||||||
exec_cmd(cmd, as_shell=True)
|
exec_cmd(cmd, as_shell=True)
|
||||||
self._put_part_image(pnum)
|
self._put_part_image(pnum)
|
||||||
|
|||||||
Reference in New Issue
Block a user