From a9dd3b4eda1237700f86e7389ab662899d3f9ca7 Mon Sep 17 00:00:00 2001 From: DragonSlayer_14 Date: Wed, 20 Aug 2025 23:31:36 +0200 Subject: [PATCH] =?UTF-8?q?Feat:=20Implementiert=20Funktionen=20zum=20Ein-?= =?UTF-8?q?=20und=20Aush=C3=A4ngen=20von=20Dateisystemen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/filesystem/mount.rs | 86 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/filesystem/mount.rs diff --git a/src/filesystem/mount.rs b/src/filesystem/mount.rs new file mode 100644 index 0000000..29b350e --- /dev/null +++ b/src/filesystem/mount.rs @@ -0,0 +1,86 @@ +use crate::log::{log, LogLevel}; +use std::process::Command; + +/// Führt die Einbindung eines Dateisystems durch. +/// +/// # Parameter +/// * `mount_point` - Der lokale Verzeichnispfad, an dem das Dateisystem eingebunden werden soll +/// * `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) { + #[cfg(target_os = "windows")] + { + let output = Command::new("New-PSDrive") + .args([ + "-Name", + &mount_point[0..1], // First letter for drive letter + "-PSProvider", + "FileSystem", + "-Root", + network_path, + "-Persist", + "-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); + } + } + + #[cfg(not(target_os = "windows"))] + { + let output = Command::new("mount") + .arg("-p") + .arg(mount_point) + .arg("-t") + .arg(mount_type) + .arg(network_path) + .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); + } + } +} + +/// Hängt ein Dateisystem aus. +/// +/// # Parameter +/// * `mount_point` - Der lokale Verzeichnispfad, von dem das Dateisystem ausgehängt werden soll +pub fn unmount(mount_point: &str) { + #[cfg(target_os = "windows")] + { + let output = Command::new("Remove-PSDrive") + .args([ + "-Name", + &mount_point[0..1], // First letter for drive letter + "-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); + } + } + + #[cfg(not(target_os = "windows"))] + { + let output = Command::new("umount") + .arg(mount_point) + .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); + } + } +}