diff --git a/src/platform_posix.cc b/src/platform_posix.cc index c172446b..71dbb591 100644 --- a/src/platform_posix.cc +++ b/src/platform_posix.cc @@ -39,9 +39,6 @@ limitations under the License. #include #endif -#include -#include - #include #include #include @@ -52,10 +49,14 @@ namespace pipeline { void ThreadEnter(); } +// Normalize the path, including eliminating redundant . and duplicated / +// characters. std::string NormalizePath(const std::string &path) { - llvm::SmallString<256> P(path); - llvm::sys::path::remove_dots(P, true); - return {P.data(), P.size()}; + char canonical[PATH_MAX + 1]; + if (realpath(path.c_str(), canonical)) { + return canonical; + } + return path; } void FreeUnusedMemory() { diff --git a/src/utils.cc b/src/utils.cc index 642f4e24..67347002 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -125,6 +125,7 @@ void EnsureEndsInSlash(std::string &path) { std::string EscapeFileName(std::string path) { bool slash = path.size() && path.back() == '/'; + path = NormalizePath(path); #ifdef _WIN32 std::replace(path.begin(), path.end(), ':', '@'); #endif