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.
This commit is contained in:
Calum Lind 2014-01-19 16:14:48 +00:00
parent 35842af019
commit a2fcaa15c9
2 changed files with 21 additions and 4 deletions

View File

@ -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")

View File

@ -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")