axtloss/rework-partitioning
amy 3 years ago
parent 09573dd0b1
commit 3dba94d714

@ -200,7 +200,7 @@ fn part_disk(device: &str, efi: bool) {
format!("format {}1 as fat32", device).as_str(), format!("format {}1 as fat32", device).as_str(),
); );
exec_eval( 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(), format!("format {}2 as btrfs", device).as_str(),
); );
mount(format!("{}2", device).as_str(), "/mnt", ""); 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(), format!("format {}1 as ext4", device).as_str(),
); );
exec_eval( 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(), format!("format {}2 as btrfs", device).as_str(),
); );
mount(format!("{}2", device).as_str(), "/mnt/", ""); 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) { fn mount(partition: &str, mountpoint: &str, options: &str) {
let options = if options.is_empty() { "\"\"" } else { options }; if !options.is_empty() {
exec_eval( exec_eval(
exec( exec(
"mount", "mount",
vec![ vec![
String::from(partition), String::from(partition),
String::from(mountpoint), String::from(mountpoint),
String::from("-o"), String::from("-o"),
String::from(options), String::from(options),
], ],
), ),
format!( format!(
"mount {} with options {} at {}", "mount {} with options {} at {}",
partition, options, mountpoint partition, options, mountpoint
) )
.as_str(), .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) { fn umount(mountpoint: &str) {

@ -2,15 +2,15 @@ use crate::internal::*;
pub fn exec_eval( pub fn exec_eval(
return_code: std::result::Result<std::process::ExitStatus, std::io::Error>, return_code: std::result::Result<std::process::ExitStatus, std::io::Error>,
logmsg: &str, logmsg: &str
) { ) {
match &return_code { match &return_code {
Ok(_) => { Ok(_) => {
log(format!("{}: Success", logmsg)); log(format!("[ \x1b[2;1;32mOK\x1b[0m ] {}", logmsg));
} }
Err(e) => { Err(e) => {
crash( crash(
format!("{}: Failed with error: {}", logmsg, e), format!("{} ERROR: {}", logmsg, e),
return_code.unwrap_err().raw_os_error().unwrap(), 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) => { Err(e) => {
crash( crash(
format!("[ \x1b[2;1;31mFAILED\x1b[0m ] {} ERROR: {}", logmsg, e), format!("{} ERROR: {}", logmsg, e),
return_code.unwrap_err().raw_os_error().unwrap(), return_code.unwrap_err().raw_os_error().unwrap(),
); );
} }

@ -10,7 +10,7 @@ pub fn crash(a: String, b: i32) {
} else { } else {
a a
}; };
println!("\x1b[2;22;31m❌:\x1b[0m \x1b[1;91m{}\x1b[0m", a); println!("[ \x1b[2;1;32mOK\x1b[0m ] {}", a);
exit(b); exit(b);
} }
pub fn log(a: String) { pub fn log(a: String) {

Loading…
Cancel
Save