diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index ed9c27bfb..08343e494 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -230,10 +230,20 @@ class Torrent(object): if log.isEnabledFor(logging.DEBUG): log.debug("Torrent object created.") + def on_metadata_received(self): + self.handle_has_metadata = True + self.torrent_info = self.handle.get_torrent_info() + if self.options["prioritize_first_last_pieces"]: + self.set_prioritize_first_last(True) + self.write_torrentfile() + def has_metadata(self): if self.handle_has_metadata: return self.handle_has_metadata self.handle_has_metadata = self.handle.has_metadata() + if self.handle_has_metadata: + # We just got the metadata + self.on_metadata_received() return self.handle_has_metadata ## Options methods ## @@ -731,9 +741,6 @@ class Torrent(object): #print " update_status" self.status = status - if self.torrent_info is None and self.has_metadata(): - self.torrent_info = self.handle.get_torrent_info() - def _create_status_funcs(self): #if you add a key here->add it to core.py STATUS_KEYS too. self.status_funcs = { diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 6dafd1939..e5475aecc 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -1104,7 +1104,7 @@ class TorrentManager(component.Component): torrent = self.torrents[str(alert.handle.info_hash())] except: return - torrent.write_torrentfile() + torrent.on_metadata_received() def on_alert_file_error(self, alert): log.debug("on_alert_file_error: %s", decode_string(alert.message()))