[Lldb-commits] [lldb] r230451 - When FileSpec::Resolve is given a bare file like "ls",

Jason Molenda jmolenda at apple.com
Tue Feb 24 18:35:25 PST 2015


Author: jmolenda
Date: Tue Feb 24 20:35:25 2015
New Revision: 230451

URL: http://llvm.org/viewvc/llvm-project?rev=230451&view=rev
Log:
When FileSpec::Resolve is given a bare file like "ls",
and llvm::sys::fs::make_absolute prepends the current
working directory to that path, leave the original
bare file name unchanged if $cwd/ls doesn't exist.

http://reviews.llvm.org/D7477
<rdar://problem/18775190>


Modified:
    lldb/trunk/source/Host/common/FileSpec.cpp
    lldb/trunk/test/functionalities/paths/TestPaths.py

Modified: lldb/trunk/source/Host/common/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=230451&r1=230450&r2=230451&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSpec.cpp (original)
+++ lldb/trunk/source/Host/common/FileSpec.cpp Tue Feb 24 20:35:25 2015
@@ -164,7 +164,20 @@ FileSpec::Resolve (llvm::SmallVectorImpl
         ResolveUsername(path);
 #endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER
 
+    // Save a copy of the original path that's passed in
+    llvm::SmallString<PATH_MAX> original_path(path.begin(), path.end());
+
     llvm::sys::fs::make_absolute(path);
+
+    
+    path.push_back(0);  // Be sure we have a nul terminated string
+    path.pop_back();
+    struct stat file_stats;
+    if (::stat (path.data(), &file_stats) != 0)
+    {
+        path.clear();
+        path.append(original_path.begin(), original_path.end());
+    }
 }
 
 FileSpec::FileSpec() : 

Modified: lldb/trunk/test/functionalities/paths/TestPaths.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/paths/TestPaths.py?rev=230451&r1=230450&r2=230451&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/paths/TestPaths.py (original)
+++ lldb/trunk/test/functionalities/paths/TestPaths.py Tue Feb 24 20:35:25 2015
@@ -28,6 +28,12 @@ class TestPaths(TestBase):
             # No directory path types should have the filename set
             self.assertTrue (f.GetFilename() == None);
 
+    def test_filespec_resolve_doesnt_prepend_cwd_if_file_doesnt_exist (self):
+        file_only = lldb.SBFileSpec("VeryUnlikelToExistInTheCurrentWorkingDirectory", True)
+        # SBFileSpec(path, True) should not prepend the current-working-directory to the
+        # file path if it doesn't exist in the current directory.
+        self.assertTrue (file_only.GetDirectory() == None)
+
     @unittest2.skipUnless(sys.platform.startswith("win32"), "Test for windows only")
     def test_windows_double_slash (self):
         '''Test to check the path with double slash is handled correctly '''





More information about the lldb-commits mailing list