#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

#8 in #chmod

Download history 808/week @ 2023-12-06 803/week @ 2023-12-13 623/week @ 2023-12-20 535/week @ 2023-12-27 1040/week @ 2024-01-03 886/week @ 2024-01-10 885/week @ 2024-01-17 1124/week @ 2024-01-24 1110/week @ 2024-01-31 1127/week @ 2024-02-07 1247/week @ 2024-02-14 1008/week @ 2024-02-21 866/week @ 2024-02-28 807/week @ 2024-03-06 1096/week @ 2024-03-13 1590/week @ 2024-03-20

4,522 downloads per month
Used in 11 crates (8 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

~190KB