1
0
Fork 0
forked from koniifer/ableos

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