Commit 4970ef6b authored by Stefan Schindler's avatar Stefan Schindler
Browse files

cleanup rename

parent 1a641e5b
...@@ -26,21 +26,21 @@ const WRITE_BUFFER_SIZE: usize = 4 * 1024; ...@@ -26,21 +26,21 @@ const WRITE_BUFFER_SIZE: usize = 4 * 1024;
fn main() { fn main() {
let model = get_file_contents("/sys/devices/virtual/dmi/id/product_version"); let model = get_file_contents("/sys/devices/virtual/dmi/id/product_version");
println!("\n\n {} running on {}\n", BOLD.paint("whipe buddy"), BOLD.paint(model)); println!("\n\n {} running on {}\n", BOLD.paint("wipe buddy"), BOLD.paint(model));
let disks = parse_disks(); let disks = parse_disks();
let pool = threadpool::ThreadPool::new(2); let pool = threadpool::ThreadPool::new(2);
show_disk_status(&disks); show_disk_status(&disks);
loop { loop {
println!("\nPress {} to exit, {} for a list of available commands", BOLD.paint("q"), BOLD.paint("h")); println!("\nPress {} to exit, {} for a list of available commands:", BOLD.paint("q"), BOLD.paint("h"));
let input = read_one_line_from_stdin(); let input = read_one_line_from_stdin();
match input.trim() { match input.trim() {
"q" => return, "q" => return,
"h" => print_help(), "h" => print_help(),
"l" => show_disk_status(&disks), "l" => show_disk_status(&disks),
"w" => select_disk_to_whipe(&disks), "w" => select_disk_to_wipe(&disks),
"" => show_disk_status(&disks), "" => show_disk_status(&disks),
com => println!("unknown command: {}", com), com => println!("unknown command: {}", com),
} }
...@@ -122,6 +122,8 @@ fn get_file_contents(path: &str) -> String { ...@@ -122,6 +122,8 @@ fn get_file_contents(path: &str) -> String {
} }
fn read_one_line_from_stdin() -> String { fn read_one_line_from_stdin() -> String {
print!("> ");
io::stdout().flush().expect("Unable to flush stdout inside fn read_one_line_from_stdin()");
let mut input = String::new(); let mut input = String::new();
io::stdin().read_line(&mut input).unwrap_or(0); io::stdin().read_line(&mut input).unwrap_or(0);
input input
...@@ -139,7 +141,7 @@ struct DiskInformation { ...@@ -139,7 +141,7 @@ struct DiskInformation {
enum DiskState { enum DiskState {
Detected, Detected,
Protected, Protected,
QueueForWhipe, QueueForWipe,
Wiping{ progress: ByteUnit, per_second: ByteUnit }, Wiping{ progress: ByteUnit, per_second: ByteUnit },
Wiped{ took: Duration }, Wiped{ took: Duration },
WipeFailed, WipeFailed,
...@@ -151,8 +153,8 @@ impl Display for DiskState { ...@@ -151,8 +153,8 @@ impl Display for DiskState {
match self { match self {
&Detected => write!(f, "Detected"), &Detected => write!(f, "Detected"),
&Protected => write!(f, "Protected"), &Protected => write!(f, "Protected"),
&QueueForWhipe => write!(f, "Queued for Whipe"), &QueueForWipe => write!(f, "Queued for Wipe"),
&Wiping { ref progress, ref per_second } => write!(f, "Whiping {} ({}/s)", progress, per_second), &Wiping { ref progress, ref per_second } => write!(f, "Wiping {} ({}/s)", progress, per_second),
&Wiped { ref took } => write!(f, "Wiped successfully in {} seconds", took.as_secs()), &Wiped { ref took } => write!(f, "Wiped successfully in {} seconds", took.as_secs()),
&WipeFailed=> write!(f, "Wipe failed"), &WipeFailed=> write!(f, "Wipe failed"),
} }
...@@ -308,7 +310,7 @@ fn print_help() { ...@@ -308,7 +310,7 @@ fn print_help() {
("q", "quit"), ("q", "quit"),
("h", "print this help"), ("h", "print this help"),
("l", "list found disks and status"), ("l", "list found disks and status"),
("w", "start whiping a disk"), ("w", "start wiping a disk"),
]; ];
for option in options.iter() { for option in options.iter() {
...@@ -316,14 +318,14 @@ fn print_help() { ...@@ -316,14 +318,14 @@ fn print_help() {
} }
} }
fn select_disk_to_whipe(disks: &Vec<Arc<DiskInformation>>) { fn select_disk_to_wipe(disks: &Vec<Arc<DiskInformation>>) {
println!("{}", HEADING.paint("Enter the id of the disk you would like to be whiped:")); println!("{}", HEADING.paint("Enter the id of the disk you would like to be wiped:"));
match read_one_line_from_stdin().trim().parse() { match read_one_line_from_stdin().trim().parse() {
Ok(id) => { Ok(id) => {
if let Some(disk) = disks.iter().find(|ref e| e.id == id && *e.state.lock().unwrap() == Detected) { if let Some(disk) = disks.iter().find(|ref e| e.id == id && *e.state.lock().unwrap() == Detected) {
while { while {
println!("\nWhiping is {}!\nDestroy any data on {} ({})\nEnter {} to continue or {} to abort?", UNDERLINE.paint("non-reversable"), BOLD.paint(&*disk.name), disk.size, BOLD.paint("y"), BOLD.paint("a")); println!("\nWiping is {}!\nDestroy any data on {} ({})\nEnter {} to continue or {} to abort?", UNDERLINE.paint("non-reversable"), BOLD.paint(&*disk.name), disk.size, BOLD.paint("y"), BOLD.paint("a"));
match read_one_line_from_stdin().trim() { match read_one_line_from_stdin().trim() {
"y" | "Y" | "j" | "J" => { false }, "y" | "Y" | "j" | "J" => { false },
...@@ -333,7 +335,7 @@ fn select_disk_to_whipe(disks: &Vec<Arc<DiskInformation>>) { ...@@ -333,7 +335,7 @@ fn select_disk_to_whipe(disks: &Vec<Arc<DiskInformation>>) {
} {} } {}
*disk.state.lock().unwrap() = QueueForWhipe; *disk.state.lock().unwrap() = QueueForWipe;
return; return;
} }
...@@ -346,14 +348,14 @@ fn select_disk_to_whipe(disks: &Vec<Arc<DiskInformation>>) { ...@@ -346,14 +348,14 @@ fn select_disk_to_whipe(disks: &Vec<Arc<DiskInformation>>) {
fn update_jobs(disks: &Vec<Arc<DiskInformation>>, pool: &threadpool::ThreadPool) { fn update_jobs(disks: &Vec<Arc<DiskInformation>>, pool: &threadpool::ThreadPool) {
for disk in disks { for disk in disks {
if *disk.state.lock().unwrap() == QueueForWhipe { if *disk.state.lock().unwrap() == QueueForWipe {
println!("Queued {} for whipe", BOLD.paint(&*disk.name)); println!("Queued {} for wipe", BOLD.paint(&*disk.name));
let disk = disk.clone(); let disk = disk.clone();
pool.execute(move || { pool.execute(move || {
println!("{}{}", Blue.paint("Wiping "), BOLD.paint(&*disk.name)); println!("{}{}", Green.paint("Wiping "), BOLD.paint(&*disk.name));
match whipe_disk(&disk) { match wipe_disk(&disk) {
Ok(duration) => { Ok(duration) => {
*disk.state.lock().unwrap() = Wiped{ took: duration }; *disk.state.lock().unwrap() = Wiped{ took: duration };
println!("{}{} in {} seconds", println!("{}{} in {} seconds",
...@@ -378,7 +380,7 @@ fn update_jobs(disks: &Vec<Arc<DiskInformation>>, pool: &threadpool::ThreadPool) ...@@ -378,7 +380,7 @@ fn update_jobs(disks: &Vec<Arc<DiskInformation>>, pool: &threadpool::ThreadPool)
} }
} }
fn whipe_disk(disk: &Arc<DiskInformation>) -> std::io::Result<std::time::Duration> { fn wipe_disk(disk: &Arc<DiskInformation>) -> std::io::Result<std::time::Duration> {
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
*disk.state.lock().unwrap() = Wiping{ progress: Byte(0), per_second: Byte(0) }; *disk.state.lock().unwrap() = Wiping{ progress: Byte(0), per_second: Byte(0) };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment