From 2bea8f58e0746a7385b393d341d0c0d332483401 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 28 Oct 2022 19:44:00 -0300 Subject: [PATCH] fix duplicated file entry on startup --- lbry/torrent/torrent_manager.py | 7 +++++-- tests/integration/datanetwork/test_file_commands.py | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lbry/torrent/torrent_manager.py b/lbry/torrent/torrent_manager.py index b6ac5ed3d..ce873b07c 100644 --- a/lbry/torrent/torrent_manager.py +++ b/lbry/torrent/torrent_manager.py @@ -50,7 +50,7 @@ class TorrentSource(ManagedDownloadSource): def mime_type(self) -> Optional[str]: return guess_media_type(os.path.basename(self.full_path))[0] - async def start(self, timeout: Optional[float] = None, save_now: Optional[bool] = False): + async def setup(self, timeout: Optional[float] = None): try: metadata_download = self.torrent_session.add_torrent(self.identifier, self.download_directory) await asyncio.wait_for(metadata_download, timeout, loop=self.loop) @@ -59,6 +59,9 @@ class TorrentSource(ManagedDownloadSource): raise DownloadMetadataTimeoutError(self.identifier) self.download_directory = self.torrent_session.save_path(self.identifier) self._file_name = Path(self.torrent_session.full_path(self.identifier)).name + + async def start(self, timeout: Optional[float] = None, save_now: Optional[bool] = False): + await self.setup(timeout) await self.storage.add_torrent(self.identifier, self.torrent_length, self.torrent_name) self.rowid = await self.storage.save_downloaded_file( self.identifier, self.file_name, self.download_directory, 0.0, added_on=self._added_on @@ -173,7 +176,7 @@ class TorrentManager(SourceManager): torrent_session=self.torrent_session ) self.add(stream) - await stream.start() + await stream.setup() async def initialize_from_database(self): for file in await self.storage.get_all_torrent_files(): diff --git a/tests/integration/datanetwork/test_file_commands.py b/tests/integration/datanetwork/test_file_commands.py index 2f7ccd21a..e259041b9 100644 --- a/tests/integration/datanetwork/test_file_commands.py +++ b/tests/integration/datanetwork/test_file_commands.py @@ -115,6 +115,8 @@ class FileCommands(CommandTestCase): await self.daemon.file_manager.start() self.assertEqual((await self.daemon.jsonrpc_file_list())['items'][0].identifier, new_btih) self.assertItemCount(await self.daemon.jsonrpc_file_list(), 1) + # check it was saved properly, once + self.assertEqual(1, len(await self.daemon.storage.get_all_torrent_files())) self.assertIn(new_btih, self.client_session._handles) self.assertNotIn(btih, self.client_session._handles)