disk

Function umask

Source
pub fn umask(umask: u32)
Expand description

Set the umask value of your entire process.

This will be the permission umask used by disk (and your entire process) when creating directories/files.

Note, this is umask, not chmod, meaning, to get the equivalent behavior of:

chmod 640

you should set a umask of:

umask 037

which in Rust, using this function with octal notation, would look like:

fn main() {
    // Make all future writes use this `umask`.
    disk::umask(0o037);

   /* write some files with 640 (rw-r-----) perms */
   /* create directories with 740 (rwxr-----) perms */
}

The umask should take care to make sure that directory executable bits are not masked. umask cannot add executable bits so even with 0o000, files that did not already have it cannot gain them.

§Default values

These are the default values that will be subtracted from when using this function.

  • The default Rust directory permissions are 0o755 or rwxr-xr-x
  • The default Rust file permissions are 0o666 or rw-r--r--

§Examples

Desired permissionschmod equivalentumask()
rwxr-----chmod 755umask(0o022)
rwxrwx---chmod 770umask(0o007)
rwxrw----chmod 760umask(0o017)
rwxr-x---chmod 750umask(0o027)
rwxr-----chmod 740umask(0o037)
rwx------chmod 740umask(0o077)

§Note

This function does nothing on non-UNIX targets (Windows).