Skip to content

Commit

Permalink
Add force fsync option to FileSink
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed Sep 29, 2024
1 parent 59fec49 commit a058985
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions include/quill/sinks/FileSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,18 @@ class FileSink : public StreamSink
/**
* Fsync the file descriptor.
*/
void fsync_file() noexcept
void fsync_file(bool force_fsync = false) noexcept
{
auto const now = std::chrono::steady_clock::now();

if ((now - _last_fsync_timestamp) < _config.minimum_fsync_interval())
if (!force_fsync)
{
return;
auto const now = std::chrono::steady_clock::now();
if ((now - _last_fsync_timestamp) < _config.minimum_fsync_interval())
{
return;
}
_last_fsync_timestamp = now;
}

_last_fsync_timestamp = now;

#ifdef _WIN32
FlushFileBuffers(reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(_file))));
#else
Expand Down
2 changes: 1 addition & 1 deletion include/quill/sinks/RotatingFileSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class RotatingFileSink : public FileSink

// We need to flush and also fsync before actually getting the size of the file
FileSink::flush_sink();
FileSink::fsync_file(_file);
FileSink::fsync_file(true);

if (_get_file_size(_filename) <= 0)
{
Expand Down

0 comments on commit a058985

Please sign in to comment.