From 176dc27f526004a34e4abf71b52e20e7a68a28a6 Mon Sep 17 00:00:00 2001 From: DragonSlayer_14 Date: Thu, 21 Aug 2025 12:49:31 +0200 Subject: [PATCH] =?UTF-8?q?Ref:=20=C3=9Cberarbeitet=20`mount`-=20und=20`un?= =?UTF-8?q?mount`-Implementierung,=20f=C3=BCgt=20detaillierteres=20Logging?= =?UTF-8?q?=20hinzu=20und=20verbessert=20Fehlerbehandlung.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/filesystem/mount.rs | 114 +++++++++++++++++++++++++++++++++++----- 1 file changed, 102 insertions(+), 12 deletions(-) diff --git a/src/filesystem/mount.rs b/src/filesystem/mount.rs index 29b350e..2248bd6 100644 --- a/src/filesystem/mount.rs +++ b/src/filesystem/mount.rs @@ -8,6 +8,15 @@ use std::process::Command; /// * `network_path` - Der Netzwerkpfad zum einzubindenden Dateisystem /// * `mount_type` - Der Mount-Typ, z.B. "nfs" oder "davfs2" pub fn mount(mount_point: &str, network_path: &str, mount_type: &str) { + log( + "mount", + &*format!( + "Mounting filesystem ({}) at \"{}\" as \"{}\"", + network_path, mount_point, mount_type + ), + LogLevel::Info, + ); + #[cfg(target_os = "windows")] { let output = Command::new("New-PSDrive") @@ -20,31 +29,96 @@ pub fn mount(mount_point: &str, network_path: &str, mount_type: &str) { network_path, "-Persist", "-Type", - mount_type + mount_type, ]) .output() .expect("Failed to execute mount command"); if !output.status.success() { - log("mount", &*format!("Filesystem ({}) couldn't be mounted at \"{}\" as \"{}\"", network_path, mount_point, mount_type), LogLevel::Error); - log("mount", &*String::from_utf8_lossy(&output.stderr), LogLevel::Debug); + log( + "mount", + &*format!( + "Filesystem ({}) couldn't be mounted at \"{}\" as \"{}\"", + network_path, mount_point, mount_type + ), + LogLevel::Error, + ); + log( + "mount", + &*String::from_utf8_lossy(&output.stderr), + LogLevel::Debug, + ); } } #[cfg(not(target_os = "windows"))] { - let output = Command::new("mount") + let mount_point: &str = if mount_point.ends_with('/') { + mount_point + } else { + &*format!("{}/", mount_point) + }; + + let output = Command::new("mkdir") .arg("-p") .arg(mount_point) + .output() + .expect("Failed to create mount point directory"); + + if output.status.success() { + log("mount", "Mountpoint created successfully!", LogLevel::Info); + } else { + log( + "mount", + &*String::from_utf8_lossy(&output.stderr), + LogLevel::Debug, + ); + } + + let output = Command::new("chmod") + .arg("777") + .arg(mount_point) + .output() + .expect("Failed to set mount point permissions"); + + if output.status.success() { + log( + "mount", + "Successfully set mount point permissions.", + LogLevel::Info, + ); + } else { + log( + "mount", + &*String::from_utf8_lossy(&output.stderr), + LogLevel::Debug, + ); + } + + let output = Command::new("mount") .arg("-t") .arg(mount_type) .arg(network_path) + .arg(mount_point) .output() .expect("Failed to execute mount command"); - if !output.status.success() { - log("mount", &*format!("Filesystem ({}) couldn't be mounted at \"{}\" as \"{}\"", network_path, mount_point, mount_type), LogLevel::Error); - log("mount", &*String::from_utf8_lossy(&output.stderr), LogLevel::Debug); + if output.status.success() { + log("mount", "Filesystem mounted successfully.", LogLevel::Info); + } else { + log( + "mount", + &*format!( + "Filesystem ({}) couldn't be mounted at \"{}\" as \"{}\"", + network_path, mount_point, mount_type + ), + LogLevel::Error, + ); + log( + "mount", + &*String::from_utf8_lossy(&output.stderr), + LogLevel::Debug, + ); } } } @@ -60,14 +134,22 @@ pub fn unmount(mount_point: &str) { .args([ "-Name", &mount_point[0..1], // First letter for drive letter - "-Force" + "-Force", ]) .output() .expect("Failed to execute unmount command"); if !output.status.success() { - log("unmount", &*format!("Filesystem couldn't be unmounted from \"{}\"", mount_point), LogLevel::Error); - log("unmount", &*String::from_utf8_lossy(&output.stderr), LogLevel::Debug); + log( + "unmount", + &*format!("Filesystem couldn't be unmounted from \"{}\"", mount_point), + LogLevel::Error, + ); + log( + "unmount", + &*String::from_utf8_lossy(&output.stderr), + LogLevel::Debug, + ); } } @@ -79,8 +161,16 @@ pub fn unmount(mount_point: &str) { .expect("Failed to execute unmount command"); if !output.status.success() { - log("unmount", &*format!("Filesystem couldn't be unmounted from \"{}\"", mount_point), LogLevel::Error); - log("unmount", &*String::from_utf8_lossy(&output.stderr), LogLevel::Debug); + log( + "unmount", + &*format!("Filesystem couldn't be unmounted from \"{}\"", mount_point), + LogLevel::Error, + ); + log( + "unmount", + &*String::from_utf8_lossy(&output.stderr), + LogLevel::Debug, + ); } } }