diff options
Diffstat (limited to 'scripts/lib')
-rw-r--r-- | scripts/lib/wic/engine.py | 63 |
1 files changed, 14 insertions, 49 deletions
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py index 9d596be3a7..b9e60cbe4e 100644 --- a/scripts/lib/wic/engine.py +++ b/scripts/lib/wic/engine.py | |||
@@ -345,64 +345,29 @@ class Disk: | |||
345 | path)) | 345 | path)) |
346 | 346 | ||
347 | def copy(self, src, dest): | 347 | def copy(self, src, dest): |
348 | """Copy files or directories to/from the vfat or ext* partition.""" | 348 | """Copy partition image into wic image.""" |
349 | pnum = dest.part if isinstance(src, str) else src.part | 349 | pnum = dest.part if isinstance(src, str) else src.part |
350 | partimg = self._get_part_image(pnum) | ||
351 | 350 | ||
352 | if self.partitions[pnum].fstype.startswith('ext'): | 351 | if self.partitions[pnum].fstype.startswith('ext'): |
353 | if isinstance(src, str): # host to image case | 352 | if isinstance(src, str): |
354 | if os.path.isdir(src): | 353 | cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\ |
355 | base = os.path.abspath(src) | 354 | format(os.path.dirname(dest.path), src, os.path.basename(src), |
356 | base_parent = os.path.dirname(base) | 355 | self.debugfs, self._get_part_image(pnum)) |
357 | cmds = [] | 356 | else: # copy from wic |
358 | made = set() | 357 | # run both dump and rdump to support both files and directory |
359 | |||
360 | for root, dirs, files in os.walk(base): | ||
361 | for fname in files: | ||
362 | host_file = os.path.join(root, fname) | ||
363 | rel = os.path.relpath(host_file, base_parent) | ||
364 | dest_file = os.path.join(dest.path, rel) | ||
365 | dest_dir = os.path.dirname(dest_file) | ||
366 | |||
367 | # create dir structure (mkdir -p) | ||
368 | parts = dest_dir.strip('/').split('/') | ||
369 | cur = '' | ||
370 | for p in parts: | ||
371 | cur = cur + '/' + p | ||
372 | if cur not in made: | ||
373 | cmds.append(f'mkdir "{cur}"') | ||
374 | made.add(cur) | ||
375 | |||
376 | cmds.append(f'write "{host_file}" "{dest_file}"') | ||
377 | |||
378 | # write script to a temp file | ||
379 | with tempfile.NamedTemporaryFile(mode='w', delete=False, | ||
380 | prefix='wic-debugfs-') as tf: | ||
381 | for line in cmds: | ||
382 | tf.write(line + '\n') | ||
383 | scriptname = tf.name | ||
384 | |||
385 | cmd = f"{self.debugfs} -w -f {scriptname} {partimg}" | ||
386 | |||
387 | else: # single file | ||
388 | cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\ | ||
389 | format(os.path.dirname(dest.path), src, | ||
390 | os.path.basename(src), self.debugfs, partimg) | ||
391 | |||
392 | else: # image to host case | ||
393 | cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\ | 358 | cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\ |
394 | format(os.path.dirname(src.path), src.path, | 359 | format(os.path.dirname(src.path), src.path, |
395 | dest, src.path, dest, self.debugfs, partimg) | 360 | dest, src.path, dest, self.debugfs, |
396 | 361 | self._get_part_image(pnum)) | |
397 | else: # fat | 362 | else: # fat |
398 | if isinstance(src, str): | 363 | if isinstance(src, str): |
399 | cmd = "{} -i {} -snop {} ::{}".format(self.mcopy, | 364 | cmd = "{} -i {} -snop {} ::{}".format(self.mcopy, |
400 | partimg, | 365 | self._get_part_image(pnum), |
401 | src, dest.path) | 366 | src, dest.path) |
402 | else: | 367 | else: |
403 | cmd = "{} -i {} -snop ::{} {}".format(self.mcopy, | 368 | cmd = "{} -i {} -snop ::{} {}".format(self.mcopy, |
404 | partimg, | 369 | self._get_part_image(pnum), |
405 | src.path, dest) | 370 | src.path, dest) |
406 | 371 | ||
407 | exec_cmd(cmd, as_shell=True) | 372 | exec_cmd(cmd, as_shell=True) |
408 | self._put_part_image(pnum) | 373 | self._put_part_image(pnum) |