1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #3682 from cakebaker/ticket_3246

df: fix output if input path is device name
This commit is contained in:
Sylvestre Ledru 2022-06-30 23:55:58 +02:00 committed by GitHub
commit 63bf7db171
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,8 +67,17 @@ where
} else {
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 {
@ -199,5 +208,14 @@ mod tests {
let mounts = [mount_info("/foo/bar")];
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]));
}
}
}