Function set_permissions_nofollow

pub fn set_permissions_nofollow<P: AsRef<Path>>(path: P, perm: Permissions) -> Result<()>

Changes the permissions found on a file or a directory. On certain platforms, if the file is a symlink, it will change the permissions bits on the symlink itself rather than the target (e.g. Windows, BSD, MacOS). On other platforms, this results in an error when attempting to change permissions on a symlink (e.g. Linux).

Note that non-final path elements are allowed to be symlinks.

Platform-specific behavior

This function currently corresponds to the following underlying operations:

Note that, this may change in the future.

Errors

This function will return an error in the following situations, but is not limited to just these cases:

Note: On Linux and other Unix-based platforms with symlinks (non-BSD-based), this will result in an Unsupported error if the final element is a symlink.

Examples

#![feature(set_permissions_nofollow)]
use std::fs;

fn main() -> std::io::Result<()> {
    let mut perms = fs::symlink_metadata("foo.txt")?.permissions();
    perms.set_readonly(true);
    // This should result in an error on certain platforms or
    // succeed in modifying the permissions of a symlink
    fs::set_permissions_nofollow("foo.txt", perms)?;
    Ok(())
}