diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-03-17 15:59:31 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-03-17 15:59:31 +0100 |
commit | 653d4c4a9f6acf69da8be34c49a30a388d15f835 (patch) | |
tree | 947dba673e29ee3a583d29524a2f093bd9c7de98 | |
parent | f9c73b520782a8fd058156136229aff20740e84b (diff) |
don't drop the mounts
-rw-r--r-- | src/main.rs | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/src/main.rs b/src/main.rs index cd1bd29..120ab14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use std::io::Write; use std::process::{self, Command, ExitCode}; use std::thread; use std::time::Duration; -use sys_mount::{Mount, Unmount, UnmountFlags}; +use sys_mount::{Mount, Unmount, UnmountDrop, UnmountFlags}; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; fn start() -> anyhow::Result<()> { @@ -45,7 +45,7 @@ fn start() -> anyhow::Result<()> { Ok(()) } -fn mount_or_halt(part_id: u8, mount_point: &str, fs: &str) { +fn mount_or_halt(part_id: u8, mount_point: &str, fs: &str) -> UnmountDrop<Mount> { let mut stdout = StandardStream::stdout(ColorChoice::Always); let mut mount = None; @@ -69,50 +69,54 @@ fn mount_or_halt(part_id: u8, mount_point: &str, fs: &str) { }; } - if mount.is_none() { - if let Some(e) = mount_err { - match stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red))) { - Ok(_) => { - match writeln!(&mut stdout, "[ ERROR ] Can't mount {}: {}", mount_point, e) { - Ok(_) => {} - Err(_) => println!("[ ERROR ] Can't mount {}: {}", mount_point, e), + match mount { + None => { + if let Some(e) = mount_err { + match stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red))) { + Ok(_) => { + match writeln!(&mut stdout, "[ ERROR ] Can't mount {}: {}", mount_point, e) + { + Ok(_) => {} + Err(_) => println!("[ ERROR ] Can't mount {}: {}", mount_point, e), + } } + Err(_) => println!("[ ERROR ] Can't mount {}: {}", mount_point, e), } - Err(_) => println!("[ ERROR ] Can't mount {}: {}", mount_point, e), - } - } else { - match stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red))) { - Ok(_) => match writeln!( - &mut stdout, - "[ ERROR ] Can't mount {}: Unknown error (this shouldn't happen)", - mount_point - ) { - Ok(_) => {} - Err(_) => println!( + } else { + match stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red))) { + Ok(_) => match writeln!( + &mut stdout, "[ ERROR ] Can't mount {}: Unknown error (this shouldn't happen)", mount_point - ), - }, - Err(_) => { - println!( - "[ ERROR ] Can't mount {}: Unknown error (this shouldn't happen)", - mount_point - ) + ) { + Ok(_) => {} + Err(_) => println!( + "[ ERROR ] Can't mount {}: Unknown error (this shouldn't happen)", + mount_point + ), + }, + Err(_) => { + println!( + "[ ERROR ] Can't mount {}: Unknown error (this shouldn't happen)", + mount_point + ) + } } } - } - loop { - thread::sleep(Duration::MAX); + loop { + thread::sleep(Duration::MAX); + } } + Some(handle) => handle, } } fn main() -> ExitCode { let mut stdout = StandardStream::stdout(ColorChoice::Always); - mount_or_halt(1, "/boot", "vfat"); - mount_or_halt(4, "/data", "ext4"); + let _ = mount_or_halt(1, "/boot", "vfat"); + let _ = mount_or_halt(4, "/data", "ext4"); if process::id() != 1 { match stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red))) { |