file-mode

Crates.iofile-mode
lib.rsfile-mode
version0.1.2
sourcesrc
created_at2021-02-24 11:58:22.111666
updated_at2021-02-24 12:03:09.983672
descriptionDecode Unix file mode bits, change them and apply them to files
homepagehttps://sr.ht/~jpastuszek/file-mode/
repositoryhttps://git.sr.ht/~jpastuszek/file-mode
max_upload_size
id359943
size72,937
Jakub Pastuszek (jpastuszek)

documentation

https://docs.rs/file-mode

README

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.

Commit count: 0

cargo fmt