fixed #186 and added a better test

This commit is contained in:
Arvid Norberg 2007-10-21 00:19:37 +00:00
parent 960df77d0a
commit 31e5716b03
2 changed files with 42 additions and 5 deletions

View File

@ -485,11 +485,12 @@ namespace libtorrent
{ {
std::string p = (m_save_path / i->path).string(); std::string p = (m_save_path / i->path).string();
fs::path bp = i->path.branch_path(); fs::path bp = i->path.branch_path();
std::pair<iter_t, bool> ret = directories.insert(bp.string()); std::pair<iter_t, bool> ret;
ret.second = true;
while (ret.second && !bp.empty()) while (ret.second && !bp.empty())
{ {
std::pair<iter_t, bool> ret = directories.insert((m_save_path / bp).string());
bp = bp.branch_path(); bp = bp.branch_path();
std::pair<iter_t, bool> ret = directories.insert(bp.string());
} }
std::remove(p.c_str()); std::remove(p.c_str());
} }
@ -498,9 +499,6 @@ namespace libtorrent
// subdirectories first // subdirectories first
std::for_each(directories.rbegin(), directories.rend() std::for_each(directories.rbegin(), directories.rend()
, bind((int(*)(char const*))&std::remove, bind(&std::string::c_str, _1))); , bind((int(*)(char const*))&std::remove, bind(&std::string::c_str, _1)));
std::string p = (m_save_path / m_info->name()).string();
std::remove(p.c_str());
} }
void storage::write_resume_data(entry& rd) const void storage::write_resume_data(entry& rd) const

View File

@ -133,6 +133,37 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
} }
} }
void test_remove(path const& test_path)
{
boost::intrusive_ptr<torrent_info> info(new torrent_info());
info->set_piece_size(4);
info->add_file("temp_storage/test1.tmp", 8);
info->add_file("temp_storage/folder1/test2.tmp", 8);
info->add_file("temp_storage/folder2/test3.tmp", 0);
info->add_file("temp_storage/_folder3/test4.tmp", 0);
info->add_file("temp_storage/_folder3/subfolder/test5.tmp", 8);
char buf[4] = {0, 0, 0, 0};
sha1_hash h = hasher(buf, 4).final();
for (int i = 0; i < 6; ++i) info->set_hash(i, h);
info->create_torrent();
file_pool fp;
boost::scoped_ptr<storage_interface> s(
default_storage_constructor(info, test_path, fp));
// allocate the files and create the directories
s->initialize(true);
TEST_CHECK(exists(test_path / "temp_storage/_folder3/subfolder/test5.tmp"));
TEST_CHECK(exists(test_path / "temp_storage/folder2/test3.tmp"));
s->delete_files();
TEST_CHECK(!exists(test_path / "temp_storage"));
}
void run_test(path const& test_path) void run_test(path const& test_path)
{ {
std::cerr << "\n=== " << test_path.string() << " ===\n" << std::endl; std::cerr << "\n=== " << test_path.string() << " ===\n" << std::endl;
@ -199,6 +230,13 @@ void run_test(path const& test_path)
TEST_CHECK(file_size(test_path / "temp_storage" / "test1.tmp") == 17 + 612 + 1); TEST_CHECK(file_size(test_path / "temp_storage" / "test1.tmp") == 17 + 612 + 1);
remove_all(test_path / "temp_storage"); remove_all(test_path / "temp_storage");
// ==============================================
std::cerr << "=== test 5 ===" << std::endl;
test_remove(test_path);
} }
int test_main() int test_main()
@ -220,6 +258,7 @@ int test_main()
} }
std::for_each(test_paths.begin(), test_paths.end(), bind(&run_test, _1)); std::for_each(test_paths.begin(), test_paths.end(), bind(&run_test, _1));
return 0; return 0;
} }