From 492a1d9a3a00ba16bdfe3764bca9988ec2246cbb Mon Sep 17 00:00:00 2001 From: petersulyok Date: Sat, 6 Apr 2024 20:53:17 +0200 Subject: [PATCH] Fix: exception raised if partition data is missing for dos partition on an USB HDD (issue #6). --- src/diskinfo/partition.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/diskinfo/partition.py b/src/diskinfo/partition.py index 505feb2..c22f118 100644 --- a/src/diskinfo/partition.py +++ b/src/diskinfo/partition.py @@ -113,9 +113,18 @@ def __init__(self, name: str, dev_id: str) -> None: self.__part_label = _read_udev_property(path, "ID_PART_ENTRY_NAME=") self.__part_uuid = _read_udev_property(path, "ID_PART_ENTRY_UUID=") self.__part_type = _read_udev_property(path, "ID_PART_ENTRY_TYPE=") - self.__part_number = int(_read_udev_property(path, "ID_PART_ENTRY_NUMBER=")) - self.__part_offset = int(_read_udev_property(path, "ID_PART_ENTRY_OFFSET=")) - self.__part_size = int(_read_udev_property(path, "ID_PART_ENTRY_SIZE=")) + self.__part_number = 0 + value = _read_udev_property(path, "ID_PART_ENTRY_NUMBER=") + if value: + self.__part_number = int(value) + self.__part_offset = -1 + value = _read_udev_property(path, "ID_PART_ENTRY_OFFSET=") + if value: + self.__part_offset = int(value) + self.__part_size = 0 + value = _read_udev_property(path, "ID_PART_ENTRY_SIZE=") + if value: + self.__part_size = int(value) value = _read_udev_property(path, "ID_FS_LABEL_ENC=") if value: self.__fs_label = value