From 0299d2814fad96101feca7f00d66b4a1b4ed1de5 Mon Sep 17 00:00:00 2001 From: Bruce Leidl Date: Tue, 29 Jan 2019 11:56:56 -0500 Subject: [PATCH] function added to also find mounts by target path --- libcitadel/src/mount.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libcitadel/src/mount.rs b/libcitadel/src/mount.rs index 8122d50..46b6642 100644 --- a/libcitadel/src/mount.rs +++ b/libcitadel/src/mount.rs @@ -15,12 +15,17 @@ impl Mount { /// Returns `true` if `path` matches the source field (first field) /// of any of the mount lines listed in /proc/mounts /// - pub fn is_path_mounted>(path: P) -> Result { + pub fn is_source_mounted>(path: P) -> Result { let path_str = path.as_ref().to_string_lossy(); let mounts = Mount::all_mounts()?; Ok(mounts.into_iter().any(|m| m.source == path_str)) } + pub fn is_target_mounted>(path: P) -> Result { + let mounts = Mount::all_mounts()?; + Ok(mounts.into_iter().any(|m| m.target == path.as_ref())) + } + pub fn all_mounts() -> Result> { let s = fs::read_to_string("/proc/mounts")?; Ok(s.lines().flat_map(Mount::parse_mount_line).collect())