Feat: Implementiert Funktionen zum Ein- und Aushängen von Dateisystemen.
This commit is contained in:
86
src/filesystem/mount.rs
Normal file
86
src/filesystem/mount.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user