From cab6b97539a625b618dcf3da7eef0bf4b4196a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Thu, 16 Oct 2025 01:33:36 +0800 Subject: [PATCH] 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 --- src/fs.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fs.rs b/src/fs.rs index 4a944b4e2..5a65a2cc5 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -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); } }