mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
parent
a66527e3e2
commit
9b9d369298
1 changed files with 20 additions and 2 deletions
|
@ -67,8 +67,17 @@ where
|
||||||
} else {
|
} else {
|
||||||
path.as_ref().to_path_buf()
|
path.as_ref().to_path_buf()
|
||||||
};
|
};
|
||||||
let matches = mounts.iter().filter(|mi| path.starts_with(&mi.mount_dir));
|
|
||||||
matches.max_by_key(|mi| mi.mount_dir.len())
|
let maybe_mount_point = mounts
|
||||||
|
.iter()
|
||||||
|
.find(|mi| mi.dev_name.eq(&path.to_string_lossy()));
|
||||||
|
|
||||||
|
maybe_mount_point.or_else(|| {
|
||||||
|
mounts
|
||||||
|
.iter()
|
||||||
|
.filter(|mi| path.starts_with(&mi.mount_dir))
|
||||||
|
.max_by_key(|mi| mi.mount_dir.len())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Filesystem {
|
impl Filesystem {
|
||||||
|
@ -199,5 +208,14 @@ mod tests {
|
||||||
let mounts = [mount_info("/foo/bar")];
|
let mounts = [mount_info("/foo/bar")];
|
||||||
assert!(mount_info_from_path(&mounts, "/foo/baz", false).is_none());
|
assert!(mount_info_from_path(&mounts, "/foo/baz", false).is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_dev_name_match() {
|
||||||
|
let mut mount_info = mount_info("/foo");
|
||||||
|
mount_info.dev_name = "/dev/sda2".to_string();
|
||||||
|
let mounts = [mount_info];
|
||||||
|
let actual = mount_info_from_path(&mounts, "/dev/sda2", false).unwrap();
|
||||||
|
assert!(mount_info_eq(actual, &mounts[0]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue