about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorbinarycat <binarycat@envs.net>2025-06-23 19:06:36 -0500
committerbinarycat <binarycat@envs.net>2025-08-18 11:37:19 -0500
commitaa3008d52e7372af64bf1beda9dc5da5e653bdb6 (patch)
tree2dc7e5a42c4c31e79f6dbd8df62792e68263e691 /library/std/src/sys
parent3b9d04c62f74b9be46c3ba56cf8393529aa81d26 (diff)
downloadrust-aa3008d52e7372af64bf1beda9dc5da5e653bdb6.tar.gz
rust-aa3008d52e7372af64bf1beda9dc5da5e653bdb6.zip
implement std::fs::set_permissions_nofollow on unix
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/fs/mod.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/library/std/src/sys/fs/mod.rs b/library/std/src/sys/fs/mod.rs
index d55e28074fe..d7f98c86e6e 100644
--- a/library/std/src/sys/fs/mod.rs
+++ b/library/std/src/sys/fs/mod.rs
@@ -108,6 +108,21 @@ pub fn set_permissions(path: &Path, perm: FilePermissions) -> io::Result<()> {
     with_native_path(path, &|path| imp::set_perm(path, perm.clone()))
 }
 
+#[cfg(unix)]
+pub fn set_permissions_nofollow(path: &Path, perm: crate::fs::Permissions) -> io::Result<()> {
+    use crate::fs::OpenOptions;
+    use crate::os::unix::fs::OpenOptionsExt;
+
+    OpenOptions::new().custom_flags(libc::O_NOFOLLOW).open(path)?.set_permissions(perm)
+}
+
+#[cfg(not(unix))]
+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"
+    )
+}
+
 pub fn canonicalize(path: &Path) -> io::Result<PathBuf> {
     with_native_path(path, &imp::canonicalize)
 }