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 640you should set a umask of:
umask 037which 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
Rustdirectory permissions are0o755orrwxr-xr-x - The default
Rustfile permissions are0o666orrw-r--r--
§Examples
| Desired permissions | chmod equivalent | umask() |
|---|---|---|
rwxr----- | chmod 755 | umask(0o022) |
rwxrwx--- | chmod 770 | umask(0o007) |
rwxrw---- | chmod 760 | umask(0o017) |
rwxr-x--- | chmod 750 | umask(0o027) |
rwxr----- | chmod 740 | umask(0o037) |
rwx------ | chmod 740 | umask(0o077) |
§Note
This function does nothing on non-UNIX targets (Windows).