bmaptool: do not fail when copying a bmap file
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Tue, 17 Sep 2013 06:44:22 +0000 (09:44 +0300)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Tue, 17 Sep 2013 12:10:36 +0000 (15:10 +0300)
It is possible that the user copies the bmapfile itself using 'bmaptool copy'.
Most probably this is just by a mistake. In this case bmaptool just fails,
since it discovers the bmap file, and it does not match the "image" (where the
image is the same bmap file).

This patch teaches bmaptool to handle this case by dropping the discoverd bmap
file if its path is the same as the image path.

Change-Id: Ib48842ed6157ba364173fcd7771e1b2ba3eea9e5
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
bmaptool

index 6236810..95380e8 100755 (executable)
--- a/bmaptool
+++ b/bmaptool
@@ -181,6 +181,15 @@ def copy_command_open_all(args, log):
     # was not specified.
     (bmap_obj, bmap_path) = find_and_open_bmap(args, log)
 
+    if bmap_path == args.image:
+        # Most probably the specified the bmap file instead of the image file
+        # by mistake.
+        log.warning("image has the same path as the bmap file, dropping bmap")
+        bmap_obj.close()
+        bmap_obj = None
+        bmap_path = None
+        args.nobmap = True
+
     # Try to open the destination file. If it does not exist, a new regular
     # file will be created. If it exists and it is a regular file - it'll be
     # truncated. If this is a block device, it'll just be opened.