summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/filemap.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic/filemap.py')
-rw-r--r--scripts/lib/wic/filemap.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/scripts/lib/wic/filemap.py b/scripts/lib/wic/filemap.py
index 585b7ea84e..8fe302ab49 100644
--- a/scripts/lib/wic/filemap.py
+++ b/scripts/lib/wic/filemap.py
@@ -530,7 +530,8 @@ def filemap(image, log=None):
530 except ErrorNotSupp: 530 except ErrorNotSupp:
531 return FilemapSeek(image, log) 531 return FilemapSeek(image, log)
532 532
533def sparse_copy(src_fname, dst_fname, offset=0, skip=0, api=None): 533def sparse_copy(src_fname, dst_fname, offset=0, skip=0,
534 length=0, api=None):
534 """Efficiently copy sparse file to or into another file.""" 535 """Efficiently copy sparse file to or into another file."""
535 if not api: 536 if not api:
536 api = filemap 537 api = filemap
@@ -541,6 +542,7 @@ def sparse_copy(src_fname, dst_fname, offset=0, skip=0, api=None):
541 dst_file = open(dst_fname, 'wb') 542 dst_file = open(dst_fname, 'wb')
542 dst_file.truncate(os.path.getsize(src_fname)) 543 dst_file.truncate(os.path.getsize(src_fname))
543 544
545 written = 0
544 for first, last in fmap.get_mapped_ranges(0, fmap.blocks_cnt): 546 for first, last in fmap.get_mapped_ranges(0, fmap.blocks_cnt):
545 start = first * fmap.block_size 547 start = first * fmap.block_size
546 end = (last + 1) * fmap.block_size 548 end = (last + 1) * fmap.block_size
@@ -561,7 +563,14 @@ def sparse_copy(src_fname, dst_fname, offset=0, skip=0, api=None):
561 while read < to_read: 563 while read < to_read:
562 if read + chunk_size > to_read: 564 if read + chunk_size > to_read:
563 chunk_size = to_read - read 565 chunk_size = to_read - read
564 chunk = fmap._f_image.read(chunk_size) 566 size = chunk_size
567 if length and written + size > length:
568 size = length - written
569 chunk = fmap._f_image.read(size)
565 dst_file.write(chunk) 570 dst_file.write(chunk)
566 read += chunk_size 571 read += size
572 written += size
573 if written == length:
574 dst_file.close()
575 return
567 dst_file.close() 576 dst_file.close()