1 个稳定版本
1.0.0 | 2024 年 8 月 2 日 |
---|
#1327 在 解析实现
100 每月下载量
28KB
510 行
Permcon
一个简单的库/CLI,用于解析 Linux 文件权限并在符号和八进制表示法之间转换。此包是我 Node.js CLI permcon 的 Rust 版本。
安装
cargo install permcon
库用法
use permcon::{FilePermission, GroupPermission, SourceFormat, SpecialPermission};
use permcon::utils::get_filetype_from_char;
let perm = FilePermission::try_from("-rwxr-xr-T").unwrap();
assert_eq!(perm, FilePermission {
user: GroupPermission {
read: true,
write: true,
execute: true,
special: false,
},
group: GroupPermission {
read: true,
write: false,
execute: true,
special: false,
},
other: GroupPermission {
read: true,
write: false,
execute: false,
special: true,
},
filetype_char: '-',
filetype: get_filetype_from_char('-'),
source_format: Some(SourceFormat::Symbolic),
special: [SpecialPermission::Nil, SpecialPermission::Nil, SpecialPermission::StickyBit],
});
CLI 用法
❯ permcon 1754
# -rwxr-xr-T
❯ permcon rwxrwxr-t
# 1775
# Note: a `--` is required if the permission string starts with an `-`.
❯ permcon -- -rwxrwxr-t
# 1775
❯ permcon -a -- -rwxrwxr-t
# file type : Regular File
# symbolic : -rwxrwxr-t
# octal : 1775
# ------------------------
# user (rwx, 7): read, write, execute
# group(rwx, 7): read, write, execute
# other(r-t, 5): read, _ , (execute, StickyBit)
# ------------------------
# special permissions: StickyBit
❯ permcon -a 1754
# file type : Unknown
# symbolic : -rwxr-xr-T
# octal : 1754
# ------------------------
# user (rwx, 7): read, write, execute
# group(r-x, 5): read, _ , execute
# other(r-T, 4): read, _ , (_, StickyBit)
# ------------------------
# special permissions: StickyBit
如果您发现错误或想改进某些内容,请随时打开一个问题或创建一个拉取请求 :).
依赖项
~4–6MB
~106K SLoC