Add move command

This commit is contained in:
Vincent Ollivier 2019-12-30 22:48:43 +01:00
parent 27e6314db4
commit 1877ce471f
3 changed files with 27 additions and 1 deletions

View File

@ -1,5 +1,6 @@
pub mod date;
pub mod read;
pub mod r#move;
pub mod shell;
pub mod uptime;
pub mod write;

25
src/user/move.rs Normal file
View File

@ -0,0 +1,25 @@
use crate::print;
use crate::kernel::fs;
pub fn main(args: &[&str]) {
if args.len() != 3 {
return;
}
let from = args[1];
let to = args[2];
if to.starts_with("/dev") || to.starts_with("/sys") {
print!("Permission denied to write to '{}'\n", to);
} else {
if let Some(file_from) = fs::File::open(from) {
if let Some(mut file_to) = fs::File::create(to) {
file_to.write(&file_from.read());
} else {
print!("Permission denied to write to '{}'\n", to);
}
} else {
print!("File not found '{}'\n", from);
}
}
}

View File

@ -59,7 +59,7 @@ pub fn key_handle(key: DecodedKey) {
"j" | "jd" | "jump" | "jump-dir" => print!("TODO\n"),
"k" | "kill" => print!("TODO\n"),
"l" | "list" | "ls" => print!("TODO\n"), // same as `rd`
"m" | "move" | "mv" => print!("TODO\n"),
"m" | "move" | "mv" => user::r#move::main(&args),
"n" => print!("?\n"),
"o" => print!("?\n"),
"p" | "print" => print!("TODO\n"),