From 3dba94d714c12f747f7ac15260bc57d4ab6fe14c Mon Sep 17 00:00:00 2001 From: amy Date: Sun, 23 Jan 2022 15:32:18 +0100 Subject: [PATCH] bugfixes --- src/functions/partition.rs | 54 +++++++++++++++++++++------------ src/internal/returncode_eval.rs | 8 ++--- src/internal/strings.rs | 2 +- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/functions/partition.rs b/src/functions/partition.rs index 2deb13b..adbe1b1 100755 --- a/src/functions/partition.rs +++ b/src/functions/partition.rs @@ -200,7 +200,7 @@ fn part_disk(device: &str, efi: bool) { format!("format {}1 as fat32", device).as_str(), ); exec_eval( - exec("mkfs.btrfs", vec![format!("{}2", device)]), + exec("mkfs.btrfs", vec!["-f".to_string(), format!("{}2", device)]), format!("format {}2 as btrfs", device).as_str(), ); mount(format!("{}2", device).as_str(), "/mnt", ""); @@ -244,7 +244,7 @@ fn part_disk(device: &str, efi: bool) { format!("format {}1 as ext4", device).as_str(), ); exec_eval( - exec("mkfs.btrfs", vec![format!("{}2", device)]), + exec("mkfs.btrfs", vec!["-f".to_string(), format!("{}2", device)]), format!("format {}2 as btrfs", device).as_str(), ); mount(format!("{}2", device).as_str(), "/mnt/", ""); @@ -288,23 +288,39 @@ fn part_disk(device: &str, efi: bool) { } fn mount(partition: &str, mountpoint: &str, options: &str) { - let options = if options.is_empty() { "\"\"" } else { options }; - exec_eval( - exec( - "mount", - vec![ - String::from(partition), - String::from(mountpoint), - String::from("-o"), - String::from(options), - ], - ), - format!( - "mount {} with options {} at {}", - partition, options, mountpoint - ) - .as_str(), - ); + if !options.is_empty() { + exec_eval( + exec( + "mount", + vec![ + String::from(partition), + String::from(mountpoint), + String::from("-o"), + String::from(options), + ], + ), + format!( + "mount {} with options {} at {}", + partition, options, mountpoint + ) + .as_str(), + ); + } else { + exec_eval( + exec( + "mount", + vec![ + String::from(partition), + String::from(mountpoint), + ], + ), + format!( + "mount {} with no options at {}", + partition, mountpoint + ) + .as_str(), + ); + } } fn umount(mountpoint: &str) { diff --git a/src/internal/returncode_eval.rs b/src/internal/returncode_eval.rs index 827bc2e..01e8812 100755 --- a/src/internal/returncode_eval.rs +++ b/src/internal/returncode_eval.rs @@ -2,15 +2,15 @@ use crate::internal::*; pub fn exec_eval( return_code: std::result::Result, - logmsg: &str, + logmsg: &str ) { match &return_code { Ok(_) => { - log(format!("{}: Success", logmsg)); + log(format!("[ \x1b[2;1;32mOK\x1b[0m ] {}", logmsg)); } Err(e) => { crash( - format!("{}: Failed with error: {}", logmsg, e), + format!("{} ERROR: {}", logmsg, e), return_code.unwrap_err().raw_os_error().unwrap(), ); } @@ -24,7 +24,7 @@ pub fn files_eval(return_code: std::result::Result<(), std::io::Error>, logmsg: } Err(e) => { crash( - format!("[ \x1b[2;1;31mFAILED\x1b[0m ] {} ERROR: {}", logmsg, e), + format!("{} ERROR: {}", logmsg, e), return_code.unwrap_err().raw_os_error().unwrap(), ); } diff --git a/src/internal/strings.rs b/src/internal/strings.rs index a276eb8..3dc4317 100755 --- a/src/internal/strings.rs +++ b/src/internal/strings.rs @@ -10,7 +10,7 @@ pub fn crash(a: String, b: i32) { } else { a }; - println!("\x1b[2;22;31m❌:\x1b[0m \x1b[1;91m{}\x1b[0m", a); + println!("[ \x1b[2;1;32mOK\x1b[0m ] {}", a); exit(b); } pub fn log(a: String) {