diff --git a/ChangeLog b/ChangeLog index 62b045c22..260b7ef4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -44,6 +44,8 @@ release 0.14.4 (should mean a slight performance improvement) * fixed a bug where a failed rename_file() would leave the storage in an error state which would pause the torrent + * fixed case when move_storage() would fail. Added a new alert + to be posted when it does release 0.14.3 diff --git a/docs/manual.rst b/docs/manual.rst index c1ca747ad..b7746a560 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -2002,7 +2002,8 @@ drop while copying the file. Since disk IO is performed in a separate thread, this operation is also asynchronous. Once the operation completes, the ``storage_moved_alert`` is generated, with the new -path as the message. +path as the message. If the move fails for some reason, ``storage_moved_failed_alert`` +is generated instead, containing the error message. rename_file() ------------- @@ -4974,6 +4975,21 @@ the storage. }; +storage_moved_failed_alert +-------------------------- + +The ``storage_moved_failed_alert`` is generated when an attempt to move the storage +(via torrent_handle::move_storage()) fails. + +:: + + struct storage_moved_failed_alert: torrent_alert + { + // ... + error_code error; + }; + + torrent_paused_alert -------------------- diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index a78e5a634..1e24625b2 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -773,6 +773,27 @@ namespace libtorrent } }; + struct TORRENT_EXPORT storage_moved_failed_alert: torrent_alert + { + storage_moved_failed_alert(torrent_handle const& h, error_code const& ec_) + : torrent_alert(h) + , error(ec_) + {} + + error_code error; + + virtual std::auto_ptr clone() const + { return std::auto_ptr(new storage_moved_failed_alert(*this)); } + virtual char const* what() const { return "storage moved failed"; } + const static int static_category = alert::storage_notification; + virtual int category() const { return static_category; } + virtual std::string message() const + { + return torrent_alert::message() + " storage move failed: " + + error.message(); + } + }; + struct TORRENT_EXPORT torrent_deleted_alert: torrent_alert { torrent_deleted_alert(torrent_handle const& h) diff --git a/src/torrent.cpp b/src/torrent.cpp index 0369f06be..f7ec87e23 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -4123,6 +4123,10 @@ namespace libtorrent else { m_save_path = save_path; + if (alerts().should_post()) + { + alerts().post_alert(storage_moved_alert(get_handle(), m_save_path.string())); + } } } @@ -4130,11 +4134,21 @@ namespace libtorrent { session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); - if (alerts().should_post()) + if (ret == 0) { - alerts().post_alert(storage_moved_alert(get_handle(), j.str)); + if (alerts().should_post()) + { + alerts().post_alert(storage_moved_alert(get_handle(), j.str)); + } + m_save_path = j.str; + } + else + { + if (alerts().should_post()) + { + alerts().post_alert(storage_moved_failed_alert(get_handle(), j.error)); + } } - m_save_path = j.str; } piece_manager& torrent::filesystem()