From 4d297d82783d3f378c1d7597a51d13e217bbb033 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Wed, 21 Nov 2012 16:38:21 +0200 Subject: [PATCH] BmapCopy.py: fix a bug when copying without bmap Fix a regression introduced in version 0.5: when copying without bmap the script fails with the following error: AttributeError: BmapCopy instance has no attribute '_f_bmap' This is because we never define this attribute when there is no bmap, but still use it. The fix is: 1. Define all attributes in the __init__ constructor. 2. Always check if _f_bmap is not None before using it. While on it, do a minor space clean-up. Change-Id: I3f729588d33be8e2a447fca817b994500840503a Signed-off-by: Artem Bityutskiy --- bmaptools/BmapCopy.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/bmaptools/BmapCopy.py b/bmaptools/BmapCopy.py index ce7df6e..ede64ad 100644 --- a/bmaptools/BmapCopy.py +++ b/bmaptools/BmapCopy.py @@ -247,11 +247,19 @@ class BmapCopy: self._f_image_needs_close = False self._f_bmap_needs_close = False + self._f_dest = None + self._f_image = None + self._f_bmap = None + + self._dest_path = None + self._image_path = None + self._bmap_path = None + if hasattr(dest, "write"): - self._f_dest = dest - self._dest_path = dest.name + self._f_dest = dest + self._dest_path = dest.name else: - self._dest_path = dest + self._dest_path = dest self._open_destination_file() if hasattr(image, "read"): @@ -428,7 +436,8 @@ class BmapCopy: # Save file positions in order to restore them at the end image_pos = self._f_image.tell() dest_pos = self._f_dest.tell() - bmap_pos = self._f_bmap.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'. @@ -495,7 +504,8 @@ class BmapCopy: # Restore file positions self._f_image.seek(image_pos) self._f_dest.seek(dest_pos) - self._f_bmap.seek(bmap_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 -- 2.7.4