Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for ca (regular file with capabilities set) #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ nu-ansi-term = { version = "0.50", optional = true }
crossterm = { version = "0.27", optional = true }
owo-colors = { version = "4.0", optional = true }

[target.'cfg(target_os = "linux")'.dependencies]
capctl = "0.2.4"

[dev-dependencies]
tempfile = "^3"

Expand Down
17 changes: 16 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ pub trait Colorable {

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

#[cfg(target_os = "linux")]
fn has_capabilities(&self) -> bool {
matches!(
capctl::caps::FileCaps::get_for_file(self.path()),
Ok(Some(..))
)
}
#[cfg(not(target_os = "linux"))]
fn has_capabilities(&self) -> bool {
false
}
}

impl Colorable for DirEntry {
Expand Down Expand Up @@ -333,11 +345,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
Loading