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:
"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. """
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)
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. """
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)
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