Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit ee88d49

Browse files
committed
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 <[email protected]>
1 parent 563a5e4 commit ee88d49

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

bmaptool

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,21 @@ def open_files(args, log):
381381
bmap_path = None
382382
args.nobmap = True
383383

384+
# If the destination file is under "/dev", but does not exist, print a
385+
# warning. This is done in order to be more user-friendly, because
386+
# sometimes users mean to write to a block device, them misspell its name.
387+
# We just create the "/dev/misspelled" file, write the data there, and
388+
# report success. Later on the user finds out that the image was not really
389+
# written to the device, and gets confused. Similar confusion may happen if
390+
# the destination file is not a special device for some reasons.
391+
if os.path.normpath(args.dest).startswith("/dev/"):
392+
if not os.path.exists(args.dest):
393+
log.warning("\"%s\" does not exist, creating a regular file " \
394+
"\"%s\"" % (args.dest, args.dest))
395+
elif stat.S_ISREG(os.stat(args.dest).st_mode):
396+
log.warning("\"%s\" is under \"/dev\", but it is a regular file, " \
397+
"not a device node" % args.dest)
398+
384399
# Try to open the destination file. If it does not exist, a new regular
385400
# file will be created. If it exists and it is a regular file - it'll be
386401
# truncated. If this is a block device, it'll just be opened.

0 commit comments

Comments
 (0)