Index: include/lldb/Host/FileSpec.h =================================================================== --- include/lldb/Host/FileSpec.h +++ include/lldb/Host/FileSpec.h @@ -259,13 +259,9 @@ /// /// @param[in] s /// The stream to which to dump the object description. - /// - /// @param[in] trailing_slash - /// If true and the file is a non root directory, then a trailing slash - /// will be added. //------------------------------------------------------------------ void - Dump(Stream *s, bool trailing_slash = true) const; + Dump(Stream *s) const; //------------------------------------------------------------------ /// Existence test. @@ -635,9 +631,12 @@ lldb::DataBufferSP ReadFileContentsAsCString(Error *error_ptr = NULL); + static bool PathSyntaxIsPosix(PathSyntax syntax); + static void Normalize(llvm::SmallVectorImpl &path, PathSyntax syntax = ePathSyntaxHostNative); static void DeNormalize(llvm::SmallVectorImpl &path, PathSyntax syntax = ePathSyntaxHostNative); + char GetPathSeparator() const; //------------------------------------------------------------------ /// Run through the input string, replaying the effect of any ".." and produce Index: source/Host/common/FileSpec.cpp =================================================================== --- source/Host/common/FileSpec.cpp +++ source/Host/common/FileSpec.cpp @@ -252,11 +252,17 @@ return *this; } +bool +FileSpec::PathSyntaxIsPosix(PathSyntax syntax) +{ + return (syntax == ePathSyntaxPosix || + (syntax == ePathSyntaxHostNative && + FileSystem::GetNativePathSyntax() == ePathSyntaxPosix)); +} + void FileSpec::Normalize(llvm::SmallVectorImpl &path, PathSyntax syntax) { - if (syntax == ePathSyntaxPosix || - (syntax == ePathSyntaxHostNative && FileSystem::GetNativePathSyntax() == ePathSyntaxPosix)) - return; + if (PathSyntaxIsPosix(syntax)) return; std::replace(path.begin(), path.end(), '\\', '/'); // Windows path can have \\ slashes which can be changed by replace @@ -269,13 +275,17 @@ void FileSpec::DeNormalize(llvm::SmallVectorImpl &path, PathSyntax syntax) { - if (syntax == ePathSyntaxPosix || - (syntax == ePathSyntaxHostNative && FileSystem::GetNativePathSyntax() == ePathSyntaxPosix)) - return; + if (PathSyntaxIsPosix(syntax)) return; std::replace(path.begin(), path.end(), '/', '\\'); } +char +FileSpec::GetPathSeparator() const +{ + return PathSyntaxIsPosix(m_syntax) ? '/' : '\\'; +} + //------------------------------------------------------------------ // Update the contents of this object with a new path. The path will // be split up into a directory and filename and stored as uniqued @@ -609,15 +619,14 @@ // directory delimiter, and the filename. //------------------------------------------------------------------ void -FileSpec::Dump(Stream *s, bool trailing_slash) const +FileSpec::Dump(Stream *s) const { if (s) { - m_directory.Dump(s); - if ((m_filename || trailing_slash) && m_directory && - !m_directory.GetStringRef().endswith("/")) - s->PutChar('/'); - m_filename.Dump(s); + std::string path{GetPath(true)}; + s->PutCString(path.c_str()); + if (!m_filename && !path.empty() && path.back() != GetPathSeparator()) + s->PutChar(GetPathSeparator()); } } @@ -816,10 +825,11 @@ void FileSpec::GetPath(llvm::SmallVectorImpl &path, bool denormalize) const { - StreamString stream; - Dump(&stream, false); - path.append(stream.GetString().begin(), stream.GetString().end()); + path.append(m_directory.GetStringRef().begin(), m_directory.GetStringRef().end()); + if (m_directory) path.insert(path.end(), '/'); + path.append(m_filename.GetStringRef().begin(), m_filename.GetStringRef().end()); Normalize(path, m_syntax); + if (path.size() > 1 && path.back() == '/') path.pop_back(); if (denormalize && !path.empty()) DeNormalize(path, m_syntax); } @@ -1383,15 +1393,7 @@ if (directory.size() > 0) { - if (m_syntax == ePathSyntaxWindows) - { - if (directory.size() >= 2 && directory[1] == ':') - return false; - if (directory[0] == '/') - return false; - return true; - } - else + if (PathSyntaxIsPosix(m_syntax)) { // If the path doesn't start with '/' or '~', return true switch (directory[0]) @@ -1403,6 +1405,14 @@ return true; } } + else + { + if (directory.size() >= 2 && directory[1] == ':') + return false; + if (directory[0] == '/') + return false; + return true; + } } else if (m_filename) {