mirror of
https://github.com/openharmony/third_party_rust_which-rs.git
synced 2026-07-01 21:14:07 -04:00
windows: Also search for file without added extension (#57)
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.
This commit is contained in:
+16
-10
@@ -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);
|
||||
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)
|
||||
}))
|
||||
PathBuf::from(p)
|
||||
})),
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user