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

26be86e (cargo-release) version 0.1.2

1 year, 4 months ago

2cfce72 (cargo-release) start next development iteration 0.1.2

1 year, 4 months ago

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

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

// apply chmod string

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