From 90a2509d68b59f4361d971aa563eb1ea04a422b6 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 10 May 2013 02:18:14 +0000 Subject: [PATCH] fix bug in recent move_storage patch --- src/storage.cpp | 26 ++++++++++++++------------ test/test_storage.cpp | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/storage.cpp b/src/storage.cpp index 2b4fe6b1d..0690507e7 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -756,17 +756,8 @@ namespace libtorrent // check to see if any of the files exist error_code ec; - - std::set to_move; file_storage const& f = files(); - for (file_storage::iterator i = f.begin() - , end(f.end()); i != end; ++i) - { - std::string split = split_path(f.file_path(*i)); - to_move.insert(to_move.begin(), split); - } - file_status s; if (flags == fail_if_exist) { @@ -774,10 +765,10 @@ namespace libtorrent if (ec != boost::system::errc::no_such_file_or_directory) { // the directory exists, check all the files - for (std::set::const_iterator i = to_move.begin() - , end(to_move.end()); i != end; ++i) + for (file_storage::iterator i = f.begin() + , end(f.end()); i != end; ++i) { - std::string new_path = combine_path(save_path, *i); + std::string new_path = combine_path(save_path, f.file_path(*i)); stat_file(new_path, &s, ec); if (ec != boost::system::errc::no_such_file_or_directory) return piece_manager::file_exist; @@ -785,6 +776,17 @@ namespace libtorrent } } + // collect all directories in to_move. This is because we + // try to move entire directories by default (instead of + // files independently). + std::set to_move; + for (file_storage::iterator i = f.begin() + , end(f.end()); i != end; ++i) + { + std::string split = split_path(f.file_path(*i)); + to_move.insert(to_move.begin(), split); + } + ec.clear(); stat_file(save_path, &s, ec); if (ec == boost::system::errc::no_such_file_or_directory) diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 131b0e26a..5dd9e95a7 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -139,6 +139,15 @@ void on_move_storage(int ret, bool* done, disk_io_job const& j, std::string path *done = true; } +void on_move_storage_exist(int ret, bool* done, disk_io_job const& j, std::string path) +{ + std::cerr << "on_move_storage_exist ret: " << ret << " path: " << j.str << std::endl; + TEST_EQUAL(ret, piece_manager::file_exist); + TEST_EQUAL(j.str, path); + *done = true; +} + + void print_error(int ret, boost::scoped_ptr const& s) { std::cerr << "returned: " << ret @@ -591,6 +600,15 @@ void run_storage_tests(boost::intrusive_ptr info TEST_CHECK(!exists(combine_path(test_path, combine_path("temp_storage2", "temp_storage")))); TEST_CHECK(!exists(combine_path(test_path, combine_path("temp_storage2", "part0")))); + done = false; + pm->async_move_storage(test_path, fail_if_exist, boost::bind(&on_move_storage_exist, _1, &done, _2, test_path)); + run_until(ios, done); + + TEST_CHECK(exists(combine_path(test_path, "part0"))); + TEST_CHECK(!exists(combine_path(test_path, combine_path("temp_storage2", "temp_storage")))); + TEST_CHECK(!exists(combine_path(test_path, combine_path("temp_storage2", "part0")))); + + r.piece = 0; r.start = 0; r.length = block_size;