From 8bb33867519e5de35f3b279c11b2cd1f02a02003 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/mod.rs | 1 + src/file/imp/windows.rs | 9 ++++++++- src/lib.rs | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/file/imp/mod.rs b/src/file/imp/mod.rs index fbb2bbf63..08451fd7f 100644 --- a/src/file/imp/mod.rs +++ b/src/file/imp/mod.rs @@ -1,3 +1,4 @@ +use std::io; cfg_if::cfg_if! { if #[cfg(any(unix, target_os = "redox", target_os = "wasi"))] { mod unix; 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 ///