[Lldb-commits] [lldb] r332618 - FileSpec objects that resolve to "." should have "." in m_filename and m_directory empty.
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Thu May 17 09:12:38 PDT 2018
Author: gclayton
Date: Thu May 17 09:12:38 2018
New Revision: 332618
URL: http://llvm.org/viewvc/llvm-project?rev=332618&view=rev
Log:
FileSpec objects that resolve to "." should have "." in m_filename and m_directory empty.
After switching to LLVM normalization, if we init FileSpec with "." we would end up with m_directory being NULL and m_filename being "".
This patch fixes this by allowing the path to be normalized and if it normalized to nothing, set it to m_filename.
Differential Revision: https://reviews.llvm.org/D46783
Modified:
lldb/trunk/source/Utility/FileSpec.cpp
lldb/trunk/unittests/Utility/FileSpecTest.cpp
Modified: lldb/trunk/source/Utility/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/FileSpec.cpp?rev=332618&r1=332617&r2=332618&view=diff
==============================================================================
--- lldb/trunk/source/Utility/FileSpec.cpp (original)
+++ lldb/trunk/source/Utility/FileSpec.cpp Thu May 17 09:12:38 2018
@@ -258,6 +258,14 @@ void FileSpec::SetFile(llvm::StringRef p
if (m_style == Style::windows)
std::replace(resolved.begin(), resolved.end(), '\\', '/');
+ if (resolved.empty()) {
+ // If we have no path after normalization set the path to the current
+ // directory. This matches what python does and also a few other path
+ // utilities.
+ m_filename.SetString(".");
+ return;
+ }
+
m_filename.SetString(llvm::sys::path::filename(resolved, m_style));
llvm::StringRef dir = llvm::sys::path::parent_path(resolved, m_style);
if (!dir.empty())
Modified: lldb/trunk/unittests/Utility/FileSpecTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/FileSpecTest.cpp?rev=332618&r1=332617&r2=332618&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/FileSpecTest.cpp (original)
+++ lldb/trunk/unittests/Utility/FileSpecTest.cpp Thu May 17 09:12:38 2018
@@ -199,9 +199,10 @@ TEST(FileSpecTest, GetNormalizedPath) {
{"/..", "/"},
{"/.", "/"},
{"..", ".."},
- {".", ""},
+ {".", "."},
+ {"", "."},
{"../..", "../.."},
- {"foo/..", ""},
+ {"foo/..", "."},
{"foo/../bar", "bar"},
{"../foo/..", ".."},
{"./foo", "foo"},
@@ -230,17 +231,18 @@ TEST(FileSpecTest, GetNormalizedPath) {
{R"(\..)", R"(\..)"},
// {R"(c:..)", R"(c:..)"},
{R"(..)", R"(..)"},
- {R"(.)", R"()"},
+ {R"(.)", R"(.)"},
// TODO: fix llvm::sys::path::remove_dots() to return "c:\" below.
{R"(c:..\..)", R"(c:\..\..)"},
{R"(..\..)", R"(..\..)"},
- {R"(foo\..)", R"()"},
+ {R"(foo\..)", R"(.)"},
{R"(foo\..\bar)", R"(bar)"},
{R"(..\foo\..)", R"(..)"},
{R"(.\foo)", R"(foo)"},
{R"(.\.\foo)", R"(foo)"},
{R"(..\foo)", R"(..\foo)"},
{R"(..\..\foo)", R"(..\..\foo)"},
+ {"", "."},
};
for (auto test : windows_tests) {
EXPECT_EQ(test.second,
More information about the lldb-commits
mailing list