From cb8e9d3018d28a793dc8a723e27a901b0710ff78 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Thu, 1 Oct 2015 19:15:02 +0100 Subject: [PATCH] [Core] Move add tracker merge into Torrent method --- deluge/core/torrent.py | 14 ++++++++++++++ deluge/core/torrentmanager.py | 12 ++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 32bf03197..c6031acf8 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -591,6 +591,20 @@ class Torrent(object): """ self.tracker_status = status + def merge_trackers(self, torrent_info): + """Merges new trackers in torrent_info into torrent""" + log.info("Adding any new trackers to torrent (%s) already in session...", self.torrent_id) + if not torrent_info: + return + # Don't merge trackers if either torrent has private flag set. + if torrent_info.priv() or self.get_status(["private"])["private"]: + log.info("Adding trackers aborted: Torrent has private flag set.") + else: + for tracker in torrent_info.trackers(): + self.handle.add_tracker({"url": tracker.url, "tier": tracker.tier}) + # Update torrent.trackers from libtorrent handle. + self.set_trackers() + def update_state(self): """Updates the state, based on libtorrent's torrent state""" status = self.handle.status() diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index eb7f24500..23f775a76 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -337,16 +337,8 @@ class TorrentManager(component.Component): # Check for existing torrent in session. if torrent_id in self.get_torrent_list(): log.warning("Unable to add torrent (%s), already in session", torrent_id) - if torrent_info: - log.info("Adding any new trackers to torrent (%s) already in session...", torrent_id) - # Don't merge trackers if either torrent has private flag set. - if torrent_info.priv() or self[torrent_id].get_status(["private"])["private"]: - log.info("Adding trackers aborted: Torrent has private flag set.") - else: - for tracker in torrent_info.trackers(): - self[torrent_id].handle.add_tracker({"url": tracker.url, "tier": tracker.tier}) - # Update torrent.trackers from lt. - self[torrent_id].set_trackers() + # Attempt merge trackers before returning. + self.torrents[torrent_id].merge_trackers(torrent_info) return # Load default options and update if needed.