mirror of
https://github.com/transmission/transmission
synced 2025-03-12 07:03:44 +00:00
refactor: remove tr_ctorSetMetainfoFromHash() (#2116)
* refactor: remove tr_ctorSetMetainfoFromHash()
This commit is contained in:
parent
af4a953cd1
commit
4ecf74081c
7 changed files with 1 additions and 113 deletions
|
@ -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));
|
||||
|
|
|
@ -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*);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -1875,12 +1875,6 @@ bool trashDataFile(char const* filename, tr_error** error)
|
|||
result = static_cast<tr_parse_result>(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_parse_result>(tr_ctorSetMetainfoFromHash(ctor, hashString.UTF8String));
|
||||
}
|
||||
|
||||
if (result == TR_PARSE_OK)
|
||||
{
|
||||
fHandle = tr_torrentNew(ctor, NULL, NULL);
|
||||
|
|
Loading…
Add table
Reference in a new issue