fixed windows network path recognition issue

This commit is contained in:
Arvid Norberg 2011-11-27 10:23:50 +00:00
parent 614b279acb
commit 413c04abcf
2 changed files with 27 additions and 8 deletions

View File

@ -379,12 +379,29 @@ namespace libtorrent
if (f.empty()) return false; if (f.empty()) return false;
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS
// match \\ form
if (f == "\\\\") return true; if (f == "\\\\") return true;
int i = 0; int i = 0;
// match the xx:\ or xx:/ form // match the xx:\ or xx:/ form
while (f[i] && is_alpha(f[i])) ++i; while (f[i] && is_alpha(f[i])) ++i;
if (i == int(f.size()-2) && f[i] == ':' && (f[i+1] == '\\' || f[i+1] == '/')) if (i == int(f.size()-2) && f[i] == ':' && (f[i+1] == '\\' || f[i+1] == '/'))
return true; 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 #else
// as well as parent_path("/") should be "/". // as well as parent_path("/") should be "/".
if (f == "/") return true; if (f == "/") return true;
@ -395,13 +412,7 @@ namespace libtorrent
bool has_parent_path(std::string const& f) bool has_parent_path(std::string const& f)
{ {
if (f.empty()) return false; if (f.empty()) return false;
if (is_root_path(f)) return false;
#ifdef TORRENT_WINDOWS
if (f == "\\\\") return false;
#else
// as well as parent_path("/") should be "/".
if (f == "/") return false;
#endif
int len = f.size() - 1; int len = f.size() - 1;
// if the last character is / or \ ignore it // if the last character is / or \ ignore it

View File

@ -819,7 +819,11 @@ int test_main()
TEST_EQUAL(is_root_path("c:\\blah"), false); TEST_EQUAL(is_root_path("c:\\blah"), false);
TEST_EQUAL(is_root_path("c:\\"), true); TEST_EQUAL(is_root_path("c:\\"), true);
TEST_EQUAL(is_root_path("\\\\"), 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 #else
TEST_EQUAL(is_root_path("/blah"), false); TEST_EQUAL(is_root_path("/blah"), false);
TEST_EQUAL(is_root_path("/"), true); TEST_EQUAL(is_root_path("/"), true);
@ -846,6 +850,10 @@ int test_main()
TEST_EQUAL(has_parent_path("c:\\"), false); TEST_EQUAL(has_parent_path("c:\\"), false);
TEST_EQUAL(parent_path("c:\\a"), "c:\\"); TEST_EQUAL(parent_path("c:\\a"), "c:\\");
TEST_EQUAL(has_parent_path("c:\\a"), true); 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 #endif
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS