diff --git a/ChangeLog b/ChangeLog index 760b761e0..80de51e69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -91,6 +91,7 @@ * resume data no longer has timestamps of files * require C++11 to build libtorrent + * fix move_storage with save_path with a trailing slash * fix tracker announce issue, advertising port 0 in secondary IPv6 announce * fix missing boost/noncopyable.hpp includes * fix python binding for torrent_info::creation_date() diff --git a/include/libtorrent/aux_/path.hpp b/include/libtorrent/aux_/path.hpp index 3277c0f29..2cd7301c3 100644 --- a/include/libtorrent/aux_/path.hpp +++ b/include/libtorrent/aux_/path.hpp @@ -148,7 +148,7 @@ namespace libtorrent { TORRENT_EXTRA_EXPORT std::string remove_extension(std::string const& f); TORRENT_EXTRA_EXPORT void replace_extension(std::string& f, std::string const& ext); TORRENT_EXTRA_EXPORT bool is_root_path(std::string const& f); - + TORRENT_EXTRA_EXPORT bool compare_path(std::string const& lhs, std::string const& rhs); // internal used by create_torrent.hpp TORRENT_EXTRA_EXPORT std::string parent_path(std::string const& f); diff --git a/src/path.cpp b/src/path.cpp index fd9d9d6b0..d54d8969d 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -596,6 +596,24 @@ namespace { return false; } + bool compare_path(std::string const& lhs, std::string const& rhs) + { + std::string::size_type const lhs_size = !lhs.empty() + && (lhs[lhs.size()-1] == '/' +#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2) + || lhs[lhs.size()-1] == '\\' +#endif + ) ? lhs.size() - 1 : lhs.size(); + + std::string::size_type const rhs_size = !rhs.empty() + && (rhs[rhs.size()-1] == '/' +#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2) + || rhs[rhs.size()-1] == '\\' +#endif + ) ? rhs.size() - 1 : rhs.size(); + return lhs.compare(0, lhs_size, rhs, 0, rhs_size) == 0; + } + bool has_parent_path(std::string const& f) { if (f.empty()) return false; diff --git a/src/storage_utils.cpp b/src/storage_utils.cpp index fa52e7a82..4baed311c 100644 --- a/src/storage_utils.cpp +++ b/src/storage_utils.cpp @@ -382,7 +382,7 @@ namespace libtorrent { namespace aux { error_code err; std::string subdir = combine_path(save_path, s); - while (subdir != save_path && !err) + while (!compare_path(subdir, save_path) && !err) { remove(subdir, err); subdir = parent_path(subdir); diff --git a/test/test_file.cpp b/test/test_file.cpp index f307a2cfa..dcd1397f1 100644 --- a/test/test_file.cpp +++ b/test/test_file.cpp @@ -205,6 +205,30 @@ TORRENT_TEST(paths) TEST_EQUAL(is_root_path("/"), true); #endif +#ifdef TORRENT_WINDOWS + TEST_CHECK(compare_path("c:\\blah\\", "c:\\blah")); + TEST_CHECK(compare_path("c:\\blah", "c:\\blah")); + TEST_CHECK(compare_path("c:\\blah/", "c:\\blah")); + TEST_CHECK(compare_path("c:\\blah", "c:\\blah\\")); + TEST_CHECK(compare_path("c:\\blah", "c:\\blah")); + TEST_CHECK(compare_path("c:\\blah", "c:\\blah/")); + + TEST_CHECK(!compare_path("c:\\bla", "c:\\blah/")); + TEST_CHECK(!compare_path("c:\\bla", "c:\\blah")); + TEST_CHECK(!compare_path("c:\\blah", "c:\\bla")); + TEST_CHECK(!compare_path("c:\\blah\\sdf", "c:\\blah")); +#else + TEST_CHECK(compare_path("/blah", "/blah")); + TEST_CHECK(compare_path("/blah/", "/blah")); + TEST_CHECK(compare_path("/blah", "/blah")); + TEST_CHECK(compare_path("/blah", "/blah/")); + + TEST_CHECK(!compare_path("/bla", "/blah/")); + TEST_CHECK(!compare_path("/bla", "/blah")); + TEST_CHECK(!compare_path("/blah", "/bla")); + TEST_CHECK(!compare_path("/blah/sdf", "/blah")); +#endif + // if has_parent_path() returns false // parent_path() should return the empty string TEST_EQUAL(parent_path("blah"), "");