summaryrefslogtreecommitdiff
path: root/kvmd/plugins
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2023-08-19 06:21:32 +0300
committerMaxim Devaev <[email protected]>2023-08-19 06:21:32 +0300
commit61de01d892bd2f05f1806e4e915280e56254c086 (patch)
treec6e6735c0dc83f60e3e75f2394af406a2004064a /kvmd/plugins
parent1f64f7b3babd19b768cd8519537c9498b28f9dd6 (diff)
msd: using .incomplete files instead of .complete
Diffstat (limited to 'kvmd/plugins')
-rw-r--r--kvmd/plugins/msd/otg/storage.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/kvmd/plugins/msd/otg/storage.py b/kvmd/plugins/msd/otg/storage.py
index 2efd87c0..08ac65e1 100644
--- a/kvmd/plugins/msd/otg/storage.py
+++ b/kvmd/plugins/msd/otg/storage.py
@@ -54,7 +54,7 @@ class Image(_ImageDc):
super().__init__(name, path)
self.__storage = storage
(self.__dir_path, file_name) = os.path.split(path)
- self.__complete_path = os.path.join(self.__dir_path, f".__{file_name}.complete")
+ self.__incomplete_path = os.path.join(self.__dir_path, f".__{file_name}.incomplete")
self.__adopted = False
async def _reload(self) -> None: # Only for Storage() and set_complete()
@@ -80,7 +80,7 @@ class Image(_ImageDc):
async def __is_complete(self) -> bool:
if self.__storage:
- return (await aiofiles.os.path.exists(self.__complete_path))
+ return (not (await aiofiles.os.path.exists(self.__incomplete_path)))
return True
async def __is_removable(self) -> bool:
@@ -113,26 +113,31 @@ class Image(_ImageDc):
async def remove(self, fatal: bool) -> None:
assert self.__storage
+ removed = False
try:
await aiofiles.os.remove(self.path)
+ removed = True
self.__storage.images.pop(self.name, None)
except FileNotFoundError:
pass
except Exception:
if fatal:
raise
- await self.set_complete(False)
+ finally:
+ # Удаляем .incomplete вместе с файлом
+ if removed:
+ await self.set_complete(True)
async def set_complete(self, flag: bool) -> None:
assert self.__storage
if flag:
- async with aiofiles.open(self.__complete_path, "w"):
- pass
- else:
try:
- await aiofiles.os.remove(self.__complete_path)
+ await aiofiles.os.remove(self.__incomplete_path)
except FileNotFoundError:
pass
+ else:
+ async with aiofiles.open(self.__incomplete_path, "w"):
+ pass
await self._reload()