diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index a1fbdc2ba..8a7bb15a8 100755 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -321,7 +321,7 @@ namespace libtorrent int rename_file_impl(int index, std::string const& new_filename) { return m_storage->rename_file(index, new_filename); } - bool move_storage_impl(fs::path const& save_path); + int move_storage_impl(fs::path const& save_path); int allocate_slot_for_piece(int piece_index); #ifndef NDEBUG diff --git a/src/storage.cpp b/src/storage.cpp index 327d9e20a..1c16a866d 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1409,14 +1409,14 @@ namespace libtorrent return m_storage->hash_for_slot(slot, ph, m_files.piece_size(piece)); } - bool piece_manager::move_storage_impl(fs::path const& save_path) + int piece_manager::move_storage_impl(fs::path const& save_path) { if (m_storage->move_storage(save_path)) { m_save_path = fs::complete(save_path); - return true; + return 0; } - return false; + return -1; } void piece_manager::write_resume_data(entry& rd) const diff --git a/src/torrent.cpp b/src/torrent.cpp index 7e74379ba..88d1f2325 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3249,6 +3249,7 @@ namespace libtorrent { alerts().post_alert(storage_moved_alert(get_handle(), j.str)); } + m_save_path = j.str; } piece_manager& torrent::filesystem() diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 569c3ffe7..d2f0a1d6d 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -50,6 +50,13 @@ void on_check_files(int ret, disk_io_job const& j) std::cerr << "on_check_files ret: " << ret << " " << j.piece << std::endl; } +void on_move_storage(int ret, disk_io_job const& j, std::string path) +{ + std::cerr << "on_move_storage ret: " << ret << " path:" << j.str << std::endl; + TEST_CHECK(ret == 0); + TEST_CHECK(j.str == path); +} + void run_storage_tests(boost::intrusive_ptr info , file_storage& fs , path const& test_path @@ -111,16 +118,26 @@ void run_storage_tests(boost::intrusive_ptr info ios.reset(); ios.run_one(); } + ios.reset(); + ios.poll(); // test move_storage boost::function none; TEST_CHECK(exists(test_path / "temp_storage")); - pm->async_move_storage(test_path / "temp_storage2", none); + pm->async_move_storage(test_path / "temp_storage2", bind(on_move_storage, _1, _2, (test_path / "temp_storage2").string())); + test_sleep(2000); + ios.reset(); + ios.poll(); + TEST_CHECK(!exists(test_path / "temp_storage")); TEST_CHECK(exists(test_path / "temp_storage2/temp_storage")); - pm->async_move_storage(test_path, none); + pm->async_move_storage(test_path, bind(on_move_storage, _1, _2, test_path.string())); + test_sleep(2000); + ios.reset(); + ios.poll(); + TEST_CHECK(!exists(test_path / "temp_storage2/temp_storage")); remove_all(test_path / "temp_storage2"); @@ -129,7 +146,11 @@ void run_storage_tests(boost::intrusive_ptr info TEST_CHECK(exists(test_path / "temp_storage/test1.tmp")); TEST_CHECK(!exists(test_path / "part0")); pm->async_rename_file(0, "part0", none); + test_sleep(2000); + ios.reset(); + ios.poll(); + TEST_CHECK(!exists(test_path / "temp_storage/test1.tmp")); TEST_CHECK(exists(test_path / "part0"));