From a2fcaa15c96880def22add9bbab5ea9e8fb2d416 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sun, 19 Jan 2014 16:14:48 +0000 Subject: [PATCH] Fix #2006 : Display error when moving storage location fails Adds handler for storage_moved_failed_alert and then sets the torrent to Error state and pauses it. --- deluge/core/torrent.py | 12 ++++++++---- deluge/core/torrentmanager.py | 13 +++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index d438dff1e..8c9f8c78e 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -182,11 +182,11 @@ class Torrent(object): # Various torrent options self.handle.resolve_countries(True) - self.set_options(self.options) - # Status message holds error info about the torrent self.statusmsg = "OK" + self.set_options(self.options) + # The torrent's state self.state = None @@ -452,8 +452,7 @@ class Torrent(object): log.debug("set_state_based_on_ltstate: %s", deluge.common.LT_TORRENT_STATE[ltstate]) log.debug("session.is_paused: %s", session_is_paused) - # First we check for an error from libtorrent, and set the state to that - # if any occurred. + # First we check for an error from libtorrent, and set the state to that if any occurred. if len(status.error) > 0: # This is an error'd torrent self.state = "Error" @@ -461,6 +460,11 @@ class Torrent(object): if status.paused: self.handle.auto_managed(False) return + elif self.statusmsg.startswith("Error:"): + self.state = "Error" + if status.paused: + self.handle.auto_managed(False) + return else: self.set_status_message("OK") diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index f511210b0..d2621b402 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -182,6 +182,7 @@ class TorrentManager(component.Component): self.alerts.register_handler("tracker_warning_alert", self.on_alert_tracker_warning) self.alerts.register_handler("tracker_error_alert", self.on_alert_tracker_error) self.alerts.register_handler("storage_moved_alert", self.on_alert_storage_moved) + self.alerts.register_handler("storage_moved_failed_alert", self.on_alert_storage_moved_failed) self.alerts.register_handler("torrent_resumed_alert", self.on_alert_torrent_resumed) self.alerts.register_handler("state_changed_alert", self.on_alert_state_changed) self.alerts.register_handler("save_resume_data_alert", self.on_alert_save_resume_data) @@ -1028,6 +1029,18 @@ class TorrentManager(component.Component): torrent.set_save_path(os.path.normpath(alert.handle.save_path())) torrent.set_move_completed(False) + def on_alert_storage_moved_failed(self, alert): + """Alert handler for libtorrent storage_moved_failed_alert""" + log.warning("on_alert_storage_moved_failed: %s", decode_string(alert.message())) + try: + torrent_id = str(alert.handle.info_hash()) + torrent = self.torrents[torrent_id] + except (RuntimeError, KeyError): + return + # Set an Error message and pause the torrent + torrent.set_status_message("Error: moving storage location failed") + torrent.pause() + def on_alert_torrent_resumed(self, alert): """Alert handler for libtorrent torrent_resumed_alert""" log.debug("on_alert_torrent_resumed")