alnyan/yggdrasil: implement binary resolution from PATH

This commit is contained in:
2023-11-14 14:54:35 +02:00
parent 3668bbdf3a
commit 957d3dec43
2 changed files with 25 additions and 0 deletions
+2
View File
@@ -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();
+23
View File
@@ -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
}