Skip to content

Commit

Permalink
fix duplicated file entry on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba committed Oct 28, 2022
1 parent 6bcf68e commit e7e7ad7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lbry/torrent/torrent_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def full_path(self) -> Optional[str]:
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)
Expand All @@ -59,6 +59,9 @@ async def start(self, timeout: Optional[float] = None, save_now: Optional[bool]
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
Expand Down Expand Up @@ -173,7 +176,7 @@ async def _load_stream(self, rowid: int, bt_infohash: str, file_name: Optional[s
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():
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/datanetwork/test_file_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ async def test_download_torrent(self):
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)
Expand Down

0 comments on commit e7e7ad7

Please sign in to comment.