From fd83f073f3e84feb1388ef739c1096f7d4a741de Mon Sep 17 00:00:00 2001 From: Daemon Coder <11915375+codefiles@users.noreply.github.com> Date: Thu, 4 May 2023 04:42:37 -0400 Subject: Update `SysCommand()` calls in remaining files (#1707) --- archinstall/lib/luks.py | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'archinstall/lib/luks.py') diff --git a/archinstall/lib/luks.py b/archinstall/lib/luks.py index fc531a06..53a5e8d2 100644 --- a/archinstall/lib/luks.py +++ b/archinstall/lib/luks.py @@ -88,30 +88,28 @@ class Luks2: 'luksFormat', str(self.luks_dev_path), ]) - try: - # Retry formatting the volume because archinstall can some times be too quick - # which generates a "Device /dev/sdX does not exist or access denied." between - # setting up partitions and us trying to encrypt it. - cmd_handle = None - for i in range(storage['DISK_RETRY_ATTEMPTS']): - if (cmd_handle := SysCommand(cryptsetup_args)).exit_code != 0: - time.sleep(storage['DISK_TIMEOUTS']) - else: - break + # Retry formatting the volume because archinstall can some times be too quick + # which generates a "Device /dev/sdX does not exist or access denied." between + # setting up partitions and us trying to encrypt it. + for retry_attempt in range(storage['DISK_RETRY_ATTEMPTS']): + try: + SysCommand(cryptsetup_args) + break + except SysCallError as error: + time.sleep(storage['DISK_TIMEOUTS']) - if cmd_handle is not None and cmd_handle.exit_code != 0: - output = str(b''.join(cmd_handle)) - raise DiskError(f'Could not encrypt volume "{self.luks_dev_path}": {output}') - except SysCallError as err: - if err.exit_code == 1: - log(f'luks2 partition currently in use: {self.luks_dev_path}') - log('Attempting to unmount, crypt-close and trying encryption again') + if retry_attempt != storage['DISK_RETRY_ATTEMPTS'] - 1: + continue - self.lock() - # Then try again to set up the crypt-device - SysCommand(cryptsetup_args) - else: - raise err + if error.exit_code == 1: + log(f'luks2 partition currently in use: {self.luks_dev_path}') + log('Attempting to unmount, crypt-close and trying encryption again') + + self.lock() + # Then try again to set up the crypt-device + SysCommand(cryptsetup_args) + else: + raise DiskError(f'Could not encrypt volume "{self.luks_dev_path}": {error}') return key_file @@ -119,11 +117,7 @@ class Luks2: command = f'/usr/bin/cryptsetup luksUUID {self.luks_dev_path}' try: - result = SysCommand(command) - if result.exit_code != 0: - raise DiskError(f'Unable to get UUID for Luks device: {result.decode()}') - - return result.decode() # type: ignore + return SysCommand(command).decode().strip() # type: ignore except SysCallError as err: log(f'Unable to get UUID for Luks device: {self.luks_dev_path}', level=logging.INFO) raise err -- cgit v1.2.3-54-g00ecf