Skip to content

Commit e7e7ad7

Browse files
committed
fix duplicated file entry on startup
1 parent 6bcf68e commit e7e7ad7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lbry/torrent/torrent_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def full_path(self) -> Optional[str]:
5050
def mime_type(self) -> Optional[str]:
5151
return guess_media_type(os.path.basename(self.full_path))[0]
5252

53-
async def start(self, timeout: Optional[float] = None, save_now: Optional[bool] = False):
53+
async def setup(self, timeout: Optional[float] = None):
5454
try:
5555
metadata_download = self.torrent_session.add_torrent(self.identifier, self.download_directory)
5656
await asyncio.wait_for(metadata_download, timeout, loop=self.loop)
@@ -59,6 +59,9 @@ async def start(self, timeout: Optional[float] = None, save_now: Optional[bool]
5959
raise DownloadMetadataTimeoutError(self.identifier)
6060
self.download_directory = self.torrent_session.save_path(self.identifier)
6161
self._file_name = Path(self.torrent_session.full_path(self.identifier)).name
62+
63+
async def start(self, timeout: Optional[float] = None, save_now: Optional[bool] = False):
64+
await self.setup(timeout)
6265
await self.storage.add_torrent(self.identifier, self.torrent_length, self.torrent_name)
6366
self.rowid = await self.storage.save_downloaded_file(
6467
self.identifier, self.file_name, self.download_directory, 0.0, added_on=self._added_on
@@ -173,7 +176,7 @@ async def _load_stream(self, rowid: int, bt_infohash: str, file_name: Optional[s
173176
torrent_session=self.torrent_session
174177
)
175178
self.add(stream)
176-
await stream.start()
179+
await stream.setup()
177180

178181
async def initialize_from_database(self):
179182
for file in await self.storage.get_all_torrent_files():

tests/integration/datanetwork/test_file_commands.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ async def test_download_torrent(self):
115115
await self.daemon.file_manager.start()
116116
self.assertEqual((await self.daemon.jsonrpc_file_list())['items'][0].identifier, new_btih)
117117
self.assertItemCount(await self.daemon.jsonrpc_file_list(), 1)
118+
# check it was saved properly, once
119+
self.assertEqual(1, len(await self.daemon.storage.get_all_torrent_files()))
118120

119121
self.assertIn(new_btih, self.client_session._handles)
120122
self.assertNotIn(btih, self.client_session._handles)

0 commit comments

Comments
 (0)