To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

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;
fn main() {
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 pool = threadpool::ThreadPool::new(2);
show_disk_status(&disks);
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();
match input.trim() {
"q" => return,
"h" => print_help(),
"l" => show_disk_status(&disks),
"w" => select_disk_to_whipe(&disks),
"w" => select_disk_to_wipe(&disks),
"" => show_disk_status(&disks),
com => println!("unknown command: {}", com),
}
......@@ -122,6 +122,8 @@ fn get_file_contents(path: &str) -> 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();
io::stdin().read_line(&mut input).unwrap_or(0);
input
......@@ -139,7 +141,7 @@ struct DiskInformation {
enum DiskState {
Detected,
Protected,
QueueForWhipe,
QueueForWipe,
Wiping{ progress: ByteUnit, per_second: ByteUnit },
Wiped{ took: Duration },
WipeFailed,
......@@ -151,8 +153,8 @@ impl Display for DiskState {
match self {
&Detected => write!(f, "Detected"),
&Protected => write!(f, "Protected"),
&QueueForWhipe => write!(f, "Queued for Whipe"),
&Wiping { ref progress, ref per_second } => write!(f, "Whiping {} ({}/s)", progress, per_second),
&QueueForWipe => write!(f, "Queued for Wipe"),
&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()),
&WipeFailed=> write!(f, "Wipe failed"),
}
......@@ -308,7 +310,7 @@ fn print_help() {
("q", "quit"),
("h", "print this help"),
("l", "list found disks and status"),
("w", "start whiping a disk"),
("w", "start wiping a disk"),
];
for option in options.iter() {
......@@ -316,14 +318,14 @@ fn print_help() {
}
}
fn select_disk_to_whipe(disks: &Vec<Arc<DiskInformation>>) {
println!("{}", HEADING.paint("Enter the id of the disk you would like to be whiped:"));
fn select_disk_to_wipe(disks: &Vec<Arc<DiskInformation>>) {
println!("{}", HEADING.paint("Enter the id of the disk you would like to be wiped:"));
match read_one_line_from_stdin().trim().parse() {
Ok(id) => {
if let Some(disk) = disks.iter().find(|ref e| e.id == id && *e.state.lock().unwrap() == Detected) {
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() {
"y" | "Y" | "j" | "J" => { false },
......@@ -333,7 +335,7 @@ fn select_disk_to_whipe(disks: &Vec<Arc<DiskInformation>>) {
} {}
*disk.state.lock().unwrap() = QueueForWhipe;
*disk.state.lock().unwrap() = QueueForWipe;
return;
}
......@@ -346,14 +348,14 @@ fn select_disk_to_whipe(disks: &Vec<Arc<DiskInformation>>) {
fn update_jobs(disks: &Vec<Arc<DiskInformation>>, pool: &threadpool::ThreadPool) {
for disk in disks {
if *disk.state.lock().unwrap() == QueueForWhipe {
println!("Queued {} for whipe", BOLD.paint(&*disk.name));
if *disk.state.lock().unwrap() == QueueForWipe {
println!("Queued {} for wipe", BOLD.paint(&*disk.name));
let disk = disk.clone();
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) => {
*disk.state.lock().unwrap() = Wiped{ took: duration };
println!("{}{} in {} seconds",
......@@ -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();
*disk.state.lock().unwrap() = Wiping{ progress: Byte(0), per_second: Byte(0) };
......
Markdown is supported
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