refactor: cryptsetup._get_device_from_status
This commit is contained in:
+20
-6
@@ -457,7 +457,23 @@ class Cryptsetup:
|
||||
return (MAPPER_PATH / mapper_entry).exists()
|
||||
|
||||
@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"):
|
||||
if line.startswith(" device:"):
|
||||
device = Path(line.split(":")[-1].strip())
|
||||
@@ -465,14 +481,12 @@ class Cryptsetup:
|
||||
else:
|
||||
print("panic")
|
||||
exit(EXIT_ERROR)
|
||||
for item in DISK_BY_UUID.iterdir():
|
||||
# noinspection PyUnboundLocalVariable
|
||||
if item.readlink() == device:
|
||||
return item
|
||||
# noinspection PyUnboundLocalVariable
|
||||
return device
|
||||
|
||||
@classmethod
|
||||
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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user