Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #74 from egbertbouman/fix_torrentinfo
Browse files Browse the repository at this point in the history
Fix error in TorrentInfoEndpoint
  • Loading branch information
egbertbouman authored Jun 14, 2024
2 parents 8957694 + 4c2bc38 commit 88f159f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/tribler/core/libtorrent/restapi/torrentinfo_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ async def get_torrent_info(self, request: Request) -> RESTResponse: # noqa: C90
self.download_manager.notifier.notify(Notification.torrent_metadata_added, metadata=metadata_dict)

download = self.download_manager.downloads.get(metadata_dict["infohash"])
metainfo_request = self.download_manager.metainfo_requests.get(metadata_dict["infohash"], [None])[0]
download_is_metainfo_request = download == metainfo_request
metainfo_lookup = self.download_manager.metainfo_requests.get(metadata_dict["infohash"])
metainfo_download = metainfo_lookup.download if metainfo_lookup else None
download_is_metainfo_request = download == metainfo_download

# Check if the torrent is already in the downloads
encoded_metainfo = deepcopy(metainfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ipv8.test.base import TestBase

import tribler
from tribler.core.libtorrent.download_manager.download_manager import MetainfoLookup
from tribler.core.libtorrent.restapi.torrentinfo_endpoint import TorrentInfoEndpoint, recursive_unicode
from tribler.core.libtorrent.torrentdef import TorrentDef, TorrentDefNoMetainfo
from tribler.core.restapi.rest_endpoint import HTTP_BAD_REQUEST, HTTP_INTERNAL_SERVER_ERROR
Expand Down Expand Up @@ -479,7 +480,8 @@ async def test_get_torrent_info_valid_metainfo_request(self) -> None:
Test if a valid metainfo request has its info returned correctly.
"""
tdef = TorrentDef().load_from_memory(TORRENT_WITH_DIRS_CONTENT)
self.download_manager.metainfo_requests = {tdef.infohash: [self.download_manager.downloads.get(tdef.infohash)]}
download = self.download_manager.downloads.get(tdef.infohash)
self.download_manager.metainfo_requests = {tdef.infohash: MetainfoLookup(download, 1)}
with patch("tribler.core.libtorrent.torrentdef.TorrentDef.load", AsyncMock(return_value=tdef)):
response = await self.endpoint.get_torrent_info(GetTorrentInfoRequest({"hops": 0, "uri": "file://"}))
response_body_json = await response_to_json(response)
Expand Down

0 comments on commit 88f159f

Please sign in to comment.