File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -3156,6 +3156,25 @@ pub fn set_permissions<P: AsRef<Path>>(path: P, perm: Permissions) -> io::Result
3156
3156
fs_imp:: set_permissions ( path. as_ref ( ) , perm. 0 )
3157
3157
}
3158
3158
3159
+ /// Set the permissions of a file, unless it is a symlink.
3160
+ ///
3161
+ /// Note that the non-final path elements are allowed to be symlinks.
3162
+ ///
3163
+ /// # Platform-specific behavior
3164
+ ///
3165
+ /// Currently unimplemented on Windows.
3166
+ ///
3167
+ /// On Unix platforms, this results in a [`FilesystemLoop`] error if the last element is a symlink.
3168
+ ///
3169
+ /// This behavior may change in the future.
3170
+ ///
3171
+ /// [`FilesystemLoop`]: crate::io::ErrorKind::FilesystemLoop
3172
+ #[ doc( alias = "chmod" , alias = "SetFileAttributes" ) ]
3173
+ #[ unstable( feature = "set_permissions_nofollow" , issue = "141607" ) ]
3174
+ pub fn set_permissions_nofollow < P : AsRef < Path > > ( path : P , perm : Permissions ) -> io:: Result < ( ) > {
3175
+ fs_imp:: set_permissions_nofollow ( path. as_ref ( ) , perm)
3176
+ }
3177
+
3159
3178
impl DirBuilder {
3160
3179
/// Creates a new set of options with default mode/security settings for all
3161
3180
/// platforms and also non-recursive.
Original file line number Diff line number Diff line change @@ -108,6 +108,21 @@ pub fn set_permissions(path: &Path, perm: FilePermissions) -> io::Result<()> {
108
108
with_native_path ( path, & |path| imp:: set_perm ( path, perm. clone ( ) ) )
109
109
}
110
110
111
+ #[ cfg( unix) ]
112
+ pub fn set_permissions_nofollow ( path : & Path , perm : crate :: fs:: Permissions ) -> io:: Result < ( ) > {
113
+ use crate :: fs:: OpenOptions ;
114
+ use crate :: os:: unix:: fs:: OpenOptionsExt ;
115
+
116
+ OpenOptions :: new ( ) . custom_flags ( libc:: O_NOFOLLOW ) . open ( path) ?. set_permissions ( perm)
117
+ }
118
+
119
+ #[ cfg( not( unix) ) ]
120
+ pub fn set_permissions_nofollow ( _path : & Path , _perm : crate :: fs:: Permissions ) -> io:: Result < ( ) > {
121
+ crate :: unimplemented!(
122
+ "`set_permissions_nofollow` is currently only implemented on Unix platforms"
123
+ )
124
+ }
125
+
111
126
pub fn canonicalize ( path : & Path ) -> io:: Result < PathBuf > {
112
127
with_native_path ( path, & imp:: canonicalize)
113
128
}
You can’t perform that action at this time.
0 commit comments