diff options
author | Maxim Devaev <[email protected]> | 2023-03-07 18:14:05 +0200 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2023-03-07 18:14:05 +0200 |
commit | 544adcec6b9bc22f540f3ed91805fcbee8d0be14 (patch) | |
tree | c1b0ec05c4ac61d518d618b251ffe11702a77242 | |
parent | 9ecb7fb94d629919f71f4fd58e3502f041f1b7d9 (diff) |
removable flag for image
-rw-r--r-- | kvmd/plugins/msd/otg/storage.py | 15 | ||||
-rw-r--r-- | web/share/js/kvm/msd.js | 2 |
2 files changed, 12 insertions, 5 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 diff --git a/web/share/js/kvm/msd.js b/web/share/js/kvm/msd.js index 8ef89dcb..fae72e43 100644 --- a/web/share/js/kvm/msd.js +++ b/web/share/js/kvm/msd.js @@ -249,7 +249,7 @@ export function Msd() { tools.el.setEnabled($("msd-image-selector"), (online && !s.drive.connected && !s.busy)); __applyStateImageSelector(); tools.el.setEnabled($("msd-download-button"), (online && s.drive.image && !s.drive.connected && !s.busy)); - tools.el.setEnabled($("msd-remove-button"), (online && s.drive.image && !s.drive.connected && !s.busy)); + tools.el.setEnabled($("msd-remove-button"), (online && s.drive.image && s.drive.image.removable && !s.drive.connected && !s.busy)); tools.radio.setEnabled("msd-mode-radio", (online && s.features.cdrom && !s.drive.connected && !s.busy)); tools.radio.setValue("msd-mode-radio", `${Number(online && s.features.cdrom && s.drive.cdrom)}`); |