From c0c925d6ac209897dec7e49f0664991d513f52e8 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 4 Feb 2024 20:33:32 +0100 Subject: [PATCH] Fail on Windows if somebody tries to set permissions there. That way, there will be no surprises as would be the case with doing nothing. --- src/file/imp/windows.rs | 9 ++++++++- src/lib.rs | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/file/imp/windows.rs b/src/file/imp/windows.rs index a8a6f76c4..e7f603843 100644 --- a/src/file/imp/windows.rs +++ b/src/file/imp/windows.rs @@ -19,11 +19,18 @@ fn to_utf16(s: &Path) -> Vec { s.as_os_str().encode_wide().chain(iter::once(0)).collect() } +fn not_supported(msg: &str) -> io::Result { + Err(io::Error::new(io::ErrorKind::Other, msg)) +} + pub fn create_named( path: &Path, open_options: &mut OpenOptions, - _permissions: Option<&std::fs::Permissions>, + permissions: Option<&std::fs::Permissions>, ) -> io::Result { + if permissions.map_or(false, |p| p.readonly()) { + return not_supported("changing permissions is not supported on this platform"); + } open_options .create_new(true) .read(true) diff --git a/src/lib.rs b/src/lib.rs index 798c2276d..b5c9364e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -420,7 +420,8 @@ impl<'a, 'b> Builder<'a, 'b> { /// /// ## Windows and others /// - /// This setting is ignored. + /// This setting is unsupported and trying to set a directory read-only + /// will cause an error to be returned.. /// /// # Limitations ///