1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-30 10:52:00 +00:00

fix: do not lose magnet links when upgrading from tr3 to 4 (#4840)

This commit is contained in:
Cœur 2023-02-13 08:10:54 +08:00 committed by GitHub
parent dcd7501211
commit 649fd4d0d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 0 deletions

View file

@ -382,6 +382,21 @@ struct MetainfoHandler final : public transmission::benc::BasicHandler<MaxBencDe
{
tm_.addWebseed(value);
}
else if (pathIs(MagnetInfoKey, DisplayNameKey))
{
// compatibility with Transmission <= 3.0
tm_.name_ = tr_strv_replace_invalid(value);
}
else if (pathIs(MagnetInfoKey, InfoHashKey))
{
// compatibility with Transmission <= 3.0
if (value.length() == sizeof(tr_sha1_digest_t))
{
std::copy_n(std::data(value), sizeof(tr_sha1_digest_t), reinterpret_cast<char*>(std::data(tm_.info_hash_)));
tm_.info_hash_str_ = tr_sha1_to_string(tm_.info_hash_);
tm_.has_magnet_info_hash_ = true;
}
}
else if (
pathIs(ChecksumKey) || //
pathIs(ErrCallbackKey) || //
@ -495,6 +510,12 @@ private:
bool finish(Context const& context)
{
// Support Transmission <= 3.0 magnets stored in torrent format.
if (tm_.has_magnet_info_hash_)
{
return true;
}
// bittorrent 1.0 spec
// http://bittorrent.org/beps/bep_0003.html
//
@ -544,6 +565,7 @@ private:
static constexpr std::string_view CreatedByKey = "created by"sv;
static constexpr std::string_view CreatedByUtf8Key = "created by.utf-8"sv;
static constexpr std::string_view CreationDateKey = "creation date"sv;
static constexpr std::string_view DisplayNameKey = "display-name"sv;
static constexpr std::string_view DurationKey = "duration"sv;
static constexpr std::string_view Ed2kKey = "ed2k"sv;
static constexpr std::string_view EncodedRateKey = "encoded rate"sv;
@ -558,6 +580,7 @@ private:
static constexpr std::string_view HeightKey = "height"sv;
static constexpr std::string_view HttpSeedsKey = "httpseeds"sv;
static constexpr std::string_view InfoKey = "info"sv;
static constexpr std::string_view InfoHashKey = "info_hash"sv;
static constexpr std::string_view LengthKey = "length"sv;
static constexpr std::string_view LibtorrentResumeKey = "libtorrent_resume"sv;
static constexpr std::string_view LocaleKey = "locale"sv;

View file

@ -243,6 +243,7 @@ private:
// Used when loading piece checksums on demand.
uint64_t pieces_offset_ = 0;
bool has_magnet_info_hash_ = false;
bool is_private_ = false;
bool is_v2_ = false;
};

View file

@ -0,0 +1 @@
d13:announce-listll42:udp://tracker.opentrackr.org:1337/announceel43:udp://tracker.coppersurfer.tk:6969/announceel49:udp://tracker.leechers-paradise.org:6969/announceel44:udp://tracker.openbittorrent.com:80/announceel40:https://ashrise.com:443/phoenix/announceee11:magnet-infod12:display-name24:gimp-2.10.32-1-arm64.dmg9:info_hash20:ÀG¸u˜ðôºå­ôÉúiÒËe8:url-listl49:https://ftp.acc.umu.se/pub/gimp/gimp/v2.10/macos/56:https://ftp.cc.uoc.gr/mirrors/gimp/pub/gimp/v2.10/macos/41:https://ftp.fau.de/gimp/gimp/v2.10/macos/57:https://ftp.gwdg.de/pub/grafik/gimp-org/gimp/v2.10/macos/58:https://ftp.icm.edu.pl/pub/graphics/gimp/gimp/v2.10/macos/57:https://ftp.kr.freebsd.org/pub/gimp/pub/gimp/v2.10/macos/53:https://ftp.lysator.liu.se/pub/gimp/gimp/v2.10/macos/62:https://ftp.snt.utwente.nl/pub/software/gimp/gimp/v2.10/macos/46:https://gimp.astra.in.ua/pub/gimp/v2.10/macos/46:https://gimp.ip-connect.info/gimp/v2.10/macos/47:https://gimp.ip-connect.vn.ua/gimp/v2.10/macos/47:https://mirror.dogado.de/gimp/gimp/v2.10/macos/53:https://mirror.edgeuno.net/gimp/pub/gimp/v2.10/macos/46:https://mirror.fcix.net/gimp/gimp/v2.10/macos/53:https://mirror.freedif.org/gimp/pub/gimp/v2.10/macos/54:https://mirror.kumi.systems/gimp/pub/gimp/v2.10/macos/48:https://mirror.metanet.ch/gimp/gimp/v2.10/macos/48:https://mirror.nju.edu.cn/gimp/gimp/v2.10/macos/46:https://mirror.surf/gimp/pub/gimp/v2.10/macos/45:https://mirror.umd.edu/gimp/gimp/v2.10/macos/70:https://mirror2.sandyriver.net/pub/software/gimp/pub/gimp/v2.10/macos/53:https://mirrors.dotsrc.org/gimp/pub/gimp/v2.10/macos/59:https://mirrors.gethosted.online/gimp/pub/gimp/v2.10/macos/59:https://mirrors.ocf.berkeley.edu/gimp/pub/gimp/v2.10/macos/65:https://mirrors.ukfast.co.uk/sites/gimp.org/pub/gimp/v2.10/macos/51:https://mirrors.xmission.com/gimp/gimp/v2.10/macos/52:https://paducahix.mm.fcix.net/gimp/gimp/v2.10/macos/50:https://www-ftp.lip6.fr/pub/gimp/gimp/v2.10/macos/48:https://www.gimp.ca/mirror/pub/gimp/v2.10/macos/70:https://www.mirrorservice.org/sites/ftp.gimp.org/pub/gimp/v2.10/macos/71:https://www.nic.funet.fi/pub/mirrors/ftp.gimp.org/pub/gimp/v2.10/macos/43:https://download.gimp.org/gimp/v2.10/macos/ee

View file

@ -219,6 +219,14 @@ TEST_F(TorrentMetainfoTest, ctorSaveContents)
tr_ctorFree(ctor);
}
TEST_F(TorrentMetainfoTest, magnetInfoHash)
{
// compatibility with magnet torrents created by Transmission <= 3.0
auto const src_filename = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, "/gimp-2.10.32-1-arm64.dmg.torrent"sv };
auto tm = tr_torrent_metainfo{};
EXPECT_TRUE(tm.parseTorrentFile(src_filename));
}
TEST_F(TorrentMetainfoTest, HoffmanStyleWebseeds)
{
auto const src_filename = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, "/debian-11.2.0-amd64-DVD-1.iso.torrent"sv };