Merge pull request 'command parser file resolution' (#18) from theoddgarlic/ableos:master into master

Reviewed-on: https://git.ablecorp.us:443/able/ableos/pulls/18
This commit is contained in:
able 2022-08-01 09:58:16 +00:00
commit 40d52d2c91

View file

@ -168,63 +168,37 @@ pub fn command_parser(user: String, command: String) {
"quit" => shutdown(),
_ => {
let home_exec_path = format!("/home/{}/bins/{}.wasm", user, bin_name);
let shared_exec_path = format!("/shared/bins/{}.wasm", bin_name);
let system_exec_path = format!("/system/bins/{}.wasm", bin_name);
let home_exec_file = fs.open(&home_exec_path.as_bytes(), OpenOptions::new().read(true));
let shared_exec_file =
fs.open(&shared_exec_path.as_bytes(), OpenOptions::new().read(true));
let system_exec_file =
fs.open(&system_exec_path.as_bytes(), OpenOptions::new().read(true));
let mut in_home = false;
let mut in_shared = false;
let mut in_system = false;
let mut binary_prog: Vec<u8> = vec![];
match home_exec_file {
Ok(file) => {
let ret = file.read_to_end(&mut binary_prog).unwrap();
in_home = true;
let mut options = OpenOptions::new();
options.read(true);
let file = {
let path = format!("/home/{user}/bins/{bin_name}.wasm");
if let Ok(file ) = fs.open(&path.as_bytes(), &options) {
file
} else {
let path = format!("/shared/bins/{bin_name}.wasm");
if let Ok(file) = fs.open(&path.as_bytes(), &options) {
file
} else {
let path = format!("/system/bins/{bin_name}.wasm");
match fs.open(&path.as_bytes(), &options) {
Ok(file) => file,
Err(error) => {
trace!("{:?}", error);
println!("No such binary: {}", bin_name);
error!("No such binary: {}", bin_name);
return;
}
}
}
}
};
Err(error) => {
trace!("{:?}", error);
in_home = false;
}
}
match shared_exec_file {
Ok(file) => {
let ret = file.read_to_end(&mut binary_prog).unwrap();
in_shared = true;
}
Err(error) => {
trace!("{:?}", error);
in_shared = false;
}
}
match system_exec_file {
Ok(file) => {
let ret = file.read_to_end(&mut binary_prog).unwrap();
in_system = true;
}
Err(error) => {
trace!("{:?}", error);
in_system = false;
}
}
let mut binary = vec![];
file.read_to_end(&mut binary).unwrap();
let args = iter.collect::<Vec<&str>>();
println!("{:?}", args);
if in_home || in_shared || in_system {
run_program(&binary_prog);
} else {
println!("No such binary: {}", bin_name);
error!("No such binary: {}", bin_name);
}
run_program(&binary);
}
}
}