From 838df441847d710ebb74aa740eee17912b39030b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 7 May 2009 06:41:41 +0000 Subject: [PATCH] documented file_rename_failed_alert and file_renamed_alert. they were previously not documented. Fixed bug where the storage would be left in an error state (and eventually pause the torrent) when a rename_file() failed. The error is now only reported back through the alert --- ChangeLog | 2 ++ docs/manual.rst | 36 ++++++++++++++++++++++++++++++ include/libtorrent/alert_types.hpp | 12 +++++----- src/disk_io_thread.cpp | 5 +++++ src/torrent.cpp | 3 ++- 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8b9e9f589..62b045c22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -42,6 +42,8 @@ release 0.14.4 * fixed magnet link parser to accept hex-encoded info-hashes * fixed inverted logic when picking which peers to connect to (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 release 0.14.3 diff --git a/docs/manual.rst b/docs/manual.rst index 62ba002c4..c1ca747ad 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -4587,6 +4587,42 @@ generated and the torrent is paused. std::string msg; }; +file_renamed_alert +------------------------ + +This is posted as a response to a ``torrent_handle::rename_file`` call, if the rename +operation succeeds. + +:: + + struct file_renamed_alert: torrent_alert + { + // ... + std::string name; + int index; + }; + +The ``index`` member refers to the index of the file that was renamed, +``name`` is the new name of the file. + + +file_rename_failed_alert +------------------------ + +This is posted as a response to a ``torrent_handle::rename_file`` call, if the rename +operation failed. + +:: + + struct file_rename_failed_alert: torrent_alert + { + // ... + int index; + error_code error; + }; + +The ``index`` member refers to the index of the file that was supposed to be renamed, +``error`` is the error code returned from the filesystem. tracker_announce_alert ---------------------- diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index bc5fcf3a9..a78e5a634 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -155,11 +155,11 @@ namespace libtorrent struct TORRENT_EXPORT file_rename_failed_alert: torrent_alert { file_rename_failed_alert(torrent_handle const& h - , std::string const& msg_ - , int index_) + , int index_ + , error_code ec_) : torrent_alert(h) - , msg(msg_) , index(index_) + , error(ec_) {} virtual std::auto_ptr clone() const @@ -169,16 +169,16 @@ namespace libtorrent virtual std::string message() const { char ret[200 + NAME_MAX]; - snprintf(ret, sizeof(msg), "%s: failed to rename file %d: %s" - , torrent_alert::message().c_str(), index, msg.c_str()); + snprintf(ret, sizeof(ret), "%s: failed to rename file %d: %s" + , torrent_alert::message().c_str(), index, error.message().c_str()); return ret; } const static int static_category = alert::storage_notification; virtual int category() const { return static_category; } - std::string msg; int index; + error_code error; }; struct TORRENT_EXPORT performance_alert: torrent_alert diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index fb81da162..a137462bd 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1524,6 +1524,11 @@ namespace libtorrent m_log << log_time() << " rename_file" << std::endl; #endif ret = j.storage->rename_file_impl(j.piece, j.str); + if (ret != 0) + { + test_error(j); + break; + } } } #ifndef BOOST_NO_EXCEPTIONS diff --git a/src/torrent.cpp b/src/torrent.cpp index 491967fa8..454efd962 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2068,7 +2068,8 @@ namespace libtorrent else { if (alerts().should_post()) - alerts().post_alert(file_rename_failed_alert(get_handle(), j.str, j.piece)); + alerts().post_alert(file_rename_failed_alert(get_handle() + , j.piece, j.error)); } } }