2023-04-20 15:19:36 +00:00
|
|
|
//@ignore-target-windows
|
2023-07-27 11:40:22 +00:00
|
|
|
|
2021-03-29 18:18:59 +00:00
|
|
|
#![warn(clippy::non_octal_unix_permissions)]
|
|
|
|
use std::fs::{DirBuilder, File, OpenOptions, Permissions};
|
|
|
|
use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt, PermissionsExt};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let permissions = 0o760;
|
|
|
|
|
|
|
|
// OpenOptionsExt::mode
|
|
|
|
let mut options = OpenOptions::new();
|
|
|
|
options.mode(0o440);
|
|
|
|
options.mode(0o400);
|
|
|
|
options.mode(permissions);
|
|
|
|
|
|
|
|
// PermissionsExt::from_mode
|
|
|
|
let _permissions = Permissions::from_mode(0o647);
|
|
|
|
let _permissions = Permissions::from_mode(0o000);
|
|
|
|
let _permissions = Permissions::from_mode(permissions);
|
|
|
|
|
|
|
|
// PermissionsExt::set_mode
|
|
|
|
let f = File::create("foo.txt").unwrap();
|
|
|
|
let metadata = f.metadata().unwrap();
|
|
|
|
let mut permissions = metadata.permissions();
|
|
|
|
|
|
|
|
permissions.set_mode(0o644);
|
|
|
|
permissions.set_mode(0o704);
|
2024-01-06 13:41:25 +00:00
|
|
|
// no error
|
|
|
|
permissions.set_mode(0b111_000_100);
|
2021-03-29 18:18:59 +00:00
|
|
|
|
|
|
|
// DirBuilderExt::mode
|
|
|
|
let mut builder = DirBuilder::new();
|
|
|
|
builder.mode(0o755);
|
|
|
|
builder.mode(0o406);
|
2024-01-06 13:41:25 +00:00
|
|
|
// no error
|
|
|
|
permissions.set_mode(0b111000100);
|
2021-03-29 18:18:59 +00:00
|
|
|
}
|