Skip to content

Commit 917d672

Browse files
committed
fix: linux removable device logic
1 parent fa5a7f6 commit 917d672

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

setup/sd.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
from .newsRenderer import NewsRenderer
2626

2727
sd_path = ""
28-
sd_wad_path = ""
28+
sd_wad_path = "WAD"
2929

3030

3131
def get_devices(removable_only=True):
3232
devices = {}
3333
for part in psutil.disk_partitions():
34-
if removable_only and check_removable(part):
34+
if removable_only and not check_removable(part):
3535
continue
3636
try:
3737
capacity = psutil.disk_usage(part.mountpoint).total
@@ -56,9 +56,14 @@ def check_removable(device: psutil._common.sdiskpart):
5656
return "Removable Media: Yes" in device_info
5757
case "linux":
5858
context = pyudev.Context()
59-
device_name = os.path.basename(device.device)
6059

61-
udev_device = pyudev.Devices.from_device_file(context, device_name)
60+
udev_partition = pyudev.Devices.from_device_file(context, device.device)
61+
62+
if udev_partition.device_type != "disk":
63+
udev_device = udev_partition.find_parent("block", "disk")
64+
else:
65+
udev_device = udev_partition
66+
6267
return udev_device.attributes.get("removable") == b"1"
6368
case _:
6469
return True

0 commit comments

Comments
 (0)