Ref: Überarbeitet mount- und unmount-Implementierung, fügt detaillierteres Logging hinzu und verbessert Fehlerbehandlung.
This commit is contained in:
@@ -8,6 +8,15 @@ use std::process::Command;
|
|||||||
/// * `network_path` - Der Netzwerkpfad zum einzubindenden Dateisystem
|
/// * `network_path` - Der Netzwerkpfad zum einzubindenden Dateisystem
|
||||||
/// * `mount_type` - Der Mount-Typ, z.B. "nfs" oder "davfs2"
|
/// * `mount_type` - Der Mount-Typ, z.B. "nfs" oder "davfs2"
|
||||||
pub fn mount(mount_point: &str, network_path: &str, mount_type: &str) {
|
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")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
let output = Command::new("New-PSDrive")
|
let output = Command::new("New-PSDrive")
|
||||||
@@ -20,31 +29,96 @@ pub fn mount(mount_point: &str, network_path: &str, mount_type: &str) {
|
|||||||
network_path,
|
network_path,
|
||||||
"-Persist",
|
"-Persist",
|
||||||
"-Type",
|
"-Type",
|
||||||
mount_type
|
mount_type,
|
||||||
])
|
])
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to execute mount command");
|
.expect("Failed to execute mount command");
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
log("mount", &*format!("Filesystem ({}) couldn't be mounted at \"{}\" as \"{}\"", network_path, mount_point, mount_type), LogLevel::Error);
|
log(
|
||||||
log("mount", &*String::from_utf8_lossy(&output.stderr), LogLevel::Debug);
|
"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"))]
|
#[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("-p")
|
||||||
.arg(mount_point)
|
.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("-t")
|
||||||
.arg(mount_type)
|
.arg(mount_type)
|
||||||
.arg(network_path)
|
.arg(network_path)
|
||||||
|
.arg(mount_point)
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to execute mount command");
|
.expect("Failed to execute mount command");
|
||||||
|
|
||||||
if !output.status.success() {
|
if output.status.success() {
|
||||||
log("mount", &*format!("Filesystem ({}) couldn't be mounted at \"{}\" as \"{}\"", network_path, mount_point, mount_type), LogLevel::Error);
|
log("mount", "Filesystem mounted successfully.", LogLevel::Info);
|
||||||
log("mount", &*String::from_utf8_lossy(&output.stderr), LogLevel::Debug);
|
} 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([
|
.args([
|
||||||
"-Name",
|
"-Name",
|
||||||
&mount_point[0..1], // First letter for drive letter
|
&mount_point[0..1], // First letter for drive letter
|
||||||
"-Force"
|
"-Force",
|
||||||
])
|
])
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to execute unmount command");
|
.expect("Failed to execute unmount command");
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
log("unmount", &*format!("Filesystem couldn't be unmounted from \"{}\"", mount_point), LogLevel::Error);
|
log(
|
||||||
log("unmount", &*String::from_utf8_lossy(&output.stderr), LogLevel::Debug);
|
"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");
|
.expect("Failed to execute unmount command");
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
log("unmount", &*format!("Filesystem couldn't be unmounted from \"{}\"", mount_point), LogLevel::Error);
|
log(
|
||||||
log("unmount", &*String::from_utf8_lossy(&output.stderr), LogLevel::Debug);
|
"unmount",
|
||||||
|
&*format!("Filesystem couldn't be unmounted from \"{}\"", mount_point),
|
||||||
|
LogLevel::Error,
|
||||||
|
);
|
||||||
|
log(
|
||||||
|
"unmount",
|
||||||
|
&*String::from_utf8_lossy(&output.stderr),
|
||||||
|
LogLevel::Debug,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user