From eac9c0c68b25141f35b61e138266550664d857ee Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 14 Dec 2012 15:04:30 +0200 Subject: [PATCH] BmapCopy: make object one-time usable Make the 'BmapCopy' objects usable only once, just like many other complex objects like Bzip2File. The reason for this is that it is too complex to make them re-usable, because this requires seeking image file and the destination file to the beginning, and not all files are easily seekable. In fact, some files are not seekable at all. So remove the unneeded complexity. Change-Id: I30ecdd44dead485ae9d187e3487b0efa548c15d5 Signed-off-by: Artem Bityutskiy --- bmaptools/BmapCopy.py | 17 ----------------- tests/test_api_base.py | 21 +++------------------ 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/bmaptools/BmapCopy.py b/bmaptools/BmapCopy.py index bb4ea6a..cc74648 100644 --- a/bmaptools/BmapCopy.py +++ b/bmaptools/BmapCopy.py @@ -158,9 +158,6 @@ class BmapCopy: def _parse_bmap(self): """ Parse the bmap file and initialize the 'bmap_*' attributes. """ - bmap_pos = self._f_bmap.tell() - self._f_bmap.seek(0) - try: self._xml = ElementTree.parse(self._f_bmap) except ElementTree.ParseError as err: @@ -193,8 +190,6 @@ class BmapCopy: "blocks count (%d bytes != %d blocks * %d bytes)" \ % (self.image_size, self.blocks_cnt, self.block_size)) - self._f_bmap.seek(bmap_pos) - def _open_destination_file(self): """ Open the destination file. """ @@ -459,12 +454,6 @@ class BmapCopy: upon return. The 'verify' argument defines whether the SHA1 checksum has to be verified while copying. """ - # Save file positions in order to restore them at the end - image_pos = self._f_image.tell() - dest_pos = self._f_dest.tell() - if self._f_bmap: - bmap_pos = self._f_bmap.tell() - # Create the queue for block batches and start the reader thread, which # will read the image in batches and put the results to '_batch_queue'. self._batch_queue = Queue.Queue(self._batch_queue_len) @@ -541,12 +530,6 @@ class BmapCopy: if sync: self.sync() - # Restore file positions - self._f_image.seek(image_pos) - self._f_dest.seek(dest_pos) - if self._f_bmap: - self._f_bmap.seek(bmap_pos) - def sync(self): """ Synchronize the destination file to make sure all the data are actually written to the disk. """ diff --git a/tests/test_api_base.py b/tests/test_api_base.py index a011e9e..39e6d65 100644 --- a/tests/test_api_base.py +++ b/tests/test_api_base.py @@ -180,6 +180,7 @@ def _do_test(f_image, image_size, delete = True): creator = BmapCreate.BmapCreate(f_image, f_bmap2) creator.generate() + f_bmap2.seek(0) writer = BmapCopy.BmapCopy(f_image, f_copy, f_bmap2) writer.copy(False, True) @@ -197,28 +198,12 @@ def _do_test(f_image, image_size, delete = True): assert _calculate_sha1(f_copy) == image_sha1 # - # Pass 3: repeat pass 2 to make sure the same 'BmapCreate' and - # 'BmapCopy' objects can be used more than once. - # - - f_bmap2.seek(0) - creator.generate() - f_bmap2.seek(0) - creator.generate() - writer.copy(True, False) - writer.set_progress_indicator(sys.stdout, "Done %d percent") - writer.copy(False, True) - writer.sync() - assert _calculate_sha1(f_copy) == image_sha1 - _compare_holes(f_image, f_copy) - assert filecmp.cmp(f_bmap1.name, f_bmap2.name, False) - - # - # Pass 4: test compressed files copying with bmap + # Pass 3: test compressed files copying with bmap # for compressed in _generate_compressed_files(f_image, delete = delete): # Test without setting the size + f_bmap1.seek(0) writer = BmapCopy.BmapCopy(compressed, f_copy, f_bmap1) writer.copy() assert _calculate_sha1(f_copy) == image_sha1 -- 2.7.4