diff options
author | Maxim Devaev <[email protected]> | 2022-08-04 04:04:10 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-08-04 04:04:10 +0300 |
commit | 9ee63aba3ead6493acd01c89ffe17c503cdb4017 (patch) | |
tree | 16b2ee2c5daf1a45f255fc3b2d8d5bd1e79de94b /kvmd/plugins/msd/otg | |
parent | 9925198762ab355343eb759e8117827a17645508 (diff) |
refactored msd writer api
Diffstat (limited to 'kvmd/plugins/msd/otg')
-rw-r--r-- | kvmd/plugins/msd/otg/__init__.py | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py index 6ff6e9ab..96ef9289 100644 --- a/kvmd/plugins/msd/otg/__init__.py +++ b/kvmd/plugins/msd/otg/__init__.py @@ -58,7 +58,7 @@ from .. import MsdUnknownImageError from .. import MsdImageExistsError from .. import BaseMsd from .. import MsdFileReader -from .. import MsdImageWriter +from .. import MsdFileWriter from . import fs @@ -166,7 +166,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes self.__drive = Drive(gadget, instance=0, lun=0) self.__reader: Optional[MsdFileReader] = None - self.__writer: Optional[MsdImageWriter] = None + self.__writer: Optional[MsdFileWriter] = None self.__notifier = aiotools.AioNotifier() self.__state = _State(self.__notifier) @@ -359,7 +359,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes await self.__notifier.notify() @contextlib.asynccontextmanager - async def write_image(self, name: str, size: int, remove_incomplete: Optional[bool]) -> AsyncGenerator[int, None]: + async def write_image(self, name: str, size: int, remove_incomplete: Optional[bool]) -> AsyncGenerator[MsdFileWriter, None]: try: async with self.__state._region: # pylint: disable=protected-access path: str = "" @@ -379,15 +379,16 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes await self.__remount_rw(True) self.__set_image_complete(name, False) - self.__writer = await MsdImageWriter( + self.__writer = await MsdFileWriter( notifier=self.__notifier, path=path, - size=size, - sync=self.__sync_chunk_size, + file_size=size, + sync_size=self.__sync_chunk_size, + chunk_size=self.__write_chunk_size, ).open() await self.__notifier.notify() - yield self.__write_chunk_size + yield self.__writer self.__set_image_complete(name, self.__writer.is_complete()) finally: @@ -405,10 +406,6 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes await self.__reload_state() await self.__notifier.notify() - async def write_image_chunk(self, chunk: bytes) -> int: - assert self.__writer - return (await self.__writer.write(chunk)) - @aiotools.atomic async def remove(self, name: str) -> None: async with self.__state.busy(): |