Skip to content

Commit

Permalink
df: fix output if input path is a file system
Browse files Browse the repository at this point in the history
  • Loading branch information
cakebaker committed Apr 22, 2022
1 parent 4ea443b commit ffda238
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/uu/df/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
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())
matches.min_by_key(|mi| mi.mount_dir.len())
}

impl Filesystem {
Expand Down
19 changes: 19 additions & 0 deletions tests/by-util/test_df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,22 @@ fn test_nonexistent_file() {
.stderr_is("df: does-not-exist: No such file or directory\n")
.stdout_is("File\n.\n");
}

#[test]
fn test_file_system_as_input_path() {
let fs = new_ucmd!()
.args(&[
"--output=source",
std::env::current_exe().unwrap().to_str().unwrap(),
])
.succeeds()
.stdout_move_str();
let fs = fs.lines().nth(1).unwrap();

let actual = new_ucmd!()
.args(&["--output=source", fs])
.succeeds()
.stdout_move_str();
let actual = actual.lines().nth(1).unwrap();
assert_eq!(actual, fs);
}

0 comments on commit ffda238

Please sign in to comment.