summaryrefslogtreecommitdiff
path: root/kvmd/plugins
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2023-03-07 18:14:05 +0200
committerMaxim Devaev <[email protected]>2023-03-07 18:14:05 +0200
commit544adcec6b9bc22f540f3ed91805fcbee8d0be14 (patch)
treec1b0ec05c4ac61d518d618b251ffe11702a77242 /kvmd/plugins
parent9ecb7fb94d629919f71f4fd58e3502f041f1b7d9 (diff)
removable flag for image
Diffstat (limited to 'kvmd/plugins')
-rw-r--r--kvmd/plugins/msd/otg/storage.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/kvmd/plugins/msd/otg/storage.py b/kvmd/plugins/msd/otg/storage.py
index 051ef007..b6b6d52a 100644
--- a/kvmd/plugins/msd/otg/storage.py
+++ b/kvmd/plugins/msd/otg/storage.py
@@ -40,6 +40,7 @@ class _Image:
path: str
in_storage: bool = dataclasses.field(init=False)
complete: bool = dataclasses.field(init=False, compare=False)
+ removable: bool = dataclasses.field(init=False, compare=False)
size: int = dataclasses.field(init=False, compare=False)
mod_ts: float = dataclasses.field(init=False, compare=False)
@@ -48,10 +49,8 @@ class Image(_Image):
def __init__(self, name: str, path: str, storage: Optional["Storage"]) -> None:
super().__init__(name, path)
self.__storage = storage
- self.__complete_path = os.path.join(
- os.path.dirname(path),
- ".__" + os.path.basename(path) + ".complete",
- )
+ (self.__dir_path, file_name) = os.path.split(path)
+ self.__complete_path = os.path.join(self.__dir_path, f".__{file_name}.complete")
self.__adopted = (storage._is_adopted(self) if storage else True)
@property
@@ -65,6 +64,14 @@ class Image(_Image):
return True
@property
+ def removable(self) -> bool:
+ if not self.__storage:
+ return False
+ if not self.__adopted:
+ return True
+ return os.access(self.__dir_path, os.W_OK)
+
+ @property
def size(self) -> int:
try:
return os.stat(self.path).st_size