Feat: Implementiert Funktionen zum Ein- und Aushängen von Dateisystemen.

This commit is contained in:
2025-08-20 23:31:36 +02:00
parent 32874990ea
commit a9dd3b4eda

86
src/filesystem/mount.rs Normal file
View File

@@ -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);
}
}
}