Improve permissions descriptions

This commit is contained in:
Jeremy Soller 2025-02-12 10:45:20 -07:00
parent b9b909c628
commit 17b0c665e7
No known key found for this signature in database
GPG key ID: 670FDFB5428E05CA
2 changed files with 31 additions and 9 deletions

View file

@ -104,9 +104,22 @@ open-with = Open with
owner = Owner
group = Group
other = Other
read = Read
write = Write
execute = Execute
### Mode 0
none = None
### Mode 1 (unusual)
execute-only = Execute-only
### Mode 2 (unusual)
write-only = Write-only
### Mode 3 (unusual)
write-execute = Write and execute
### Mode 4
read-only = Read-only
### Mode 5
read-execute = Read and execute
### Mode 6
read-write = Read and write
### Mode 7
read-write-execute = Read, write, and execute
# Context Pages

View file

@ -343,30 +343,39 @@ fn format_permissions_owner(metadata: &Metadata, owner: PermissionOwner) -> Stri
}
fn format_permissions(metadata: &Metadata, owner: PermissionOwner) -> String {
let mut perms: Vec<String> = Vec::new();
let mut mode = 0;
if match owner {
PermissionOwner::Owner => metadata.permissions().readable_by_owner(),
PermissionOwner::Group => metadata.permissions().readable_by_group(),
PermissionOwner::Other => metadata.permissions().readable_by_other(),
} {
perms.push(fl!("read"));
mode |= 4;
}
if match owner {
PermissionOwner::Owner => metadata.permissions().writable_by_owner(),
PermissionOwner::Group => metadata.permissions().writable_by_group(),
PermissionOwner::Other => metadata.permissions().writable_by_other(),
} {
perms.push(fl!("write"));
mode |= 2;
}
if match owner {
PermissionOwner::Owner => metadata.permissions().executable_by_owner(),
PermissionOwner::Group => metadata.permissions().executable_by_group(),
PermissionOwner::Other => metadata.permissions().executable_by_other(),
} {
perms.push(fl!("execute"));
mode |= 1;
}
match mode {
0 => fl!("none"),
1 => fl!("execute-only"),
2 => fl!("write-only"),
3 => fl!("write-execute"),
4 => fl!("read-only"),
5 => fl!("read-execute"),
6 => fl!("read-write"),
7 => fl!("read-write-execute"),
_ => unreachable!(),
}
perms.join(" ")
}
struct FormatTime(SystemTime);