From f2fc47129978f8c5ec7aad25957de33261be3343 Mon Sep 17 00:00:00 2001 From: Fiona Klute Date: Thu, 24 Apr 2025 15:33:13 +0200 Subject: [PATCH] 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 --- src/bmaptool/CLI.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bmaptool/CLI.py b/src/bmaptool/CLI.py index 40acf31..a417470 100644 --- a/src/bmaptool/CLI.py +++ b/src/bmaptool/CLI.py @@ -541,7 +541,7 @@ def open_files(args): # /sys/block//removable attribute. The value in the # file is "1" if removable, and "0" if not removable. removable_path = os.path.join( - "/sys/block", os.path.basename(args.dest), "removable" + "/sys/block", os.path.basename(os.path.realpath(args.dest)), "removable" ) try: removable_value = open(removable_path, "r").read(1)