diff options
| author | Pavel Labath <labath@google.com> | 2016-03-11 08:44:44 +0000 |
|---|---|---|
| committer | Pavel Labath <labath@google.com> | 2016-03-11 08:44:44 +0000 |
| commit | cc0e87cdae3ec45da620189b35f2e9b497549f32 (patch) | |
| tree | 88d2a9ff16eda78d55d30f173f8c2515ce15e48a /lldb/source | |
| parent | bafc9dc59104ec05876e46a49543c89d26f7e181 (diff) | |
| download | bcm5719-llvm-cc0e87cdae3ec45da620189b35f2e9b497549f32.tar.gz bcm5719-llvm-cc0e87cdae3ec45da620189b35f2e9b497549f32.zip | |
Fix a couple of cornercases in FileSpec + tests
Summary:
This fixes a couple of corner cases in FileSpec, related to AppendPathComponent and
handling of root directory (/) file spec. I add a bunch of unit tests for the new behavior.
Summary of changes:
FileSpec("/bar").GetCString(): before "//bar", after "/bar".
FileSpec("/").CopyByAppendingPathComponent("bar").GetCString(): before "//bar", after "/bar".
FileSpec("C:", ePathSyntaxWindows).CopyByAppendingPathComponent("bar").GetCString(): before "C:/bar", after "C:\bar".
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D18044
llvm-svn: 263207
Diffstat (limited to 'lldb/source')
| -rw-r--r-- | lldb/source/Host/common/FileSpec.cpp | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp index b8d35480d0f..d17b907f712 100644 --- a/lldb/source/Host/common/FileSpec.cpp +++ b/lldb/source/Host/common/FileSpec.cpp @@ -918,7 +918,7 @@ void FileSpec::GetPath(llvm::SmallVectorImpl<char> &path, bool denormalize) const { path.append(m_directory.GetStringRef().begin(), m_directory.GetStringRef().end()); - if (m_directory) + if (m_directory && !(m_directory.GetLength() == 1 && m_directory.GetCString()[0] == '/')) path.insert(path.end(), '/'); path.append(m_filename.GetStringRef().begin(), m_filename.GetStringRef().end()); Normalize(path, m_syntax); @@ -1331,17 +1331,9 @@ FileSpec::EnumerateDirectory FileSpec FileSpec::CopyByAppendingPathComponent (const char *new_path) const { - const bool resolve = false; - if (m_filename.IsEmpty() && m_directory.IsEmpty()) - return FileSpec(new_path,resolve); - StreamString stream; - if (m_filename.IsEmpty()) - stream.Printf("%s/%s",m_directory.GetCString(),new_path); - else if (m_directory.IsEmpty()) - stream.Printf("%s/%s",m_filename.GetCString(),new_path); - else - stream.Printf("%s/%s/%s",m_directory.GetCString(), m_filename.GetCString(),new_path); - return FileSpec(stream.GetData(),resolve); + FileSpec ret = *this; + ret.AppendPathComponent(new_path); + return ret; } FileSpec @@ -1442,20 +1434,26 @@ void FileSpec::AppendPathComponent(const char *new_path) { if (!new_path) return; - const bool resolve = false; - if (m_filename.IsEmpty() && m_directory.IsEmpty()) + + StreamString stream; + if (!m_directory.IsEmpty()) { - SetFile(new_path, resolve); - return; + stream.PutCString(m_directory.GetCString()); + if (m_directory.GetLength() != 1 || m_directory.GetCString()[0] != '/') + stream.PutChar('/'); } - StreamString stream; - if (m_filename.IsEmpty() || (m_filename.GetLength() == 1 && m_filename.GetCString()[0] == '.')) - stream.Printf("%s/%s", m_directory.GetCString(), new_path); - else if (m_directory.IsEmpty()) - stream.Printf("%s/%s", m_filename.GetCString(), new_path); - else - stream.Printf("%s/%s/%s", m_directory.GetCString(), m_filename.GetCString(), new_path); - SetFile(stream.GetData(), resolve); + + if (!m_filename.IsEmpty()) + { + stream.PutCString(m_filename.GetCString()); + if (m_filename.GetLength() != 1 || m_filename.GetCString()[0] != '/') + stream.PutChar('/'); + } + + stream.PutCString(new_path); + + const bool resolve = false; + SetFile(stream.GetData(), resolve, m_syntax); } void |

