From 31e5716b03977f6968938e16b9d921eabefe482f Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 21 Oct 2007 00:19:37 +0000 Subject: [PATCH] fixed #186 and added a better test --- src/storage.cpp | 8 +++----- test/test_storage.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/storage.cpp b/src/storage.cpp index 6671e38e9..58791572a 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -485,11 +485,12 @@ namespace libtorrent { std::string p = (m_save_path / i->path).string(); fs::path bp = i->path.branch_path(); - std::pair ret = directories.insert(bp.string()); + std::pair ret; + ret.second = true; while (ret.second && !bp.empty()) { + std::pair ret = directories.insert((m_save_path / bp).string()); bp = bp.branch_path(); - std::pair ret = directories.insert(bp.string()); } std::remove(p.c_str()); } @@ -498,9 +499,6 @@ namespace libtorrent // subdirectories first std::for_each(directories.rbegin(), directories.rend() , 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 diff --git a/test/test_storage.cpp b/test/test_storage.cpp index f32c56547..cf7b33f98 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -133,6 +133,37 @@ void run_storage_tests(boost::intrusive_ptr info } } +void test_remove(path const& test_path) +{ + boost::intrusive_ptr 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 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) { 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); remove_all(test_path / "temp_storage"); + + +// ============================================== + + std::cerr << "=== test 5 ===" << std::endl; + test_remove(test_path); + } int test_main() @@ -220,6 +258,7 @@ int test_main() } std::for_each(test_paths.begin(), test_paths.end(), bind(&run_test, _1)); + return 0; }