Added some errro handling for weird block devices

This commit is contained in:
Anton Hvornum 2023-02-23 09:02:58 +01:00
parent 5f2dcf7597
commit 16852f9501
No known key found for this signature in database
GPG Key ID: F1234C5BA67C59DF
1 changed files with 4 additions and 1 deletions

View File

@ -266,7 +266,10 @@ def all_blockdevices(
# we'll iterate the /sys/class definitions and find the information
# from there.
for block_device in glob.glob("/sys/class/block/*"):
device_path = pathlib.Path(f"/dev/{pathlib.Path(block_device).readlink().name}")
try:
device_path = pathlib.Path(f"/dev/{pathlib.Path(block_device).readlink().name}")
except FileNotFoundError:
log(f"Unknown device found by '/sys/class/block/*', ignoring: {device_path}", level=logging.WARNING, fg="yellow")
if device_path.exists() is False:
log(f"Unknown device found by '/sys/class/block/*', ignoring: {device_path}", level=logging.WARNING, fg="yellow")