fix bug in recent move_storage patch

This commit is contained in:
Arvid Norberg 2013-05-10 02:18:14 +00:00
parent 982a14c2e9
commit 90a2509d68
2 changed files with 32 additions and 12 deletions

View File

@ -756,17 +756,8 @@ namespace libtorrent
// check to see if any of the files exist
error_code ec;
std::set<std::string> 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<std::string>::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<std::string> 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)

View File

@ -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<storage_interface> const& s)
{
std::cerr << "returned: " << ret
@ -591,6 +600,15 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> 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;