summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buffer.c19
-rw-r--r--config.c1
-rw-r--r--ted-internal.h5
-rw-r--r--ted.cfg6
4 files changed, 25 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);
diff --git a/config.c b/config.c
index 7bdcc7c..12153d2 100644
--- a/config.c
+++ b/config.c
@@ -166,6 +166,7 @@ static const SettingString settings_string[] = {
{"comment-end", &settings_zero.comment_end, true},
{"font", &settings_zero.font, false},
{"font-bold", &settings_zero.font_bold, false},
+ {"sync", &settings_zero.sync, false},
};
static const SettingKeyCombo settings_key_combo[] = {
{"hover-key", &settings_zero.hover_key, true},
diff --git a/ted-internal.h b/ted-internal.h
index f5e3211..dd109ea 100644
--- a/ted-internal.h
+++ b/ted-internal.h
@@ -151,6 +151,11 @@ struct Settings {
RcStr *font;
/// Comma separated list of paths to bold font files.
RcStr *font_bold;
+ /// How to sync data when writing a file
+ /// - none - don't sync to disk
+ /// - full - sync data and metadata to disk
+ /// - data - only sync data but not metadata (on Windows this is the same as full)
+ RcStr *sync;
LanguageExtension *language_extensions;
/// dynamic array, sorted by KEY_COMBO(modifier, key)
KeyAction *key_actions;
diff --git a/ted.cfg b/ted.cfg
index ea59963..5a20477 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -133,6 +133,12 @@ root-identifiers = .ted-root, .ted-root.out, Cargo.toml, make.bat, CMakeLists.tx
# writing to the file (prevents loss of data if power goes out mid-write or something).
# the backups are deleted immediately after writing.
save-backup = yes
+# how much data to sync to disk on :save
+# this can be one of:
+# - none: don't sync to disk (you may lose data if power goes out)
+# - full: sync data and metadata to disk (fsync)
+# - data: sync data to disk but not metadata (fsyncdata) (on Windows this is the same as full)
+sync = data
# whether to save files with \r\n line endings.
crlf = no
# same as crlf setting, but ignored on non-Windows operating system.