From f589750a3cff6f061bc4b78ef857e52a7fbc874c Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 14 Mar 2021 12:16:46 +0100 Subject: Tweaked SysCallError() exception to include the exit code in a machine readable manner. Since it's useful as an indicator where calls might go wrong and for what reason. --- archinstall/lib/luks.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'archinstall/lib/luks.py') diff --git a/archinstall/lib/luks.py b/archinstall/lib/luks.py index de53c05e..a4d2a07d 100644 --- a/archinstall/lib/luks.py +++ b/archinstall/lib/luks.py @@ -64,12 +64,16 @@ class luks2(): with open(key_file, 'wb') as fh: fh.write(password) - cmd_handle = sys_command(f'/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash {hash_type} --key-size {key_size} --iter-time {iter_time} --key-file {os.path.abspath(key_file)} --use-urandom luksFormat {partition.path}') - if cmd_handle.exit_code == 256: - # Partition was in use, unmount it and - partition.unmount() - sys_command(f'cryptsetup close {partition.path}') + try: cmd_handle = sys_command(f'/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash {hash_type} --key-size {key_size} --iter-time {iter_time} --key-file {os.path.abspath(key_file)} --use-urandom luksFormat {partition.path}') + except SysCallError as err: + if err.exit_code == 256: + # Partition was in use, unmount it and try again + partition.unmount() + sys_command(f'cryptsetup close {partition.path}') + cmd_handle = sys_command(f'/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash {hash_type} --key-size {key_size} --iter-time {iter_time} --key-file {os.path.abspath(key_file)} --use-urandom luksFormat {partition.path}') + else: + raise err if b'Command successful.' not in b''.join(cmd_handle): raise DiskError(f'Could not encrypt volume "{partition.path}": {o}') -- cgit v1.2.3-70-g09d2