summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2024-07-12 16:26:25 -0400
committerpommicket <pommicket@gmail.com>2024-07-12 16:26:25 -0400
commitdd6dcaec09426e786f5265fcb08dea283cb63fc0 (patch)
treea128399bebb00c80d33bcdac1a472450c0643ad8 /buffer.c
parent71f1f03835566abd979fb1cb572a5195611ac9f7 (diff)
Add sync option to control how much stuff to sync to disk
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/buffer.c b/buffer.c
index ad1ee55..d5532d4 100644
--- a/buffer.c
+++ b/buffer.c
@@ -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);