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

bin+lib file-mode

解码 Unix 文件模式位,更改它们并将它们应用于文件

3 个版本

0.1.2 2021年2月24日
0.1.1 2021年2月24日
0.1.0 2021年2月24日

#6 in #target-file

Download history • Rust 包仓库 1516/week @ 2024-03-25 • Rust 包仓库 1464/week @ 2024-04-01 • Rust 包仓库 1885/week @ 2024-04-08 • Rust 包仓库 1278/week @ 2024-04-15 • Rust 包仓库 2121/week @ 2024-04-22 • Rust 包仓库 1517/week @ 2024-04-29 • Rust 包仓库 1442/week @ 2024-05-06 • Rust 包仓库 1868/week @ 2024-05-13 • Rust 包仓库 877/week @ 2024-05-20 • Rust 包仓库 964/week @ 2024-05-27 • Rust 包仓库 908/week @ 2024-06-03 • Rust 包仓库 1034/week @ 2024-06-10 • Rust 包仓库 1127/week @ 2024-06-17 • Rust 包仓库 852/week @ 2024-06-24 • Rust 包仓库 854/week @ 2024-07-01 • Rust 包仓库 929/week @ 2024-07-08 • Rust 包仓库

3,812 每月下载量
12 个 Crates (9 直接) 中使用

MIT 许可证

68KB
1.5K SLoC

Latest Version Documentation License

解码 Unix 文件模式位,更改它们并将它们应用于文件。

表示了 sys/stat.h 中描述的所有文件类型、特殊和保护位。

使用位掩码,Mode 对象可以部分表示文件模式。只有修改过的位会在目标文件中更改。针对目录(搜索)的特定修改也会正确处理。

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();

有关更多示例,请参阅docs.rs上的模块级别文档。

依赖项

~185KB