aboutsummaryrefslogtreecommitdiffstats
path: root/source/Host/common/FileSystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Host/common/FileSystem.cpp')
-rw-r--r--source/Host/common/FileSystem.cpp33
1 files changed, 15 insertions, 18 deletions
diff --git a/source/Host/common/FileSystem.cpp b/source/Host/common/FileSystem.cpp
index d5ac05bd447c..2db5bff3207f 100644
--- a/source/Host/common/FileSystem.cpp
+++ b/source/Host/common/FileSystem.cpp
@@ -49,7 +49,7 @@ void FileSystem::Initialize() {
InstanceImpl().emplace();
}
-void FileSystem::Initialize(FileCollector &collector) {
+void FileSystem::Initialize(std::shared_ptr<FileCollector> collector) {
lldbassert(!InstanceImpl() && "Already initialized.");
InstanceImpl().emplace(collector);
}
@@ -280,7 +280,7 @@ std::shared_ptr<DataBufferLLVM>
FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size,
uint64_t offset) {
if (m_collector)
- m_collector->AddFile(path);
+ m_collector->addFile(path);
const bool is_volatile = !IsLocal(path);
const ErrorOr<std::string> external_path = GetExternalPath(path);
@@ -415,13 +415,11 @@ static mode_t GetOpenMode(uint32_t permissions) {
return mode;
}
-Status FileSystem::Open(File &File, const FileSpec &file_spec, uint32_t options,
- uint32_t permissions, bool should_close_fd) {
+Expected<FileUP> FileSystem::Open(const FileSpec &file_spec,
+ File::OpenOptions options,
+ uint32_t permissions, bool should_close_fd) {
if (m_collector)
- m_collector->AddFile(file_spec);
-
- if (File.IsValid())
- File.Close();
+ m_collector->addFile(file_spec.GetPath());
const int open_flags = GetOpenFlags(options);
const mode_t open_mode =
@@ -429,20 +427,19 @@ Status FileSystem::Open(File &File, const FileSpec &file_spec, uint32_t options,
auto path = GetExternalPath(file_spec);
if (!path)
- return Status(path.getError());
+ return errorCodeToError(path.getError());
int descriptor = llvm::sys::RetryAfterSignal(
-1, OpenWithFS, *this, path->c_str(), open_flags, open_mode);
- Status error;
- if (!File::DescriptorIsValid(descriptor)) {
- File.SetDescriptor(descriptor, false);
- error.SetErrorToErrno();
- } else {
- File.SetDescriptor(descriptor, should_close_fd);
- File.SetOptions(options);
- }
- return error;
+ if (!File::DescriptorIsValid(descriptor))
+ return llvm::errorCodeToError(
+ std::error_code(errno, std::system_category()));
+
+ auto file = std::unique_ptr<File>(
+ new NativeFile(descriptor, options, should_close_fd));
+ assert(file->IsValid());
+ return std::move(file);
}
ErrorOr<std::string> FileSystem::GetExternalPath(const llvm::Twine &path) {