_build_file

This commit is contained in:
AF 2022-10-27 17:26:23 +03:00
parent f3429eb1eb
commit d29d1b1395

View File

@ -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