Feat: Fügt Funktionen zur Überprüfung von gemounteten Dateisystemen hinzu.
This commit is contained in:
89
src/filesystem/mod.rs
Normal file
89
src/filesystem/mod.rs
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
mod mount;
|
||||||
|
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
/// Überprüft, ob ein Dateisystem am angegebenen Mount-Point mit dem spezifizierten Mount-Typ eingebunden ist.
|
||||||
|
///
|
||||||
|
/// # Parameter
|
||||||
|
/// * `mount_point` - Der Pfad, an dem das Dateisystem eingebunden sein soll
|
||||||
|
/// * `mount_type` - Der erwartete Mount-Typ des Dateisystems (z.B. nfs, smb, davfs2)
|
||||||
|
///
|
||||||
|
/// # Rückgabewert
|
||||||
|
/// * `true` wenn das Dateisystem mit dem angegebenen Typ eingebunden ist
|
||||||
|
/// * `false` wenn das Dateisystem nicht oder mit einem anderen Typ eingebunden ist
|
||||||
|
pub fn is_mounted_as(mount_point: &str, mount_type: &str) -> bool {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
let drive_letter = &mount_point[0..1];
|
||||||
|
let output = Command::new("powershell")
|
||||||
|
.args([
|
||||||
|
"-Command",
|
||||||
|
&format!("(Get-PSDrive -Name {} -PSProvider 'FileSystem').Description", drive_letter)
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute get-psdrive command");
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let drive_type = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||||
|
drive_type == mount_type
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
{
|
||||||
|
let output = Command::new("mount")
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute mount command");
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mount_output = String::from_utf8_lossy(&output.stdout);
|
||||||
|
|
||||||
|
mount_output
|
||||||
|
.lines()
|
||||||
|
.any(|line| line.contains(mount_point) && line.contains(mount_type))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Überprüft, ob ein Dateisystem am angegebenen Mount-Point eingebunden ist.
|
||||||
|
///
|
||||||
|
/// # Parameter
|
||||||
|
/// * `mount_point` - Der Pfad, an dem das Dateisystem eingebunden sein soll
|
||||||
|
///
|
||||||
|
/// # Rückgabewert
|
||||||
|
/// * `true` wenn ein Dateisystem am angegebenen Pfad eingebunden ist
|
||||||
|
/// * `false` wenn kein Dateisystem eingebunden ist
|
||||||
|
pub fn is_mounted(mount_point: &str) -> bool {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
let drive_letter = &mount_point[0..1];
|
||||||
|
let output = Command::new("powershell")
|
||||||
|
.args([
|
||||||
|
"-Command",
|
||||||
|
&format!("(Get-PSDrive -Name {} -PSProvider 'FileSystem')", drive_letter)
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute get-psdrive command");
|
||||||
|
|
||||||
|
output.status.success()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
{
|
||||||
|
let output = Command::new("mount")
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute mount command");
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mount_output = String::from_utf8_lossy(&output.stdout);
|
||||||
|
|
||||||
|
mount_output.lines().any(|line| line.contains(mount_point))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user