@@ -3335,23 +3335,58 @@ pub fn set_permissions<P: AsRef<Path>>(path: P, perm: Permissions) -> io::Result
33353335 fs_imp:: set_permissions ( path. as_ref ( ) , perm. 0 )
33363336}
33373337
3338- /// Set the permissions of a file, unless it is a symlink.
3338+ /// Changes the permissions found on a file or a directory. On certain platforms, if the file
3339+ /// is a symlink, it will change the permissions bits on the symlink itself rather than
3340+ /// the target (e.g. Windows, BSD, MacOS). On other platforms, this results in an error when
3341+ /// attempting to change permissions on a symlink (e.g. Linux).
33393342///
3340- /// Note that the non-final path elements are allowed to be symlinks.
3343+ /// Note that non-final path elements are allowed to be symlinks.
33413344///
33423345/// # Platform-specific behavior
33433346///
3344- /// Currently unimplemented on Windows.
3347+ /// This function currently corresponds to the `fchmodat` function on Unix
3348+ /// with the flag `AT_SYMLINK_NOFOLLOW` enabled. On Windows, the file is opened
3349+ /// with the flag `FILE_FLAG_OPEN_REPARSE_POINT` enabled and then the permissions
3350+ /// is set through `SetFileInformationByHandle`. On all other platforms, the behavior
3351+ /// remains the same with [`fs::set_permissions`].
33453352///
3346- /// On Unix platforms, this results in a [`FilesystemLoop`] error if the last element is a symlink.
3353+ /// [`fs::set_permissions`]: crate::fs::set_permissions
33473354///
3348- /// This behavior may change in the future.
3355+ /// Note that, this [ may change in the future][changes] .
33493356///
3350- /// [`FilesystemLoop`]: crate::io::ErrorKind::FilesystemLoop
3351- #[ doc( alias = "chmod" , alias = "SetFileAttributes" ) ]
3357+ /// [changes]: io#platform-specific-behavior
3358+ ///
3359+ /// # Errors
3360+ ///
3361+ /// This function will return an error in the following situations, but is not
3362+ /// limited to just these cases:
3363+ ///
3364+ /// * `path` does not exist.
3365+ /// * The user lacks the permission to change attributes of the file.
3366+ ///
3367+ /// Note: On Linux, this will result in a [`Unsupported`] error
3368+ /// if the final element is a symlink.
3369+ ///
3370+ /// [`Unsupported`]: crate::io::ErrorKind::Unsupported
3371+ ///
3372+ /// # Examples
3373+ ///
3374+ /// ```no_run
3375+ /// use std::fs;
3376+ ///
3377+ /// fn main() -> std::io::Result<()> {
3378+ /// let mut perms = fs::symlink_metadata("foo.txt")?.permissions();
3379+ /// perms.set_readonly(true);
3380+ /// // This should result in an error on certain platforms
3381+ /// // or succeed in modifying the permissions of a symlink
3382+ /// fs::set_permissions_nofollow("foo.txt", perms)?;
3383+ /// Ok(())
3384+ /// }
3385+ /// ```
3386+ #[ doc( alias = "fchmodat" , alias = "SetFileInformationByHandle" ) ]
33523387#[ unstable( feature = "set_permissions_nofollow" , issue = "141607" ) ]
33533388pub fn set_permissions_nofollow < P : AsRef < Path > > ( path : P , perm : Permissions ) -> io:: Result < ( ) > {
3354- fs_imp:: set_permissions_nofollow ( path. as_ref ( ) , perm)
3389+ fs_imp:: set_permissions_nofollow ( path. as_ref ( ) , perm. 0 )
33553390}
33563391
33573392impl DirBuilder {
0 commit comments