summaryrefslogtreecommitdiff
path: root/kvmd/plugins/msd/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'kvmd/plugins/msd/__init__.py')
-rw-r--r--kvmd/plugins/msd/__init__.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/kvmd/plugins/msd/__init__.py b/kvmd/plugins/msd/__init__.py
index ac285f7b..741c0beb 100644
--- a/kvmd/plugins/msd/__init__.py
+++ b/kvmd/plugins/msd/__init__.py
@@ -187,15 +187,22 @@ class MsdImageWriter:
async def close(self) -> None:
assert self.__file is not None
- if self.__written == self.__size:
- (log, result) = (get_logger().info, "OK")
- elif self.__written < self.__size:
- (log, result) = (get_logger().error, "INCOMPLETE")
- else: # written > size
- (log, result) = (get_logger().warning, "OVERFLOW")
- log("Written %d of %d bytes to MSD image %r: %s", self.__written, self.__size, self.__name, result)
- await aiofs.afile_sync(self.__file)
- await self.__file.close() # type: ignore
+ logger = get_logger()
+ logger.info("Closing image writer ...")
+ try:
+ if self.__written == self.__size:
+ (log, result) = (logger.info, "OK")
+ elif self.__written < self.__size:
+ (log, result) = (logger.error, "INCOMPLETE")
+ else: # written > size
+ (log, result) = (logger.warning, "OVERFLOW")
+ log("Written %d of %d bytes to MSD image %r: %s", self.__written, self.__size, self.__name, result)
+ try:
+ await aiofs.afile_sync(self.__file)
+ finally:
+ await self.__file.close() # type: ignore
+ except Exception:
+ logger.exception("Can't close image writer")
# =====