Skip to content

Commit

Permalink
df: fix output if input path is device name
Browse files Browse the repository at this point in the history
  • Loading branch information
cakebaker authored and sylvestre committed Jun 30, 2022
1 parent a66527e commit 9b9d369
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/uu/df/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]));
}
}
}

0 comments on commit 9b9d369

Please sign in to comment.