#file #mode #unix #chmod

bin+lib file-mode

Decode Unix file mode bits, change them and apply them to files

3 releases

0.1.2 Feb 24, 2021
0.1.1 Feb 24, 2021
0.1.0 Feb 24, 2021

#123 in Unix APIs

Download history 9/week @ 2021-08-12 4/week @ 2021-08-19 5/week @ 2021-09-09 1/week @ 2021-09-16 12/week @ 2021-09-23 9/week @ 2021-09-30 9/week @ 2021-10-07 7/week @ 2021-10-14 287/week @ 2021-10-21 252/week @ 2021-10-28 207/week @ 2021-11-04 138/week @ 2021-11-11 218/week @ 2021-11-18 124/week @ 2021-11-25

706 downloads per month
Used in 2 crates (via cotton)

MIT license

67KB
1.5K SLoC

Latest Version Documentation License

Decode Unix file mode bits, change them and apply them to files.

All file type, special and protection bits described in sys/stat.h are represented.

The Mode object can represent a file mode partially by the use of a bitmask. Only modified bits will be changed in the target file. Modifications specific only to directories (search) are handled correctly.

use std::path::Path;
use file_mode::{ModePath, User};

let mode = Path::new("LICENSE").mode().unwrap();

// query bits
assert!(mode.file_type().unwrap().is_regular_file());
assert!(mode.user_protection(User::Owner).is_read_set());
assert!(mode.user_protection(User::Group).is_write_set());
assert!(!mode.user_protection(User::Other).is_execute_set());

// print as string
println!("{}", mode); // -rw-rw-r--
assert_eq!(&mode.to_string(), "-rw-rw-r--");

// apply chmod string
Path::new("LICENSE").set_mode("u+r,g+u").unwrap();

See module level documentation on docs.rs for more examples.

Dependencies

~210KB