From 3b0bf61ec36e3c7b8e09f1e316c5dad81a152d1e Mon Sep 17 00:00:00 2001 From: jzitnik-dev Date: Sun, 29 Jun 2025 10:14:57 +0200 Subject: [PATCH 1/2] feat: Create mount location directory before mount --- src/main.rs | 1 + src/utils/mounting.rs | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 22db6f3..b5428b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,4 +84,5 @@ async fn main() { // Main mainCommand(loaded_prefs); + } diff --git a/src/utils/mounting.rs b/src/utils/mounting.rs index 48894a2..70869a4 100644 --- a/src/utils/mounting.rs +++ b/src/utils/mounting.rs @@ -109,8 +109,36 @@ pub fn mount(mount_point: &MountPoint, preferences: &Preferences) { let flags1 = flag_merge(&default_flags, &global_flags, &merge_ignore); let flags2 = flag_merge(&flags1, &mount_point_flags, &merge_ignore); - let mut command = Command::new("sudo"); - command.arg("-S").arg("mount"); + // Create the mountpoint folder if doesn't exist + let mut mkdir = Command::new(if sudo { "sudo" } else { "mkdir" }); + if sudo { + mkdir.arg("-S").arg("mkdir"); + } + mkdir.arg("-p").arg(&mount_point.mount_location); + let mut mkdir_child = mkdir.spawn().expect("Failed to spawn mount command"); + if sudo { + if let Some(password) = &user_password { + if let Some(stdin) = mkdir_child.stdin.as_mut() { + stdin + .write_all(format!("{}\n", password).as_bytes()) + .expect("Failed to write to stdin"); + } + } + } + let mkdir_output = mkdir_child.wait_with_output().expect("Failed to execute command"); + if !mkdir_output.status.success() { + console_error( + &preferences.config, + format!("Mkdir failed with status code: {}", mkdir_output.status).as_str(), + ); + eprintln!("Stderr: {}", String::from_utf8_lossy(&mkdir_output.stderr)); + exit(1); + } + + let mut command = Command::new(if sudo { "sudo" } else { "mount" }); + if sudo { + command.arg("-S").arg("mount"); + } add_flags(&mut command, flags2); From 4eff646269d137447fceaa7d1da4f743f5603abb Mon Sep 17 00:00:00 2001 From: jzitnik-dev Date: Thu, 11 Sep 2025 10:51:03 +0200 Subject: [PATCH 2/2] fix: Some basic fixes --- src/utils/luks.rs | 8 +++++++- src/utils/mounting.rs | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils/luks.rs b/src/utils/luks.rs index b5799de..e6158c7 100644 --- a/src/utils/luks.rs +++ b/src/utils/luks.rs @@ -36,13 +36,17 @@ pub fn check_luks(mount_address: &String, user_password: &Option, pref: cmd }; - let mut child = command.spawn().expect("Failed to spawn cryptsetup command"); + let mut child = match command.spawn() { + Ok(child) => child, + Err(_) => return false, // Return false if spawn fails + }; if let Some(password) = user_password { if let Some(stdin) = child.stdin.as_mut() { stdin .write_all(format!("{}\n", password).as_bytes()) .expect("Failed to write sudo password to stdin"); + stdin.flush().expect("Failed to flush stdin"); } } @@ -96,6 +100,7 @@ pub fn lock(user_password: &Option, address: &String, config: &HashMap, address: &String, config: &HashMap