Skip to content

Commit 4c1c83f

Browse files
committed
LsColors: change has_color_for to public visibility & rename to has_explicit_syle_for
coreutils (https://github.com/uutils/coreutils) uses style_for_indicator to check if a style for Indicator::Capabilities is available. However, style_for_indicator uses fallbacks and can therefore return a style even if no direct style for Indicator::Capabilities is set. Directly being able to use has_color_for allows to fix that.
1 parent fd932f8 commit 4c1c83f

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -333,23 +333,23 @@ impl LsColors {
333333
}
334334

335335
/// Check if an indicator has an associated color.
336-
fn has_color_for(&self, indicator: Indicator) -> bool {
336+
pub fn has_explicit_syle_for(&self, indicator: Indicator) -> bool {
337337
self.indicator_mapping.contains_key(&indicator)
338338
}
339339

340340
/// Check if we need metadata to color a regular file.
341341
fn needs_file_metadata(&self) -> bool {
342-
self.has_color_for(Indicator::Setuid)
343-
|| self.has_color_for(Indicator::Setgid)
344-
|| self.has_color_for(Indicator::ExecutableFile)
345-
|| self.has_color_for(Indicator::MultipleHardLinks)
342+
self.has_explicit_syle_for(Indicator::Setuid)
343+
|| self.has_explicit_syle_for(Indicator::Setgid)
344+
|| self.has_explicit_syle_for(Indicator::ExecutableFile)
345+
|| self.has_explicit_syle_for(Indicator::MultipleHardLinks)
346346
}
347347

348348
/// Check if we need metadata to color a directory.
349349
fn needs_dir_metadata(&self) -> bool {
350-
self.has_color_for(Indicator::StickyAndOtherWritable)
351-
|| self.has_color_for(Indicator::OtherWritable)
352-
|| self.has_color_for(Indicator::Sticky)
350+
self.has_explicit_syle_for(Indicator::StickyAndOtherWritable)
351+
|| self.has_explicit_syle_for(Indicator::OtherWritable)
352+
|| self.has_explicit_syle_for(Indicator::Sticky)
353353
}
354354

355355
/// Get the indicator type for a path with corresponding metadata.
@@ -363,15 +363,15 @@ impl LsColors {
363363
let mode = crate::fs::mode(&metadata);
364364
let nlink = crate::fs::nlink(&metadata);
365365

366-
if self.has_color_for(Indicator::Setuid) && mode & 0o4000 != 0 {
366+
if self.has_explicit_syle_for(Indicator::Setuid) && mode & 0o4000 != 0 {
367367
return Indicator::Setuid;
368-
} else if self.has_color_for(Indicator::Setgid) && mode & 0o2000 != 0 {
368+
} else if self.has_explicit_syle_for(Indicator::Setgid) && mode & 0o2000 != 0 {
369369
return Indicator::Setgid;
370-
} else if self.has_color_for(Indicator::ExecutableFile)
370+
} else if self.has_explicit_syle_for(Indicator::ExecutableFile)
371371
&& mode & 0o0111 != 0
372372
{
373373
return Indicator::ExecutableFile;
374-
} else if self.has_color_for(Indicator::MultipleHardLinks) && nlink > 1 {
374+
} else if self.has_explicit_syle_for(Indicator::MultipleHardLinks) && nlink > 1 {
375375
return Indicator::MultipleHardLinks;
376376
}
377377
}
@@ -383,14 +383,14 @@ impl LsColors {
383383
if let Some(metadata) = file.metadata() {
384384
let mode = crate::fs::mode(&metadata);
385385

386-
if self.has_color_for(Indicator::StickyAndOtherWritable)
386+
if self.has_explicit_syle_for(Indicator::StickyAndOtherWritable)
387387
&& mode & 0o1002 == 0o1002
388388
{
389389
return Indicator::StickyAndOtherWritable;
390-
} else if self.has_color_for(Indicator::OtherWritable) && mode & 0o0002 != 0
390+
} else if self.has_explicit_syle_for(Indicator::OtherWritable) && mode & 0o0002 != 0
391391
{
392392
return Indicator::OtherWritable;
393-
} else if self.has_color_for(Indicator::Sticky) && mode & 0o1000 != 0 {
393+
} else if self.has_explicit_syle_for(Indicator::Sticky) && mode & 0o1000 != 0 {
394394
return Indicator::Sticky;
395395
}
396396
}
@@ -399,7 +399,7 @@ impl LsColors {
399399
Indicator::Directory
400400
} else if file_type.is_symlink() {
401401
// This works because `Path::exists` traverses symlinks.
402-
if self.has_color_for(Indicator::OrphanedSymbolicLink) && !file.path().exists() {
402+
if self.has_explicit_syle_for(Indicator::OrphanedSymbolicLink) && !file.path().exists() {
403403
return Indicator::OrphanedSymbolicLink;
404404
}
405405

0 commit comments

Comments
 (0)