Convert FileSystem::Open() to return Expected<FileUP>

Summary:
This patch converts FileSystem::Open from this prototype:

Status
Open(File &File, const FileSpec &file_spec, ...);

to this one:

llvm::Expected<std::unique_ptr<File>>
Open(const FileSpec &file_spec, ...);

This is beneficial on its own, as llvm::Expected is a more modern
and recommended error type than Status.  It is also a necessary step
towards https://reviews.llvm.org/D67891, and further developments
for lldb_private::File.

Reviewers: JDevlieghere, jasonmolenda, labath

Reviewed By: labath

Subscribers: mgorny, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D67996

llvm-svn: 373003
This commit is contained in:
Lawrence D'Anna
2019-09-26 17:54:59 +00:00
parent 875d20bcde
commit 2fce1137c7
26 changed files with 275 additions and 205 deletions

View File

@@ -45,6 +45,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormatAdapters.h"
#include <memory>
#include <mutex>
@@ -901,17 +902,24 @@ bool ScriptInterpreterPythonImpl::ExecuteOneLine(
debugger.AdoptTopIOHandlerFilesIfInvalid(input_file_sp, output_file_sp,
error_file_sp);
} else {
input_file_sp = std::make_shared<StreamFile>();
FileSystem::Instance().Open(input_file_sp->GetFile(),
auto nullin = FileSystem::Instance().Open(
FileSpec(FileSystem::DEV_NULL),
File::eOpenOptionRead);
output_file_sp = std::make_shared<StreamFile>();
FileSystem::Instance().Open(output_file_sp->GetFile(),
auto nullout = FileSystem::Instance().Open(
FileSpec(FileSystem::DEV_NULL),
File::eOpenOptionWrite);
error_file_sp = output_file_sp;
if (!nullin) {
result->AppendErrorWithFormatv("failed to open /dev/null: {0}\n",
llvm::fmt_consume(nullin.takeError()));
return false;
}
if (!nullout) {
result->AppendErrorWithFormatv("failed to open /dev/null: {0}\n",
llvm::fmt_consume(nullout.takeError()));
return false;
}
input_file_sp = std::make_shared<StreamFile>(std::move(nullin.get()));
error_file_sp = output_file_sp = std::make_shared<StreamFile>(std::move(nullout.get()));
}
FILE *in_file = input_file_sp->GetFile().GetStream();