Ref: Überarbeitet mount- und unmount-Implementierung, fügt detaillierteres Logging hinzu und verbessert Fehlerbehandlung.

This commit is contained in:
2025-08-21 12:49:31 +02:00
parent 663307be63
commit 176dc27f52

View File

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