diff --git a/include/libtorrent/disk_interface.hpp b/include/libtorrent/disk_interface.hpp index b290ee8f7..be19aed39 100644 --- a/include/libtorrent/disk_interface.hpp +++ b/include/libtorrent/disk_interface.hpp @@ -69,10 +69,9 @@ namespace libtorrent virtual void async_hash(storage_interface* storage, int piece, int flags , std::function handler, void* requester) = 0; virtual void async_move_storage(storage_interface* storage, std::string const& p, int flags - , std::function handler) = 0; + , std::function handler) = 0; virtual void async_release_files(storage_interface* storage - , std::function handler - = std::function()) = 0; + , std::function handler = std::function()) = 0; virtual void async_check_files(storage_interface* storage , add_torrent_params const* resume_data , std::vector& links diff --git a/include/libtorrent/disk_io_job.hpp b/include/libtorrent/disk_io_job.hpp index f74d95d55..636dcc5fa 100644 --- a/include/libtorrent/disk_io_job.hpp +++ b/include/libtorrent/disk_io_job.hpp @@ -157,9 +157,16 @@ namespace libtorrent , char* block, int flags, storage_error const& se)>; using write_handler = std::function; using hash_handler = std::function; + using move_handler = std::function; + using release_handler = std::function; using generic_handler = std::function; - boost::variant callback; + boost::variant callback; // the error code from the file operation // on error, this also contains the path of the diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 502386745..f0ff3c14e 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -301,10 +301,9 @@ namespace libtorrent void async_hash(storage_interface* storage, int piece, int flags , std::function handler, void* requester) override; void async_move_storage(storage_interface* storage, std::string const& p, int flags - , std::function handler) override; + , std::function handler) override; void async_release_files(storage_interface* storage - , std::function handler - = std::function()) override; + , std::function handler = std::function()) override; void async_delete_files(storage_interface* storage, int options , std::function handler) override; void async_check_files(storage_interface* storage diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 6617ec556..ed7066a08 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1118,9 +1118,10 @@ namespace libtorrent void on_files_deleted(disk_io_job const* j); void on_torrent_paused(disk_io_job const* j); - void on_storage_moved(disk_io_job const* j); + void on_storage_moved(int status, std::string const& path + , storage_error const& error); void on_file_renamed(disk_io_job const* j); - void on_cache_flushed(disk_io_job const* j); + void on_cache_flushed(); // upload and download rate limits for the torrent void set_limit_impl(int limit, int channel, bool state_update = true); diff --git a/src/disk_io_job.cpp b/src/disk_io_job.cpp index 33202eeaa..071ac1964 100644 --- a/src/disk_io_job.cpp +++ b/src/disk_io_job.cpp @@ -58,6 +58,18 @@ namespace libtorrent h(m_job.ret, m_job.piece, sha1_hash(m_job.d.piece_hash), m_job.error); } + void operator()(disk_io_job::move_handler& h) const + { + if (!h) return; + h(m_job.ret, std::string(m_job.buffer.string), m_job.error); + } + + void operator()(disk_io_job::release_handler& h) const + { + if (!h) return; + h(); + } + void operator()(disk_io_job::generic_handler& h) const { if (!h) return; diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 3c8cdb930..889515187 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1761,7 +1761,7 @@ namespace libtorrent } void disk_io_thread::async_move_storage(storage_interface* storage, std::string const& p, int flags - , std::function handler) + , std::function handler) { disk_io_job* j = allocate_job(disk_io_job::move_storage); j->storage = storage->shared_from_this(); @@ -1773,7 +1773,7 @@ namespace libtorrent } void disk_io_thread::async_release_files(storage_interface* storage - , std::function handler) + , std::function handler) { disk_io_job* j = allocate_job(disk_io_job::release_files); j->storage = storage->shared_from_this(); diff --git a/src/torrent.cpp b/src/torrent.cpp index b6c7c06b3..83f69b701 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2154,8 +2154,7 @@ namespace libtorrent // now. leave_seed_mode(true); - m_ses.disk_thread().async_release_files(m_storage.get() - , std::function()); + m_ses.disk_thread().async_release_files(m_storage.get()); // forget that we have any pieces m_have_all = false; @@ -4321,7 +4320,7 @@ namespace libtorrent if (m_storage.get()) { m_ses.disk_thread().async_stop_torrent(m_storage.get() - , std::bind(&torrent::on_cache_flushed, shared_from_this(), _1)); + , std::bind(&torrent::on_cache_flushed, shared_from_this())); } else { @@ -7426,7 +7425,7 @@ namespace libtorrent { // we need to keep the object alive during this operation m_ses.disk_thread().async_release_files(m_storage.get() - , std::bind(&torrent::on_cache_flushed, shared_from_this(), _1)); + , std::bind(&torrent::on_cache_flushed, shared_from_this())); } // this torrent just completed downloads, which means it will fall @@ -7761,7 +7760,7 @@ namespace libtorrent std::string const& path = save_path; #endif m_ses.disk_thread().async_move_storage(m_storage.get(), path, flags - , std::bind(&torrent::on_storage_moved, shared_from_this(), _1)); + , std::bind(&torrent::on_storage_moved, shared_from_this(), _1, _2, _3)); m_moving_storage = true; } else @@ -7781,26 +7780,27 @@ namespace libtorrent } } - void torrent::on_storage_moved(disk_io_job const* j) try + void torrent::on_storage_moved(int const status, std::string const& path + , storage_error const& error) try { TORRENT_ASSERT(is_single_thread()); m_moving_storage = false; - if (j->ret == disk_interface::no_error - || j->ret == disk_interface::need_full_check) + if (status == disk_interface::no_error + || status == disk_interface::need_full_check) { if (alerts().should_post()) - alerts().emplace_alert(get_handle(), j->buffer.string); - m_save_path = j->buffer.string; + alerts().emplace_alert(get_handle(), path); + m_save_path = path; set_need_save_resume(); - if (j->ret == disk_interface::need_full_check) + if (status == disk_interface::need_full_check) force_recheck(); } else { if (alerts().should_post()) - alerts().emplace_alert(get_handle(), j->error.ec - , resolve_filename(j->error.file), j->error.operation_str()); + alerts().emplace_alert(get_handle(), error.ec + , resolve_filename(error.file), error.operation_str()); } } catch (...) { handle_exception(); } @@ -8533,10 +8533,10 @@ namespace libtorrent return; } m_ses.disk_thread().async_release_files(m_storage.get() - , std::bind(&torrent::on_cache_flushed, shared_from_this(), _1)); + , std::bind(&torrent::on_cache_flushed, shared_from_this())); } - void torrent::on_cache_flushed(disk_io_job const*) try + void torrent::on_cache_flushed() try { TORRENT_ASSERT(is_single_thread());