1
0
Fork 0
forked from AbleOS/ableos

command parser file resolution fix

This commit is contained in:
TheOddGarlic 2022-08-01 10:21:22 +03:00
parent b1de5148b7
commit eb2654fa93

View file

@ -160,63 +160,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![];
match home_exec_file {
Ok(file) => {
let ret = file.read_to_end(&mut binary_prog).unwrap();
in_home = true;
}
Err(error) => { Err(error) => {
trace!("{:?}", error); trace!("{:?}", error);
in_home = false; println!("No such binary: {}", bin_name);
error!("No such binary: {}", bin_name);
return;
} }
} }
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) => { let mut binary = vec![];
trace!("{:?}", error); file.read_to_end(&mut binary).unwrap();
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);
}
} }
} }
} }