From 544adcec6b9bc22f540f3ed91805fcbee8d0be14 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Tue, 7 Mar 2023 18:14:05 +0200 Subject: removable flag for image --- kvmd/plugins/msd/otg/storage.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'kvmd/plugins') 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 @@ -64,6 +63,14 @@ class Image(_Image): return os.path.exists(self.__complete_path) 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: -- cgit v1.2.3