Skip to content

Commit 16a579a

Browse files
committed
feat(windows): report executable files
1 parent f41887b commit 16a579a

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/fs/file.rs

+29-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
#[cfg(unix)]
1010
use std::collections::HashMap;
11+
#[cfg(windows)]
12+
use std::collections::HashSet;
13+
#[cfg(windows)]
14+
use std::env;
1115
use std::fs::FileType;
1216
use std::io;
1317
#[cfg(unix)]
@@ -25,7 +29,6 @@ use std::time::SystemTime;
2529
use chrono::prelude::*;
2630

2731
use log::*;
28-
#[cfg(unix)]
2932
use once_cell::sync::Lazy;
3033

3134
use crate::fs::dir::Dir;
@@ -331,16 +334,33 @@ impl<'dir> File<'dir> {
331334
/// Whether this file is both a regular file *and* executable for the
332335
/// current user. An executable file has a different purpose from an
333336
/// executable directory, so they should be highlighted differently.
334-
#[cfg(unix)]
335337
pub fn is_executable_file(&self) -> bool {
336-
let bit = modes::USER_EXECUTE;
337-
if !self.is_file() {
338-
return false;
338+
#[cfg(unix)]
339+
{
340+
let bit = modes::USER_EXECUTE;
341+
if !self.is_file() {
342+
return false;
343+
}
344+
let Ok(md) = self.metadata() else {
345+
return false;
346+
};
347+
(md.permissions().mode() & bit) == bit
348+
}
349+
#[cfg(windows)]
350+
{
351+
let Some(ext) = self.ext.as_ref() else {
352+
return false;
353+
};
354+
355+
static PATHEXT: Lazy<HashSet<String>> = Lazy::new(|| {
356+
env::var("PATHEXT")
357+
.unwrap_or_default()
358+
.split(';')
359+
.map(|s| s[1..].to_string())
360+
.collect::<HashSet<String>>()
361+
});
362+
PATHEXT.contains(&ext.to_uppercase())
339363
}
340-
let Ok(md) = self.metadata() else {
341-
return false;
342-
};
343-
(md.permissions().mode() & bit) == bit
344364
}
345365

346366
/// Whether this file is a symlink on the filesystem.

src/output/file_name.rs

-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
489489
return match self.file {
490490
f if f.is_mount_point() => self.colours.mount_point(),
491491
f if f.is_directory() => self.colours.directory(),
492-
#[cfg(unix)]
493492
f if f.is_executable_file() => self.colours.executable_file(),
494493
f if f.is_link() => self.colours.symlink(),
495494
#[cfg(unix)]

0 commit comments

Comments
 (0)