Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions library/std/src/sys/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,15 @@ pub fn set_permissions_nofollow(path: &Path, perm: crate::fs::Permissions) -> io
options.open(path)?.set_permissions(perm)
}

#[cfg(any(not(unix), target_os = "vxworks"))]
#[cfg(windows)]
pub fn set_permissions_nofollow(path: &Path, perm: crate::fs::Permissions) -> io::Result<()> {
with_native_path(path, &|path| imp::set_perm_nofollow(path, perm.0.clone()))
}

#[cfg(any(not(any(unix, windows)), target_os = "vxworks"))]
pub fn set_permissions_nofollow(_path: &Path, _perm: crate::fs::Permissions) -> io::Result<()> {
crate::unimplemented!(
"`set_permissions_nofollow` is currently only implemented on Unix platforms"
"`set_permissions_nofollow` is currently only implemented on Unix and Windows platforms"
)
}

Expand Down
20 changes: 16 additions & 4 deletions library/std/src/sys/fs/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,10 +1558,22 @@ fn metadata(path: &WCStr, reparse: ReparsePoint) -> io::Result<FileAttr> {
}

pub fn set_perm(p: &WCStr, perm: FilePermissions) -> io::Result<()> {
unsafe {
cvt(c::SetFileAttributesW(p.as_ptr(), perm.attrs))?;
Ok(())
}
// Open the target (follow reparse points) and set attributes via handle so
// behavior matches `File::set_permissions` rather than ambiguous path APIs.
let mut opts = OpenOptions::new();
opts.access_mode(c::FILE_WRITE_ATTRIBUTES);
opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS);
let file = File::open_native(p, &opts)?;
file.set_permissions(perm)
}

pub fn set_perm_nofollow(p: &WCStr, perm: FilePermissions) -> io::Result<()> {
let mut opts = OpenOptions::new();
opts.access_mode(c::FILE_WRITE_ATTRIBUTES);
// `FILE_FLAG_OPEN_REPARSE_POINT` so permissions apply to the link/junction itself.
opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS | c::FILE_FLAG_OPEN_REPARSE_POINT);
let file = File::open_native(p, &opts)?;
file.set_permissions(perm)
}

pub fn set_times(p: &WCStr, times: FileTimes) -> io::Result<()> {
Expand Down