Skip to content

Commit

Permalink
Fail on Windows if somebody tries to set permissions there.
Browse files Browse the repository at this point in the history
That way, there will be no surprises as would be the case with
doing nothing.
  • Loading branch information
Byron committed Feb 4, 2024
1 parent 5ffc706 commit 8bb3386
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/file/imp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::io;
cfg_if::cfg_if! {
if #[cfg(any(unix, target_os = "redox", target_os = "wasi"))] {
mod unix;
Expand Down
9 changes: 8 additions & 1 deletion src/file/imp/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ fn to_utf16(s: &Path) -> Vec<u16> {
s.as_os_str().encode_wide().chain(iter::once(0)).collect()
}

fn not_supported<T>(msg: &str) -> io::Result<T> {
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<File> {
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)
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down

0 comments on commit 8bb3386

Please sign in to comment.