Verified Commit 34f772ca authored by Jakob Moser's avatar Jakob Moser
Browse files

Implement "is_open"

parent bf8b6678
Loading
Loading
Loading
Loading
+19 −3
Changes for poolpay/vault/Vault.py: 19 added lines, 3 removed lines.
Original line number Diff line number Diff line
from dataclasses import dataclass
from pathlib import Path
from subprocess import run
from subprocess import CalledProcessError, run
from uuid import uuid4


@@ -98,6 +98,23 @@ class Vault:
    def _umount(self) -> None:
        run(["sudo", "umount", f"{self.mountpoint.resolve()}"], check=True)

    @property
    def _is_mounted(self) -> bool:
        try:
            run(
                [
                    "findmnt",
                    "--source",
                    f"{self._mapper}",
                    "--mountpoint",
                    f"{self.mountpoint}",
                ],
                check=True,
            )
            return True
        except CalledProcessError:
            return False

    def open(self, password: str) -> None:
        self._cryptsetup_open(password)
        self._mount()
@@ -108,5 +125,4 @@ class Vault:

    @property
    def is_open(self) -> bool:
        # TODO Parse the output of "mount" to see if our mapper is mounted at our mountpoint
        raise NotImplementedError()
        return self._is_mounted