fixed move_stororage to handle the case where it fails

This commit is contained in:
Arvid Norberg 2009-05-11 21:18:09 +00:00
parent 136f101449
commit 92f42eb23c
4 changed files with 57 additions and 4 deletions

View File

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

View File

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

View File

@ -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<alert> clone() const
{ return std::auto_ptr<alert>(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)

View File

@ -4123,6 +4123,10 @@ namespace libtorrent
else
{
m_save_path = save_path;
if (alerts().should_post<storage_moved_alert>())
{
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<storage_moved_alert>())
if (ret == 0)
{
alerts().post_alert(storage_moved_alert(get_handle(), j.str));
if (alerts().should_post<storage_moved_alert>())
{
alerts().post_alert(storage_moved_alert(get_handle(), j.str));
}
m_save_path = j.str;
}
else
{
if (alerts().should_post<storage_moved_failed_alert>())
{
alerts().post_alert(storage_moved_failed_alert(get_handle(), j.error));
}
}
m_save_path = j.str;
}
piece_manager& torrent::filesystem()