Skip to content

Commit

Permalink
feat(windows): report executable files
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi authored and gierens committed Jan 20, 2025
1 parent 5ac404e commit b4496ea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
39 changes: 31 additions & 8 deletions src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#[cfg(unix)]
use std::collections::HashMap;
#[cfg(windows)]
use std::collections::HashSet;
#[cfg(windows)]
use std::env;
use std::fs::FileType;
use std::io;
#[cfg(unix)]
Expand Down Expand Up @@ -331,16 +335,35 @@ impl<'dir> File<'dir> {
/// Whether this file is both a regular file *and* executable for the
/// current user. An executable file has a different purpose from an
/// executable directory, so they should be highlighted differently.
#[cfg(unix)]
pub fn is_executable_file(&self) -> bool {
let bit = modes::USER_EXECUTE;
if !self.is_file() {
return false;
#[cfg(unix)]
{
let bit = modes::USER_EXECUTE;
if !self.is_file() {
return false;
}
let Ok(md) = self.metadata() else {
return false;
};
(md.permissions().mode() & bit) == bit
}
#[cfg(windows)]
{
let Some(ext) = self.ext.as_ref() else {
return false;
};

static PATHEXT: OnceLock<HashSet<String>> = OnceLock::new();
PATHEXT
.get_or_init(|| {
env::var("PATHEXT")
.unwrap_or_default()
.split(';')
.map(|s| s[1..].to_string())
.collect::<HashSet<String>>()
})
.contains(&ext.to_uppercase())
}
let Ok(md) = self.metadata() else {
return false;
};
(md.permissions().mode() & bit) == bit
}

/// Whether this file is a symlink on the filesystem.
Expand Down
1 change: 0 additions & 1 deletion src/output/file_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
return match self.file {
f if f.is_mount_point() => self.colours.mount_point(),
f if f.is_directory() => self.colours.directory(),
#[cfg(unix)]
f if f.is_executable_file() => self.colours.executable_file(),
f if f.is_link() => self.colours.symlink(),
#[cfg(unix)]
Expand Down

0 comments on commit b4496ea

Please sign in to comment.