From: Artem Bityutskiy Date: Mon, 30 Sep 2013 11:25:00 +0000 (+0300) Subject: bmaptool: warn if destination file is suspecious X-Git-Tag: v3.0~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ee88d4947f2ab02ad9c4a4be87970b4465290b3a;p=tools%2Fbmap-tools.git bmaptool: warn if destination file is suspecious Warn a user if he/she writes to a file under /dev, but it is not a special device file, but just a regular file. This should improve user-friendliness. Change-Id: I70e49d1c34ade667008dc606eb555e924b864ade Signed-off-by: Artem Bityutskiy --- diff --git a/bmaptool b/bmaptool index e4df75e..162fee5 100755 --- a/bmaptool +++ b/bmaptool @@ -381,6 +381,21 @@ def open_files(args, log): bmap_path = None args.nobmap = True + # If the destination file is under "/dev", but does not exist, print a + # warning. This is done in order to be more user-friendly, because + # sometimes users mean to write to a block device, them misspell its name. + # We just create the "/dev/misspelled" file, write the data there, and + # report success. Later on the user finds out that the image was not really + # written to the device, and gets confused. Similar confusion may happen if + # the destination file is not a special device for some reasons. + if os.path.normpath(args.dest).startswith("/dev/"): + if not os.path.exists(args.dest): + log.warning("\"%s\" does not exist, creating a regular file " \ + "\"%s\"" % (args.dest, args.dest)) + elif stat.S_ISREG(os.stat(args.dest).st_mode): + log.warning("\"%s\" is under \"/dev\", but it is a regular file, " \ + "not a device node" % args.dest) + # 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.