alnyan/yggdrasil: implement binary resolution from PATH
This commit is contained in:
@@ -292,6 +292,8 @@ impl Command {
|
||||
.chain(self.args.iter().map(|arg| arg.as_str())),
|
||||
);
|
||||
|
||||
let program = &super::util::resolve_binary(program).unwrap_or_else(|| program.to_owned());
|
||||
|
||||
let envs = Vec::from_iter(self.env.iter().filter_map(|(key, value)| {
|
||||
if let Some(value) = value {
|
||||
let key = key.to_str().unwrap();
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use crate::env;
|
||||
use crate::mem::size_of;
|
||||
use crate::path::PathBuf;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct KStringList {
|
||||
@@ -43,3 +45,24 @@ impl KStringList {
|
||||
base + (/* array len */1 + /* pair */ 2 * index) * size_of::<usize>()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resolve_binary(name: &str) -> Option<String> {
|
||||
// Already an absolute path
|
||||
if name.starts_with('/') {
|
||||
return None;
|
||||
}
|
||||
|
||||
let Ok(path) = env::var("PATH") else {
|
||||
return None;
|
||||
};
|
||||
|
||||
for entry in path.split(':') {
|
||||
let full_path = PathBuf::from(entry).join(name);
|
||||
|
||||
if full_path.exists() {
|
||||
return Some(full_path.to_str().unwrap().to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user