summaryrefslogtreecommitdiff
path: root/kvmd/plugins/msd/otg/__init__.py
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-07-30 18:15:50 +0300
committerMaxim Devaev <[email protected]>2022-07-30 18:15:50 +0300
commit589ec14de02de4ecf960d13d675c7f1efaa74b7c (patch)
treec0a3be50145de8f1f8eb4d3e600b9ba16c0a6482 /kvmd/plugins/msd/otg/__init__.py
parent5ee8f7a7a34641392213cbf932a61455d87bddbd (diff)
Fixed pikvm/pikvm#783: remove incomplete msd image
Diffstat (limited to 'kvmd/plugins/msd/otg/__init__.py')
-rw-r--r--kvmd/plugins/msd/otg/__init__.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py
index bc2b2f99..d3285704 100644
--- a/kvmd/plugins/msd/otg/__init__.py
+++ b/kvmd/plugins/msd/otg/__init__.py
@@ -363,9 +363,10 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
return (await self.__reader.read())
@contextlib.asynccontextmanager
- async def write_image(self, name: str, size: int) -> AsyncGenerator[int, None]:
+ async def write_image(self, name: str, size: int, remove_incomplete: Optional[bool]) -> AsyncGenerator[int, None]:
try:
async with self.__state._region: # pylint: disable=protected-access
+ path: str = ""
try:
async with self.__state._lock: # pylint: disable=protected-access
await self.__notifier.notify()
@@ -391,9 +392,15 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
await self.__notifier.notify()
yield self.__write_chunk_size
- self.__set_image_complete(name, True)
+ self.__set_image_complete(name, self.__writer.is_complete())
finally:
+ if remove_incomplete and self.__writer and not self.__writer.is_complete():
+ # Можно сперва удалить файл, потом закрыть его
+ try:
+ os.remove(path)
+ except Exception:
+ pass
await self.__close_writer()
await self.__remount_rw(False, fatal=False)
finally: