From 4ecf74081cfad75a29f01747b521103b903820de Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 7 Nov 2021 20:04:07 -0600 Subject: [PATCH] refactor: remove tr_ctorSetMetainfoFromHash() (#2116) * refactor: remove tr_ctorSetMetainfoFromHash() --- libtransmission/session.cc | 82 ------------------------------- libtransmission/session.h | 7 --- libtransmission/torrent-ctor.cc | 8 +-- libtransmission/torrent-magnet.cc | 1 - libtransmission/torrent.cc | 2 - libtransmission/transmission.h | 8 --- macosx/Torrent.mm | 6 --- 7 files changed, 1 insertion(+), 113 deletions(-) diff --git a/libtransmission/session.cc b/libtransmission/session.cc index 132b1ce9f..866681801 100644 --- a/libtransmission/session.cc +++ b/libtransmission/session.cc @@ -2074,12 +2074,6 @@ void tr_sessionClose(tr_session* session) tr_session_id_free(session->session_id); tr_lockFree(session->lock); - if (session->metainfoLookup != nullptr) - { - tr_variantFree(session->metainfoLookup); - tr_free(session->metainfoLookup); - } - tr_device_info_free(session->downloadDir); tr_free(session->configDir); tr_free(session->resumeDir); @@ -2580,82 +2574,6 @@ char const* tr_blocklistGetURL(tr_session const* session) **** ***/ -static void metainfoLookupInit(tr_session* session) -{ - TR_ASSERT(tr_isSession(session)); - - tr_variant* lookup = tr_new0(tr_variant, 1); - tr_variantInitDict(lookup, 0); - - int n = 0; - - tr_sys_path_info info; - char const* dirname = tr_getTorrentDir(session); - tr_sys_dir_t odir = (tr_sys_path_get_info(dirname, 0, &info, nullptr) && info.type == TR_SYS_PATH_IS_DIRECTORY) ? - tr_sys_dir_open(dirname, nullptr) : - TR_BAD_SYS_DIR; - - if (odir != TR_BAD_SYS_DIR) - { - tr_ctor* ctor = tr_ctorNew(session); - tr_ctorSetSave(ctor, false); /* since we already have them */ - - /* walk through the directory and find the mappings */ - char const* name = nullptr; - while ((name = tr_sys_dir_read_name(odir, nullptr)) != nullptr) - { - if (tr_str_has_suffix(name, ".torrent")) - { - tr_info inf; - char* path = tr_buildPath(dirname, name, nullptr); - tr_ctorSetMetainfoFromFile(ctor, path); - - if (tr_torrentParse(ctor, &inf) == TR_PARSE_OK) - { - ++n; - tr_variantDictAddStr(lookup, tr_quark_new(inf.hashString), path); - } - - tr_free(path); - } - } - - tr_sys_dir_close(odir, nullptr); - tr_ctorFree(ctor); - } - - session->metainfoLookup = lookup; - tr_logAddDebug("Found %d torrents in \"%s\"", n, dirname); -} - -char const* tr_sessionFindTorrentFile(tr_session const* session, char const* hashString) -{ - if (session->metainfoLookup == nullptr) - { - metainfoLookupInit((tr_session*)session); - } - - char const* filename = nullptr; - (void)tr_variantDictFindStr(session->metainfoLookup, tr_quark_new(hashString), &filename, nullptr); - return filename; -} - -void tr_sessionSetTorrentFile(tr_session* session, char const* hashString, char const* filename) -{ - /* since we walk session->configDir/torrents/ to build the lookup table, - * and tr_sessionSetTorrentFile() is just to tell us there's a new file - * in that same directory, we don't need to do anything here if the - * lookup table hasn't been built yet */ - if (session->metainfoLookup != nullptr) - { - tr_variantDictAddStr(session->metainfoLookup, tr_quark_new(hashString), filename); - } -} - -/*** -**** -***/ - void tr_sessionSetRPCEnabled(tr_session* session, bool isEnabled) { TR_ASSERT(tr_isSession(session)); diff --git a/libtransmission/session.h b/libtransmission/session.h index 8ca7d1596..f47967cef 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -30,7 +30,6 @@ #include "net.h" #include "tr-macros.h" #include "utils.h" -#include "variant.h" enum tr_auto_switch_state_t { @@ -247,8 +246,6 @@ struct tr_session struct tr_announcer* announcer; struct tr_announcer_udp* announcer_udp; - tr_variant* metainfoLookup; - struct event* nowTimer; struct event* saveTimer; @@ -274,10 +271,6 @@ bool tr_sessionAllowsDHT(tr_session const* session); bool tr_sessionAllowsLPD(tr_session const* session); -char const* tr_sessionFindTorrentFile(tr_session const* session, char const* hashString); - -void tr_sessionSetTorrentFile(tr_session* session, char const* hashString, char const* filename); - bool tr_sessionIsAddressBlocked(tr_session const* session, struct tr_address const* addr); void tr_sessionLock(tr_session*); diff --git a/libtransmission/torrent-ctor.cc b/libtransmission/torrent-ctor.cc index c9fc1fb1c..b515dad10 100644 --- a/libtransmission/torrent-ctor.cc +++ b/libtransmission/torrent-ctor.cc @@ -14,7 +14,7 @@ #include "transmission.h" #include "file.h" #include "magnet.h" -#include "session.h" /* tr_sessionFindTorrentFile() */ +#include "session.h" #include "torrent.h" /* tr_ctorGetSave() */ #include "tr-assert.h" #include "utils.h" /* tr_new0 */ @@ -162,12 +162,6 @@ int tr_ctorSetMetainfoFromFile(tr_ctor* ctor, char const* filename) return err; } -int tr_ctorSetMetainfoFromHash(tr_ctor* ctor, char const* hashString) -{ - char const* const filename = tr_sessionFindTorrentFile(ctor->session, hashString); - return filename == nullptr ? EINVAL : tr_ctorSetMetainfoFromFile(ctor, filename); -} - /*** **** ***/ diff --git a/libtransmission/torrent-magnet.cc b/libtransmission/torrent-magnet.cc index e73635c09..ab949ddde 100644 --- a/libtransmission/torrent-magnet.cc +++ b/libtransmission/torrent-magnet.cc @@ -315,7 +315,6 @@ void tr_torrentSetMetadataPiece(tr_torrent* tor, int piece, void const* data, in /* save the new .torrent file */ tr_variantToFile(&newMetainfo, TR_VARIANT_FMT_BENC, tor->info.torrent); - tr_sessionSetTorrentFile(tor->session, tor->info.hashString, tor->info.torrent); tr_torrentGotNewInfoDict(tor); tr_torrentSetDirty(tor); } diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index b97b95195..904726040 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -953,8 +953,6 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor) { tr_torrentSetLocalError(tor, "Unable to save torrent file: %s", tr_strerror(err)); } - - tr_sessionSetTorrentFile(tor->session, tor->info.hashString, path); } } diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 248075620..bd5a2b652 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -863,14 +863,6 @@ int tr_ctorSetMetainfo(tr_ctor* ctor, void const* metainfo, size_t len); /** @brief Set the constructor's metainfo from a local .torrent file */ int tr_ctorSetMetainfoFromFile(tr_ctor* ctor, char const* filename); -/** - * @brief Set the metainfo from an existing file in tr_getTorrentDir(). - * - * This is used by the Mac client on startup to pick and choose which - * torrents to load - */ -int tr_ctorSetMetainfoFromHash(tr_ctor* ctor, char const* hashString); - /** @brief Set how many peers this torrent can connect to. (Default: 50) */ void tr_ctorSetPeerLimit(tr_ctor* ctor, tr_ctorMode mode, uint16_t limit); diff --git a/macosx/Torrent.mm b/macosx/Torrent.mm index adb5f1377..aff4906ab 100644 --- a/macosx/Torrent.mm +++ b/macosx/Torrent.mm @@ -1875,12 +1875,6 @@ bool trashDataFile(char const* filename, tr_error** error) result = static_cast(tr_ctorSetMetainfoFromMagnetLink(ctor, magnetAddress.UTF8String)); } - //backup - shouldn't be needed after upgrade to 1.70 - if (result != TR_PARSE_OK && hashString) - { - result = static_cast(tr_ctorSetMetainfoFromHash(ctor, hashString.UTF8String)); - } - if (result == TR_PARSE_OK) { fHandle = tr_torrentNew(ctor, NULL, NULL);