io/FileOutputStream: add method Sync()

This commit is contained in:
Max Kellermann
2022-05-12 16:49:15 +02:00
parent 47d103e8a1
commit 270a74e53b
2 changed files with 27 additions and 0 deletions

View File

@@ -138,6 +138,15 @@ FileOutputStream::Write(const void *data, size_t size)
GetPath().c_str());
}
void
FileOutputStream::Sync()
{
assert(IsDefined());
if (!FlushFileBuffers(handle))
throw FormatLastError("Failed to sync %s", GetPath().c_str());
}
void
FileOutputStream::Commit()
{
@@ -240,6 +249,15 @@ FileOutputStream::Write(const void *data, size_t size)
GetPath().c_str());
}
void
FileOutputStream::Sync()
{
assert(IsDefined());
if (fdatasync(fd.Get()) < 0)
throw FormatErrno("Failed to sync %s", GetPath().c_str());
}
void
FileOutputStream::Commit()
{