diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2017-06-13 14:21:51 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-14 10:18:19 +0100 |
commit | cc44e2eb3b5027a3531e6349937a23d73313b3c6 (patch) | |
tree | 4613dd96aaff19ec8e1f2a4466e8e6ccd548e048 /scripts/lib | |
parent | c19f78a0713c8ac9d28b78f86c6d7b96157788f0 (diff) | |
download | openembedded-core-cc44e2eb3b5027a3531e6349937a23d73313b3c6.tar.gz openembedded-core-cc44e2eb3b5027a3531e6349937a23d73313b3c6.tar.bz2 openembedded-core-cc44e2eb3b5027a3531e6349937a23d73313b3c6.zip |
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.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
-rw-r--r-- | scripts/lib/wic/filemap.py | 15 |
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): except ErrorNotSupp: return FilemapSeek(image, log) -def sparse_copy(src_fname, dst_fname, offset=0, skip=0, api=None): +def sparse_copy(src_fname, dst_fname, offset=0, skip=0, + length=0, api=None): """Efficiently copy sparse file to or into another file.""" if not api: api = filemap @@ -541,6 +542,7 @@ def sparse_copy(src_fname, dst_fname, offset=0, skip=0, api=None): dst_file = open(dst_fname, 'wb') dst_file.truncate(os.path.getsize(src_fname)) + written = 0 for first, last in fmap.get_mapped_ranges(0, fmap.blocks_cnt): start = first * fmap.block_size end = (last + 1) * fmap.block_size @@ -561,7 +563,14 @@ def sparse_copy(src_fname, dst_fname, offset=0, skip=0, api=None): while read < to_read: if read + chunk_size > to_read: chunk_size = to_read - read - chunk = fmap._f_image.read(chunk_size) + size = chunk_size + if length and written + size > length: + size = length - written + chunk = fmap._f_image.read(size) dst_file.write(chunk) - read += chunk_size + read += size + written += size + if written == length: + dst_file.close() + return dst_file.close() |