diff --git a/src/file.cpp b/src/file.cpp index da4660032..f6e3e68bd 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -379,12 +379,29 @@ namespace libtorrent if (f.empty()) return false; #ifdef TORRENT_WINDOWS + // match \\ form if (f == "\\\\") return true; int i = 0; // match the xx:\ or xx:/ form while (f[i] && is_alpha(f[i])) ++i; if (i == int(f.size()-2) && f[i] == ':' && (f[i+1] == '\\' || f[i+1] == '/')) return true; + // match network paths \\computer_name\ form + if (f.size() > 2 && f[0] == '\\' && f[1] == '\\') + { + // we don't care about the last character, since it's OK for it + // to be a slash or a back slash + bool found = false; + for (int i = 2; i < f.size() - 1; ++i) + { + if (f[i] != '\\' && f[i] != '/') continue; + // there is a directory separator in here, + // i.e. this is not the root + found = true; + break; + } + if (!found) return true; + } #else // as well as parent_path("/") should be "/". if (f == "/") return true; @@ -395,13 +412,7 @@ namespace libtorrent bool has_parent_path(std::string const& f) { if (f.empty()) return false; - -#ifdef TORRENT_WINDOWS - if (f == "\\\\") return false; -#else - // as well as parent_path("/") should be "/". - if (f == "/") return false; -#endif + if (is_root_path(f)) return false; int len = f.size() - 1; // if the last character is / or \ ignore it diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index c91ac52a1..92579c986 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -819,7 +819,11 @@ int test_main() TEST_EQUAL(is_root_path("c:\\blah"), false); TEST_EQUAL(is_root_path("c:\\"), true); TEST_EQUAL(is_root_path("\\\\"), true); - TEST_EQUAL(is_root_path("\\\\foobar"), false); + TEST_EQUAL(is_root_path("\\\\foobar"), true); + TEST_EQUAL(is_root_path("\\\\foobar\\"), true); + TEST_EQUAL(is_root_path("\\\\foobar/"), true); + TEST_EQUAL(is_root_path("\\\\foo/bar"), false); + TEST_EQUAL(is_root_path("\\\\foo\\bar\\"), false); #else TEST_EQUAL(is_root_path("/blah"), false); TEST_EQUAL(is_root_path("/"), true); @@ -846,6 +850,10 @@ int test_main() TEST_EQUAL(has_parent_path("c:\\"), false); TEST_EQUAL(parent_path("c:\\a"), "c:\\"); TEST_EQUAL(has_parent_path("c:\\a"), true); + TEST_EQUAL(has_parent_path("\\\\a"), false); + TEST_EQUAL(has_parent_path("\\\\foobar/"), false); + TEST_EQUAL(has_parent_path("\\\\foobar\\"), false); + TEST_EQUAL(has_parent_path("\\\\foo/bar\\"), true); #endif #ifdef TORRENT_WINDOWS