Some more error handling.

This commit is contained in:
Anton Hvornum 2021-03-14 12:27:48 +01:00
parent 4ac2528822
commit e4514e8fc3
No known key found for this signature in database
GPG Key ID: F1234C5BA67C59DF
1 changed files with 8 additions and 1 deletions

View File

@ -70,7 +70,14 @@ class luks2():
if err.exit_code == 256:
# Partition was in use, unmount it and try again
partition.unmount()
sys_command(f'cryptsetup close {partition.path}')
try:
sys_command(f'cryptsetup close {partition.path}')
except SysCallError as err:
# 0 Means everything went smoothly,
# 1024 means the device was not found.
if err.exit_code not in (0, 1024):
raise err
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