fs/io/FileOutputStream: use C++ exceptions in Commit()

This commit is contained in:
Max Kellermann
2015-12-16 00:24:41 +01:00
parent 24b2198668
commit 7eae3bc8c5
8 changed files with 61 additions and 44 deletions

View File

@@ -72,13 +72,12 @@ BaseFileOutputStream::Write(const void *data, size_t size, Error &error)
return true;
}
bool
FileOutputStream::Commit(gcc_unused Error &error)
void
FileOutputStream::Commit()
{
assert(IsDefined());
Close();
return true;
}
void
@@ -162,8 +161,8 @@ BaseFileOutputStream::Write(const void *data, size_t size, Error &error)
return true;
}
bool
FileOutputStream::Commit(Error &error)
void
FileOutputStream::Commit()
{
assert(IsDefined());
@@ -176,20 +175,20 @@ FileOutputStream::Commit(Error &error)
snprintf(fd_path, sizeof(fd_path), "/proc/self/fd/%d",
GetFD().Get());
if (linkat(AT_FDCWD, fd_path, AT_FDCWD, GetPath().c_str(),
AT_SYMLINK_FOLLOW) < 0) {
error.FormatErrno("Failed to commit %s",
AT_SYMLINK_FOLLOW) < 0)
throw FormatErrno("Failed to commit %s",
GetPath().c_str());
Close();
return false;
}
}
#endif
bool success = Close();
if (!success)
error.FormatErrno("Failed to commit %s", GetPath().c_str());
return success;
if (!Close()) {
#ifdef WIN32
throw FormatLastError("Failed to commit %s",
GetPath().ToUTF8().c_str());
#else
throw FormatErrno("Failed to commit %s", GetPath().c_str());
#endif
}
}
void
@@ -233,18 +232,17 @@ AppendFileOutputStream::AppendFileOutputStream(Path _path)
#endif
}
bool
AppendFileOutputStream::Commit(gcc_unused Error &error)
void
AppendFileOutputStream::Commit()
{
assert(IsDefined());
if (!Close()) {
#ifdef WIN32
return Close();
throw FormatLastError("Failed to commit %s",
GetPath().ToUTF8().c_str());
#else
bool success = Close();
if (!success)
error.FormatErrno("Failed to commit %s", GetPath().c_str());
return success;
throw FormatErrno("Failed to commit %s", GetPath().c_str());
#endif
}
}

View File

@@ -139,7 +139,7 @@ public:
Cancel();
}
bool Commit(Error &error);
void Commit();
void Cancel();
};
@@ -152,7 +152,7 @@ public:
Close();
}
bool Commit(Error &error);
void Commit();
};
#endif