summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-06-13 14:21:51 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-06-14 10:18:28 +0100
commit16562e7672af2c8762d3d089605de48e88905de0 (patch)
tree2f1aa632f5cb3185427a937285e6fc586d20bfe7 /scripts
parentce7895a61ca9c5b7b85d9cc3a0b05ae66a0d8570 (diff)
downloadpoky-16562e7672af2c8762d3d089605de48e88905de0.tar.gz
filemap: add parameter 'length' to sparse_copy
Added parameter 'length' to specify amount of data to write into destination file. This is useful when only part of source file should be written into destination file. (From OE-Core rev: cc44e2eb3b5027a3531e6349937a23d73313b3c6) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-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()