fs: open file with O_RDWR before fsync

On Cygwin, fsync() on the history and uvar file fails with "permission
denied". Work around this by opening the file in read-write mode
instead of read-only mode.

Closes #11948
This commit is contained in:
王宇逸
2025-10-16 01:33:36 +08:00
committed by Johannes Altmanninger
parent 1c853a4d24
commit cab6b97539

View File

@@ -115,7 +115,7 @@ pub fn file_flags(&self) -> OFlag {
Self::Exclusive(WriteMethod::Append) => {
OFlag::O_WRONLY | OFlag::O_APPEND | OFlag::O_CREAT
}
Self::Exclusive(WriteMethod::RenameIntoPlace) => OFlag::O_RDONLY | OFlag::O_CREAT,
Self::Exclusive(WriteMethod::RenameIntoPlace) => OFlag::O_RDWR | OFlag::O_CREAT,
}
}
}
@@ -192,6 +192,7 @@ pub fn fsync(file: &File) -> std::io::Result<()> {
-1 => {
let os_error = std::io::Error::last_os_error();
if os_error.kind() != std::io::ErrorKind::Interrupted {
FLOGF!(synced_file_access, "fsync failed: %s", os_error);
return Err(os_error);
}
}