fixed save path updates when moving torrents. Fixes #310

This commit is contained in:
Arvid Norberg 2008-06-15 20:52:46 +00:00
parent 5314b639e2
commit 3e000a3984
4 changed files with 28 additions and 6 deletions

View File

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

View File

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

View File

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

View File

@ -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<torrent_info> info
, file_storage& fs
, path const& test_path
@ -111,16 +118,26 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
ios.reset();
ios.run_one();
}
ios.reset();
ios.poll();
// test move_storage
boost::function<void(int, disk_io_job const&)> 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<torrent_info> 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"));