[Lldb-commits] [PATCH] FileSpec::Resolve should not turn a filename-only FileSpec into a qualified FileSpec if that file doesn't exist
Jason Molenda
jmolenda at apple.com
Tue Feb 24 18:35:49 PST 2015
Updated patch to use path.clear(), path.append(original_path.begin(), original_path.end()); as suggested by Zachary.
Kept the "be sure we have a nul terminated string". nul is '\0'. null is (void*)0. We want a nul terminated cstring here.
Left the testsuite as-is, I agree it would be better to get a randomly generated temp name but this is going to be fine.
REPOSITORY
rL LLVM
http://reviews.llvm.org/D7477
Files:
source/Host/common/FileSpec.cpp
test/functionalities/paths/TestPaths.py
Index: source/Host/common/FileSpec.cpp
===================================================================
--- source/Host/common/FileSpec.cpp
+++ source/Host/common/FileSpec.cpp
@@ -164,7 +164,20 @@
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() :
Index: test/functionalities/paths/TestPaths.py
===================================================================
--- test/functionalities/paths/TestPaths.py
+++ test/functionalities/paths/TestPaths.py
@@ -28,6 +28,12 @@
# 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 '''
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7477.20652.patch
Type: text/x-patch
Size: 1717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150225/431bafcf/attachment.bin>
More information about the lldb-commits
mailing list