command parser file resolution fix
This commit is contained in:
parent
b1de5148b7
commit
eb2654fa93
|
@ -160,63 +160,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);
|
||||
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) => {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue