[bmap-tools] [PATCH 01/14] bmaptool: do not fail when copying a bmap file

Artem Bityutskiy dedekind1 at gmail.com
Thu Sep 19 06:35:14 EDT 2013

From: Artem Bityutskiy <artem.bityutskiy at intel.com>

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 at intel.com>
 bmaptool | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/bmaptool b/bmaptool
index 6236810..95380e8 100755
--- 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.

More information about the Bmap-tools mailing list