Skip to content

Commit 7ae5ae3

Browse files
committed
Resolve symlinks in device path for removable check
When running with --removable-device, the basename of dest is used to construct the path of the "removable" sysfs file for the device. However, if dest is a symlink the basename may be very different from the actual device name, and theoretically might even match a different device. Make the path absolute and resolve any symlinks before taking the basename to avoid that problem. This is of practical importance because it allows using /dev/disk/... symlinks created by udev, which is much less error-prone than using e.g. /dev/sdX. Signed-off-by: Fiona Klute <[email protected]>
1 parent 618a731 commit 7ae5ae3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/bmaptool/CLI.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,9 @@ def open_files(args):
541541
# /sys/block/<devicename>/removable attribute. The value in the
542542
# file is "1" if removable, and "0" if not removable.
543543
removable_path = os.path.join(
544-
"/sys/block", os.path.basename(args.dest), "removable"
544+
"/sys/block",
545+
os.path.basename(os.path.realpath(args.dest)),
546+
"removable"
545547
)
546548
try:
547549
removable_value = open(removable_path, "r").read(1)

0 commit comments

Comments
 (0)