From d3c55f2b0ef3883f350e8a84072ec0e2924814a8 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sun, 15 Dec 2019 17:18:11 +0100 Subject: [PATCH] Fetch metadata of stopped magnets --- libtransmission/torrent-magnet.c | 2 +- libtransmission/torrent.c | 13 +++++++++++-- libtransmission/torrent.h | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libtransmission/torrent-magnet.c b/libtransmission/torrent-magnet.c index 33e820f26..eb27a58c9 100644 --- a/libtransmission/torrent-magnet.c +++ b/libtransmission/torrent-magnet.c @@ -339,7 +339,7 @@ void tr_torrentSetMetadataPiece(tr_torrent* tor, int piece, void const* data, in tor->incompleteMetadata = NULL; tor->isStopping = true; tor->magnetVerify = true; - tor->startAfterVerify = true; + tor->startAfterVerify = !tor->prefetchMagnetMetadata; tr_torrentMarkEdited(tor); } else /* drat. */ diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 330358865..5fc1b0ea5 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -1058,8 +1058,16 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor) if (isNewTorrent) { - tor->startAfterVerify = doStart; - tr_torrentVerify(tor, NULL, NULL); + if (!tr_torrentHasMetadata(tor) && !doStart) + { + tor->prefetchMagnetMetadata = true; + tr_torrentStartNow(tor); + } + else + { + tor->startAfterVerify = doStart; + tr_torrentVerify(tor, NULL, NULL); + } } else if (doStart) { @@ -2058,6 +2066,7 @@ void tr_torrentStop(tr_torrent* tor) tor->isRunning = false; tor->isStopping = false; + tor->prefetchMagnetMetadata = false; tr_torrentSetDirty(tor); tr_runInEventThread(tor->session, stopTorrent, tor); diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index e0c9aca3b..509b58145 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -225,6 +225,7 @@ struct tr_torrent bool isDirty; bool isQueued; + bool prefetchMagnetMetadata; bool magnetVerify; bool infoDictOffsetIsCached;