fix: magnet link metainfo corrupted on restart (#2790)

This commit is contained in:
SweetPPro 2022-04-01 22:28:55 +02:00 committed by GitHub
parent a250690f30
commit bfd7797c5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -100,6 +100,7 @@ bool tr_ctorSetMetainfo(tr_ctor* ctor, char const* metainfo, size_t len, tr_erro
bool tr_ctorSetMetainfoFromMagnetLink(tr_ctor* ctor, char const* magnet_link, tr_error** error)
{
ctor->torrent_filename.clear();
ctor->metainfo = {};
return ctor->metainfo.parseMagnet(magnet_link != nullptr ? magnet_link : "", error);
}
@ -290,9 +291,11 @@ bool tr_ctorGetIncompleteDir(tr_ctor const* ctor, char const** setme)
return true;
}
tr_torrent_metainfo&& tr_ctorStealMetainfo(tr_ctor* ctor)
tr_torrent_metainfo tr_ctorStealMetainfo(tr_ctor* ctor)
{
return std::move(ctor->metainfo);
auto metainfo = tr_torrent_metainfo{};
std::swap(ctor->metainfo, metainfo);
return metainfo;
}
tr_torrent_metainfo const* tr_ctorGetMetainfo(tr_ctor const* ctor)

View File

@ -769,7 +769,7 @@ void tr_torrentGotBlock(tr_torrent* tor, tr_block_index_t blockIndex);
tr_peer_id_t const& tr_torrentGetPeerId(tr_torrent* tor);
tr_torrent_metainfo&& tr_ctorStealMetainfo(tr_ctor* ctor);
tr_torrent_metainfo tr_ctorStealMetainfo(tr_ctor* ctor);
bool tr_ctorSetMetainfoFromFile(tr_ctor* ctor, std::string const& filename, tr_error** error);
bool tr_ctorSetMetainfoFromMagnetLink(tr_ctor* ctor, std::string const& filename, tr_error** error);