forked from premiere/premiere-libtorrent
fix move_storage with save_path with a trailing slash
This commit is contained in:
parent
939b380fda
commit
cec300234c
|
@ -1,3 +1,4 @@
|
|||
* 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()
|
||||
|
|
|
@ -149,7 +149,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);
|
||||
|
|
18
src/file.cpp
18
src/file.cpp
|
@ -836,6 +836,24 @@ namespace libtorrent
|
|||
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;
|
||||
|
|
|
@ -1421,7 +1421,7 @@ namespace libtorrent
|
|||
{
|
||||
error_code err;
|
||||
std::string subdir = combine_path(old_save_path, *it);
|
||||
while (subdir != old_save_path && !err)
|
||||
while (!compare_path(subdir, old_save_path) && !err)
|
||||
{
|
||||
remove(subdir, err);
|
||||
subdir = parent_path(subdir);
|
||||
|
|
|
@ -201,6 +201,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"), "");
|
||||
|
|
Loading…
Reference in New Issue