Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/luks.py
diff options
context:
space:
mode:
authorDaemon Coder <11915375+codefiles@users.noreply.github.com>2023-05-04 04:42:37 -0400
committerGitHub <noreply@github.com>2023-05-04 10:42:37 +0200
commitfd83f073f3e84feb1388ef739c1096f7d4a741de (patch)
tree7662dea329d998e3912b6bd2d9c2e076b5f4a856 /archinstall/lib/luks.py
parentadceed22ad3d8b6aa1e6d1aee56ae0c9a0a751aa (diff)
Update `SysCommand()` calls in remaining files (#1707)
Diffstat (limited to 'archinstall/lib/luks.py')
-rw-r--r--archinstall/lib/luks.py48
1 files changed, 21 insertions, 27 deletions
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