refactor: cryptsetup._get_device_from_status

This commit is contained in:
timeshifter
2021-12-03 20:33:57 +01:00
parent bd1ff01c08
commit a52927add8
+20 -6
View File
@@ -457,7 +457,23 @@ class Cryptsetup:
return (MAPPER_PATH / mapper_entry).exists() return (MAPPER_PATH / mapper_entry).exists()
@classmethod @classmethod
def _get_device_from_status(cls, status: str) -> Path: def _get_device_by_uuid_from_status_output(cls, status: str) -> Path:
device = cls._get_device_name(status)
result = cls._resolve_uuid_of_device(device)
return result
@classmethod
def _resolve_uuid_of_device(cls, device):
for item in DISK_BY_UUID.iterdir():
if item.readlink() == device:
result = item
else:
print(f"Could not resolve UUID of cryptsetup device {device}")
exit(EXIT_ERROR)
return result
@classmethod
def _get_device_name(cls, status):
for line in status.split("\n"): for line in status.split("\n"):
if line.startswith(" device:"): if line.startswith(" device:"):
device = Path(line.split(":")[-1].strip()) device = Path(line.split(":")[-1].strip())
@@ -465,14 +481,12 @@ class Cryptsetup:
else: else:
print("panic") print("panic")
exit(EXIT_ERROR) exit(EXIT_ERROR)
for item in DISK_BY_UUID.iterdir(): # noinspection PyUnboundLocalVariable
# noinspection PyUnboundLocalVariable return device
if item.readlink() == device:
return item
@classmethod @classmethod
def _already_decrypted(cls, path: Path, mapper_entry: str) -> bool: def _already_decrypted(cls, path: Path, mapper_entry: str) -> bool:
decrypted_disk_path = cls._get_device_from_status(cls._status(mapper_entry)) decrypted_disk_path = cls._get_device_by_uuid_from_status_output(cls._status(mapper_entry))
return decrypted_disk_path == path return decrypted_disk_path == path