io/FileOutputStream: add method Sync()
This commit is contained in:
parent
47d103e8a1
commit
270a74e53b
@ -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()
|
||||
{
|
||||
|
@ -148,6 +148,15 @@ public:
|
||||
/* virtual methods from class OutputStream */
|
||||
void Write(const void *data, size_t size) override;
|
||||
|
||||
/**
|
||||
* Flush all data written to this object to disk (but does not
|
||||
* commit to the final path). This method blocks until this
|
||||
* flush is complete. It can be called repeatedly.
|
||||
*
|
||||
* Throws on error.
|
||||
*/
|
||||
void Sync();
|
||||
|
||||
/**
|
||||
* Commit all data written to the file and make the file
|
||||
* visible on the specified path.
|
||||
|
Loading…
Reference in New Issue
Block a user