Skip to content

Commit

Permalink
windows: Also search for file without added extension (#57)
Browse files Browse the repository at this point in the history
Previously if the extension of the file to be searched for was not in the
list of executable extensions (env var `PATHEXT`), the original file name
would not be searched.
E.g. `script.py` would result in `script.py.EXE`, `script.py.COM`, and so on
to be searched.

This change prepends the original file to the search list if it already has
a file extension so that the unmodified filename will be searched aswell.
  • Loading branch information
N3xed authored Apr 12, 2022
1 parent cd6add3 commit 60fd009
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,25 @@ impl Finder {
if has_executable_extension(&p, &PATH_EXTENSIONS) {
Box::new(iter::once(p))
} else {
let bare_file = p.extension().map(|_| p.clone());
// Appended paths with windows executable extensions.
// e.g. path `c:/windows/bin` will expend to:
// c:/windows/bin.COM
// c:/windows/bin.EXE
// c:/windows/bin.CMD
// e.g. path `c:/windows/bin[.ext]` will expand to:
// [c:/windows/bin.ext]
// c:/windows/bin[.ext].COM
// c:/windows/bin[.ext].EXE
// c:/windows/bin[.ext].CMD
// ...
Box::new(PATH_EXTENSIONS.iter().map(move |e| {
// Append the extension.
let mut p = p.clone().into_os_string();
p.push(e);

PathBuf::from(p)
}))
Box::new(
bare_file
.into_iter()
.chain(PATH_EXTENSIONS.iter().map(move |e| {
// Append the extension.
let mut p = p.clone().into_os_string();
p.push(e);

PathBuf::from(p)
})),
)
}
})
}
Expand Down

0 comments on commit 60fd009

Please sign in to comment.