#unix-file #mode #file #unix #chmod #target-file #object-file

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

#7 in #chmod

Download history 974/week @ 2024-05-22 861/week @ 2024-05-29 969/week @ 2024-06-05 1034/week @ 2024-06-12 1109/week @ 2024-06-19 785/week @ 2024-06-26 912/week @ 2024-07-03 743/week @ 2024-07-10 1005/week @ 2024-07-17 788/week @ 2024-07-24 733/week @ 2024-07-31 789/week @ 2024-08-07 593/week @ 2024-08-14 494/week @ 2024-08-21 577/week @ 2024-08-28 482/week @ 2024-09-04

2,296 downloads per month
Used in 12 crates (9 directly)

MIT license

68KB
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

~180KB