Skip to content

Commit

Permalink
support for ca (regular file with capabilities set)
Browse files Browse the repository at this point in the history
  • Loading branch information
matrixhead committed Jul 6, 2024
1 parent 9f8e580 commit 1128a36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ansi_term = { version = "0.12", optional = true }
nu-ansi-term = { version = "0.50", optional = true }
crossterm = { version = "0.27", optional = true }
owo-colors = { version = "4.0", optional = true }
capctl = "0.2.4"

[dev-dependencies]
tempfile = "^3"
Expand Down
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ pub trait Colorable {

/// Try to get the metadata for this file.
fn metadata(&self) -> Option<Metadata>;

fn has_capabilities(&self) -> bool {
matches!(
capctl::caps::FileCaps::get_for_file(self.path()),
Ok(Some(..))
)
}
}

impl Colorable for DirEntry {
Expand Down Expand Up @@ -333,11 +340,14 @@ impl LsColors {
if let Some(metadata) = file.metadata() {
let mode = crate::fs::mode(&metadata);
let nlink = crate::fs::nlink(&metadata);

if self.has_color_for(Indicator::Setuid) && mode & 0o4000 != 0 {
return Indicator::Setuid;
} else if self.has_color_for(Indicator::Setgid) && mode & 0o2000 != 0 {
return Indicator::Setgid;
} else if self.has_color_for(Indicator::Capabilities)
&& file.has_capabilities()
{
return Indicator::Capabilities;
} else if self.has_color_for(Indicator::ExecutableFile)
&& mode & 0o0111 != 0
{
Expand Down

0 comments on commit 1128a36

Please sign in to comment.