From d29d1b13950daf604e9167fa0e57b60ae3620022 Mon Sep 17 00:00:00 2001 From: timotheyca Date: Thu, 27 Oct 2022 17:26:23 +0300 Subject: [PATCH] _build_file --- ptvp35/__init__.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ptvp35/__init__.py b/ptvp35/__init__.py index cd8cc3b..5110ed7 100644 --- a/ptvp35/__init__.py +++ b/ptvp35/__init__.py @@ -209,16 +209,19 @@ class Db: self.__path_recover.unlink() self.__path_backup.unlink() + async def _build_file(self, db: dict): + with open(self.__path_backup, "w") as file: + self.__initial_size = await self.__loop.run_in_executor(None, self.db2io, db, file) + self.__path_recover.touch() + await self._finish_recovery() + async def _rebuild_file(self, db: dict): if self.__path_recover.exists(): await self._finish_recovery() self.__path.touch() with open(self.__path) as file: await self.__loop.run_in_executor(None, self.io2db, file, db) - with open(self.__path_backup, "w") as file: - self.__initial_size = await self.__loop.run_in_executor(None, self.db2io, db, file) - self.__path_recover.touch() - await self._finish_recovery() + await self._build_file(db) async def _reload(self): self.__file.close() @@ -257,10 +260,7 @@ class Db: self.__task.cancel() await self._dump_buffer() self.__file.close() - with open(self.__path_backup, "w") as file: - self.__initial_size = await self.__loop.run_in_executor(None, self.db2io, self.__mmdb, file) - self.__path_recover.touch() - await self._finish_recovery() + await self._build_file(self.__mmdb) def _uninitialize(self): self.__mmdb = None