Commit abcea41b authored by dns2utf8's avatar dns2utf8 🦀
Browse files

Fixing search algo

parent c1465264
Pipeline #169693243 passed with stage
in 51 seconds
......@@ -70,13 +70,16 @@ fn parse_fs(fs: &str) -> FileSystems {
}
}
/// Parsing `/proc/mounts` to build `MountInfo`
/// Parsing `/proc/mounts` to build `MountInfo`.
///
/// Make sure the folder exists with `std::fs::create_dir_all(target_dir)?;`
pub fn detect<P: AsRef<Path>>(target_dir: P) -> std::io::Result<MountInfo> {
let target_dir = target_dir.as_ref();
// Make sure the folder exists
std::fs::create_dir_all(target_dir)?;
let target_dir = target_dir.canonicalize()?;
let target_dir = target_dir.components();
let target_dir = target_dir
.components()
.map(|c| Some(c))
.chain(std::iter::once(None));
let mounts = &std::fs::read("/proc/mounts")?;
let mounts = String::from_utf8_lossy(mounts);
......@@ -103,8 +106,16 @@ pub fn detect<P: AsRef<Path>>(target_dir: P) -> std::io::Result<MountInfo> {
let mut matching_parts = 0;
for (o, mp) in target_dir.clone().zip(mount_point.components()) {
if o == mp {
matching_parts += 1;
if let Some(o) = o {
if o == mp {
matching_parts += 1;
} else {
matching_parts = 0;
break;
}
} else {
matching_parts = 0;
break;
}
}
if (mount_point == root && longest_match <= 1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment