Skip to content
Permalink
Browse files

path, bugfix: result error in path.resolve root test case on windows.

  • Loading branch information...
xicilion committed Jun 25, 2019
1 parent 15b9de4 commit 453b78c6d6cb34be959b361b1b0663f23c670612
Showing with 12 additions and 12 deletions.
  1. +12 −12 fibjs/include/path.h
@@ -287,7 +287,7 @@ inline void _path_array(exlib::string path, std::vector<exlib::string>& a)
a.push_back(exlib::string(p + p1, i - p1));
}

inline result_t _normalize(exlib::string path, exlib::string& retVal, bool removeSlash = false)
inline result_t _normalize(exlib::string path, exlib::string& retVal, bool removeSlash = false, bool root = false)
{
int32_t i;

@@ -297,12 +297,16 @@ inline result_t _normalize(exlib::string path, exlib::string& retVal, bool remov
_normalize_array(a, removeSlash);

retVal.clear();

for (i = 0; i < (int32_t)a.size(); i++) {
if (i > 0)
retVal.append(1, PATH_SLASH_POSIX);
retVal.append(a[i]);
}

if (root && a.size() == 1 && a[0].empty())
retVal.append(1, PATH_SLASH_POSIX);

return 0;
}

@@ -342,7 +346,7 @@ inline void _path_array_win32(exlib::string path, std::vector<exlib::string>& a,
}
}

inline result_t _normalize_win32(exlib::string path, exlib::string& retVal, bool removeSlash = false)
inline result_t _normalize_win32(exlib::string path, exlib::string& retVal, bool removeSlash = false, bool root = false)
{
int32_t i;

@@ -373,6 +377,9 @@ inline result_t _normalize_win32(exlib::string path, exlib::string& retVal, bool
retVal.append(a[i]);
}

if (root && a.size() == 1 && a[0].empty())
retVal.append(1, PATH_SLASH_WIN32);

return 0;
}

@@ -565,14 +572,7 @@ inline result_t _resolve(OptArgs ps, exlib::string& retVal)
p.resolvePosix(s);
}

result_t hr = _normalize(p.str(), retVal, true);
if (hr < 0)
return hr;

if (retVal.empty())
retVal = "/";

return 0;
return _normalize(p.str(), retVal, true, true);
}

inline result_t _resolve(exlib::string& path)
@@ -584,7 +584,7 @@ inline result_t _resolve(exlib::string& path)
p.resolvePosix(str);
p.resolvePosix(path);

return _normalize(p.str(), path, true);
return _normalize(p.str(), path, true, true);
}

inline result_t _resolve_win32(OptArgs ps, exlib::string& retVal)
@@ -604,7 +604,7 @@ inline result_t _resolve_win32(OptArgs ps, exlib::string& retVal)
p.resolveWin32(s);
}

return _normalize_win32(p.str(), retVal, true);
return _normalize_win32(p.str(), retVal, true, true);
}

inline result_t _resolve_win32(exlib::string& path)

0 comments on commit 453b78c

Please sign in to comment.
You can’t perform that action at this time.