mib updated this revision to Diff 259606.
mib marked an inline comment as done.
mib added a comment.
Address Shafik's comment.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D78712/new/
https://reviews.llvm.org/D78712
Files:
lldb/include/lldb/Host/FileSystem.h
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Host/common/FileSystem.cpp
lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
lldb/test/API/commands/target/basic/TestTargetCommand.py
Index: lldb/test/API/commands/target/basic/TestTargetCommand.py
===================================================================
--- lldb/test/API/commands/target/basic/TestTargetCommand.py
+++ lldb/test/API/commands/target/basic/TestTargetCommand.py
@@ -337,6 +337,12 @@
self.expect("target create -c '" + tf.name + "'", error=True,
substrs=["core file '", "' is not readable"])
+ @skipIfWindows
+ @no_debug_info_test
+ def test_target_create_unowned_core_file(self):
+ self.expect("target create -c ~root", error=True,
+ substrs=["core file '", "' is not readable"])
+
@no_debug_info_test
def test_target_create_nonexistent_sym_file(self):
self.expect("target create -s doesntexist doesntexisteither", error=True,
Index: lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
===================================================================
--- lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -91,20 +91,17 @@
// Resolve any executable within a bundle on MacOSX
Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
- if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
+ if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
+ error.SetErrorStringWithFormat(
+ "unable to find executable for '%s'",
+ resolved_module_spec.GetFileSpec().GetPath().c_str());
+ else if (!FileSystem::Instance().ReadableByCurrentUser(
+ resolved_module_spec.GetFileSpec())) {
+ error.SetErrorStringWithFormat(
+ "executable '%s' is not readable by the current user",
+ resolved_module_spec.GetFileSpec().GetPath().c_str());
+ } else
error.Clear();
- else {
- const uint32_t permissions = FileSystem::Instance().GetPermissions(
- resolved_module_spec.GetFileSpec());
- if (permissions && (permissions & eFilePermissionsEveryoneR) == 0)
- error.SetErrorStringWithFormat(
- "executable '%s' is not readable",
- resolved_module_spec.GetFileSpec().GetPath().c_str());
- else
- error.SetErrorStringWithFormat(
- "unable to find executable for '%s'",
- resolved_module_spec.GetFileSpec().GetPath().c_str());
- }
} else {
if (m_remote_platform_sp) {
error =
@@ -188,7 +185,7 @@
}
if (error.Fail() || !exe_module_sp) {
- if (FileSystem::Instance().Readable(
+ if (FileSystem::Instance().ReadableByCurrentUser(
resolved_module_spec.GetFileSpec())) {
error.SetErrorStringWithFormat(
"'%s' doesn't contain any '%s' platform architectures: %s",
@@ -196,7 +193,7 @@
GetPluginName().GetCString(), arch_names.GetData());
} else {
error.SetErrorStringWithFormat(
- "'%s' is not readable",
+ "'%s' is not readable by the current user",
resolved_module_spec.GetFileSpec().GetPath().c_str());
}
}
Index: lldb/source/Host/common/FileSystem.cpp
===================================================================
--- lldb/source/Host/common/FileSystem.cpp
+++ lldb/source/Host/common/FileSystem.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/File.h"
+#include "lldb/Host/HostInfo.h"
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/TildeExpressionResolver.h"
@@ -491,3 +493,13 @@
m_collector->addFile(file);
}
}
+
+bool FileSystem::ReadableByCurrentUser(const FileSpec &file_spec) const {
+ return Readable(file_spec) &&
+ Instance().Open(file_spec, File::eOpenOptionRead);
+}
+
+bool FileSystem::ReadableByCurrentUser(const llvm::Twine &file_path) const {
+ FileSpec file_spec(file_path.getSingleStringRef());
+ return ReadableByCurrentUser(file_spec);
+}
Index: lldb/source/Commands/CommandObjectTarget.cpp
===================================================================
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -277,9 +277,10 @@
result.SetStatus(eReturnStatusFailed);
return false;
}
- if (!FileSystem::Instance().Readable(core_file)) {
- result.AppendErrorWithFormat("core file '%s' is not readable",
- core_file.GetPath().c_str());
+ if (!FileSystem::Instance().ReadableByCurrentUser(core_file)) {
+ result.AppendErrorWithFormat(
+ "core file '%s' is not readable by the current user.",
+ core_file.GetPath().c_str());
result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -289,9 +290,10 @@
FileSpec symfile(m_symbol_file.GetOptionValue().GetCurrentValue());
if (symfile) {
if (FileSystem::Instance().Exists(symfile)) {
- if (!FileSystem::Instance().Readable(symfile)) {
- result.AppendErrorWithFormat("symbol file '%s' is not readable",
- symfile.GetPath().c_str());
+ if (!FileSystem::Instance().ReadableByCurrentUser(symfile)) {
+ result.AppendErrorWithFormat(
+ "symbol file '%s' is not readable by the current user.",
+ symfile.GetPath().c_str());
result.SetStatus(eReturnStatusFailed);
return false;
}
Index: lldb/include/lldb/Host/FileSystem.h
===================================================================
--- lldb/include/lldb/Host/FileSystem.h
+++ lldb/include/lldb/Host/FileSystem.h
@@ -189,6 +189,9 @@
void Collect(const FileSpec &file_spec);
void Collect(const llvm::Twine &file);
+ bool ReadableByCurrentUser(const FileSpec &file_spec) const;
+ bool ReadableByCurrentUser(const llvm::Twine &file) const;
+
private:
static llvm::Optional<FileSystem> &InstanceImpl();
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> m_fs;
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits