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

This commit is contained in:
Arvid Norberg 2009-05-07 06:41:41 +00:00
parent bc20af9375
commit 838df44184
5 changed files with 51 additions and 7 deletions

View File

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

View File

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

View File

@ -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<alert> 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

View File

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

View File

@ -2068,7 +2068,8 @@ namespace libtorrent
else
{
if (alerts().should_post<file_rename_failed_alert>())
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));
}
}
}