diff options
author | pommicket <pommicket@gmail.com> | 2024-07-12 16:26:25 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2024-07-12 16:26:25 -0400 |
commit | dd6dcaec09426e786f5265fcb08dea283cb63fc0 (patch) | |
tree | a128399bebb00c80d33bcdac1a472450c0643ad8 /buffer.c | |
parent | 71f1f03835566abd979fb1cb572a5195611ac9f7 (diff) |
Add sync option to control how much stuff to sync to disk
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -3264,12 +3264,19 @@ static bool buffer_write_to_file(TextBuffer *buffer, const char *path) { success = false; } fflush(out); - // make sure data is on disk before returning from this function - #if __unix__ - fdatasync(fileno(out)); - #elif _WIN32 - _commit(_fileno(out)); - #endif + const char *sync = rc_str(settings->sync, "none"); + if (!streq(sync, "none")) { + // make sure data is on disk before returning from this function + #if __unix__ + if (streq(sync, "data")) { + fdatasync(fileno(out)); + } else { + fsync(fileno(out)); + } + #elif _WIN32 + _commit(_fileno(out)); + #endif + } if (fclose(out) != 0) { if (!buffer_has_error(buffer)) buffer_error(buffer, "Couldn't close file %s.", path); |