luks: rework is_unlocked() (#3509)

This commit is contained in:
codefiles 2025-05-26 19:36:23 -04:00 committed by GitHub
parent 9f110849e6
commit 2623039fff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -126,7 +126,7 @@ class Luks2:
raise err
def is_unlocked(self) -> bool:
return self.mapper_name is not None and Path(f'/dev/mapper/{self.mapper_name}').exists()
return (mapper_dev := self.mapper_dev) is not None and mapper_dev.is_symlink()
def unlock(self, key_file: Path | None = None) -> None:
"""
@ -157,7 +157,7 @@ class Luks2:
debug(f'cryptsetup open output: {result.stdout.decode().rstrip()}')
if not self.mapper_dev or not self.mapper_dev.is_symlink():
if not self.is_unlocked():
raise DiskError(f'Failed to open luks2 device: {self.luks_dev_path}')
def lock(self) -> None: