Display file ownership and permissions.
This subsumes #414. Took feedback into account to display more human-readble permissions. Also, display the owner and group ownership inline with the permissions themselves.
This commit is contained in:
parent
b6bc5132bb
commit
4ba816b151
4 changed files with 128 additions and 2 deletions
97
src/tab.rs
97
src/tab.rs
|
|
@ -43,6 +43,7 @@ use std::{
|
|||
fmt,
|
||||
fs::{self, Metadata},
|
||||
num::NonZeroU16,
|
||||
os::unix::fs::MetadataExt,
|
||||
path::PathBuf,
|
||||
sync::{Arc, Mutex},
|
||||
time::{Duration, Instant},
|
||||
|
|
@ -60,6 +61,8 @@ use crate::{
|
|||
mime_icon::{mime_for_path, mime_icon},
|
||||
mouse_area,
|
||||
};
|
||||
use unix_permissions_ext::UNIXPermissionsExt;
|
||||
use users::{get_group_by_gid, get_user_by_uid};
|
||||
|
||||
pub const DOUBLE_CLICK_DURATION: Duration = Duration::from_millis(500);
|
||||
pub const HOVER_DURATION: Duration = Duration::from_millis(1600);
|
||||
|
|
@ -199,6 +202,60 @@ fn format_size(size: u64) -> String {
|
|||
format!("{} B", size)
|
||||
}
|
||||
}
|
||||
enum PermissionOwner {
|
||||
Owner,
|
||||
Group,
|
||||
Other,
|
||||
}
|
||||
|
||||
fn format_permissions_owner(metadata: &Metadata, owner: PermissionOwner) -> String {
|
||||
return match owner {
|
||||
PermissionOwner::Owner => get_user_by_uid(metadata.uid())
|
||||
.and_then(|user| user.name().to_str().map(ToOwned::to_owned))
|
||||
.unwrap_or_default(),
|
||||
PermissionOwner::Group => get_group_by_gid(metadata.gid())
|
||||
.and_then(|group| group.name().to_str().map(ToOwned::to_owned))
|
||||
.unwrap_or_default(),
|
||||
PermissionOwner::Other => String::from(""),
|
||||
};
|
||||
}
|
||||
fn format_permissions(metadata: &Metadata, owner: PermissionOwner) -> String {
|
||||
let readable = match owner {
|
||||
PermissionOwner::Owner => metadata.permissions().readable_by_owner(),
|
||||
PermissionOwner::Group => metadata.permissions().readable_by_group(),
|
||||
PermissionOwner::Other => metadata.permissions().readable_by_other(),
|
||||
};
|
||||
let writeable = match owner {
|
||||
PermissionOwner::Owner => metadata.permissions().writable_by_owner(),
|
||||
PermissionOwner::Group => metadata.permissions().writable_by_group(),
|
||||
PermissionOwner::Other => metadata.permissions().writable_by_other(),
|
||||
};
|
||||
let executable = match owner {
|
||||
PermissionOwner::Owner => metadata.permissions().executable_by_owner(),
|
||||
PermissionOwner::Group => metadata.permissions().executable_by_group(),
|
||||
PermissionOwner::Other => metadata.permissions().executable_by_other(),
|
||||
};
|
||||
format!(
|
||||
"{} {} {}",
|
||||
if readable {
|
||||
fl!("read")
|
||||
} else {
|
||||
String::from("")
|
||||
},
|
||||
if writeable {
|
||||
fl!("write")
|
||||
} else {
|
||||
String::from("")
|
||||
},
|
||||
if executable {
|
||||
fl!("execute")
|
||||
} else {
|
||||
String::from("")
|
||||
}
|
||||
)
|
||||
.trim_end()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn hidden_attribute(_metadata: &Metadata) -> bool {
|
||||
|
|
@ -828,6 +885,46 @@ impl Item {
|
|||
.format_localized(TIME_FORMAT, *LANGUAGE_CHRONO)
|
||||
)));
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
column = column.push(
|
||||
widget::Row::new()
|
||||
.push(widget::text(format!("{}:", fl!("owner"))))
|
||||
.push(widget::text(format_permissions_owner(
|
||||
metadata,
|
||||
PermissionOwner::Owner,
|
||||
)))
|
||||
.push(widget::text(format!(
|
||||
"({})",
|
||||
format_permissions(metadata, PermissionOwner::Owner,)
|
||||
)))
|
||||
.spacing(10),
|
||||
);
|
||||
|
||||
column = column.push(
|
||||
widget::Row::new()
|
||||
.push(widget::text(format!("{}:", fl!("group"))))
|
||||
.push(widget::text(format_permissions_owner(
|
||||
metadata,
|
||||
PermissionOwner::Group,
|
||||
)))
|
||||
.push(widget::text(format!(
|
||||
"({})",
|
||||
format_permissions(metadata, PermissionOwner::Group,)
|
||||
)))
|
||||
.spacing(10),
|
||||
);
|
||||
|
||||
column = column.push(
|
||||
widget::Row::new()
|
||||
.push(widget::text(format!("{}", fl!("other"))))
|
||||
.push(widget::text(format!(
|
||||
"({})",
|
||||
format_permissions(metadata, PermissionOwner::Other,)
|
||||
)))
|
||||
.spacing(10),
|
||||
);
|
||||
}
|
||||
}
|
||||
ItemMetadata::Trash { .. } => {
|
||||
//TODO: trash metadata
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue