From 59c35df0676977c93ed7276237179c9af8d9c476 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 26 Apr 2022 17:13:47 +0200 Subject: Optimized a bunch of partprobe calls. (#1088) * Optimized a bunch of partprobe calls. Namely fixed sleep calls, added optional path to the general archinstall.partprobe() call. And fixed some error handling in a few places which should tell us where #1083 might be going wrong. * Fixed some flake8 complaints * Fixed sleep having a min() of 0.1 or given value. * Fixed sleep having a correct range variable. * Fixed sleep logic to use max() instead of min() as it will never use the higer sleep values otheride --- archinstall/lib/disk/partition.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'archinstall/lib/disk/partition.py') diff --git a/archinstall/lib/disk/partition.py b/archinstall/lib/disk/partition.py index bf55145c..a44efa26 100644 --- a/archinstall/lib/disk/partition.py +++ b/archinstall/lib/disk/partition.py @@ -142,6 +142,7 @@ class Partition: def size(self) -> Optional[float]: for i in range(storage['DISK_RETRY_ATTEMPTS']): self.partprobe() + time.sleep(max(0.1, storage['DISK_TIMEOUTS'] * i)) try: lsblk = json.loads(SysCommand(f"lsblk --json -b -o+SIZE {self.device_path}").decode()) @@ -154,8 +155,6 @@ class Partition: else: raise error - time.sleep(storage['DISK_TIMEOUTS']) - @property def boot(self) -> bool: output = json.loads(SysCommand(f"sfdisk --json {self.block_device.path}").decode('UTF-8')) @@ -194,13 +193,12 @@ class Partition: """ for i in range(storage['DISK_RETRY_ATTEMPTS']): self.partprobe() + time.sleep(max(0.1, storage['DISK_TIMEOUTS'] * i)) partuuid = self._safe_uuid if partuuid: return partuuid - time.sleep(storage['DISK_TIMEOUTS']) - raise DiskError(f"Could not get PARTUUID for {self.path} using 'blkid -s PARTUUID -o value {self.path}'") @property @@ -210,7 +208,14 @@ class Partition: This function should only be used where uuid is not crucial. For instance when you want to get a __repr__ of the class. """ - self.partprobe() + try: + self.partprobe() + except SysCallError as partprobe_error: + if self.block_device.info.get('TYPE') == 'iso9660': + return None + + raise DiskError(f"Could not get PARTUUID of partition {self} due to partprobe error: {partprobe_error}") + try: return SysCommand(f'blkid -s PARTUUID -o value {self.device_path}').decode('UTF-8').strip() except SysCallError as error: @@ -263,7 +268,6 @@ class Partition: def partprobe(self) -> bool: if self.block_device and SysCommand(f'partprobe {self.block_device.device}').exit_code == 0: - time.sleep(1) return True return False -- cgit v1.2.3-54-g00ecf