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

@@ -48,7 +48,7 @@ std::string GetEscapedHostname(const char *hostname) {
class ModuleLock {
private:
File m_file;
FileUP m_file_up;
std::unique_ptr<lldb_private::LockFile> m_lock;
FileSpec m_file_spec;
@@ -157,16 +157,19 @@ ModuleLock::ModuleLock(const FileSpec &root_dir_spec, const UUID &uuid,
return;
m_file_spec = JoinPath(lock_dir_spec, uuid.GetAsString().c_str());
FileSystem::Instance().Open(m_file, m_file_spec,
File::eOpenOptionWrite |
File::eOpenOptionCanCreate |
File::eOpenOptionCloseOnExec);
if (!m_file) {
error.SetErrorToErrno();
auto file = FileSystem::Instance().Open(
m_file_spec, File::eOpenOptionWrite | File::eOpenOptionCanCreate |
File::eOpenOptionCloseOnExec);
if (file)
m_file_up = std::move(file.get());
else {
m_file_up.reset();
error = Status(file.takeError());
return;
}
m_lock.reset(new lldb_private::LockFile(m_file.GetDescriptor()));
m_lock.reset(new lldb_private::LockFile(m_file_up->GetDescriptor()));
error = m_lock->WriteLock(0, 1);
if (error.Fail())
error.SetErrorStringWithFormat("Failed to lock file: %s",
@@ -174,10 +177,11 @@ ModuleLock::ModuleLock(const FileSpec &root_dir_spec, const UUID &uuid,
}
void ModuleLock::Delete() {
if (!m_file)
if (!m_file_up)
return;
m_file.Close();
m_file_up->Close();
m_file_up.reset();
llvm::sys::fs::remove(m_file_spec.GetPath());
}