refactor: cryptsetup._get_device_from_status
This commit is contained in:
+19
-5
@@ -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
|
||||||
if item.readlink() == device:
|
return 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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user