Call fsync after appending to history file

This is an attempt to eliminate history file corruption as described in
https://github.com/fish-shell/fish-shell/issues/10300.
In particular, issues raised in
https://github.com/fish-shell/fish-shell/issues/10300#issuecomment-2567063654
can benefit from such synchronization.
This commit is contained in:
Daniel Rainer
2025-08-08 20:20:23 +02:00
committed by Johannes Altmanninger
parent b0ae11e769
commit 5de43a4e86

View File

@@ -48,6 +48,7 @@
expand::{expand_one, ExpandFlags},
fds::wopen_cloexec,
flog::{FLOG, FLOGF},
fs::fsync,
history::file::{append_history_item_to_buffer, HistoryFileContents},
io::IoStreams,
operation_context::{OperationContext, EXPANSION_LIMIT_BACKGROUND},
@@ -696,6 +697,7 @@ fn save_internal_via_appending(&mut self, history_path: &wstr) -> std::io::Resul
}
flush_to_file(&mut buffer, locked_history_file.get_mut(), 0)?;
fsync(locked_history_file.get())?;
self.first_unwritten_new_item_index = new_first_index;
// Since we just modified the file, update our history_file_id to match its current state