ls: Fix minor output mismatch

When a single directory is passed to ls in recursive mode, uutils ls
won't print the directory name
======================
GNU ls:
z:
======================
======================
uutils ls:
======================

This commit fixes this minor inconsistency and adds corresponding test.
This commit is contained in:
Anup Mahindre 2021-05-30 18:00:52 +05:30
parent 4d51e16140
commit 898d325aea
2 changed files with 7 additions and 1 deletions

View file

@ -1223,7 +1223,7 @@ fn list(locs: Vec<String>, config: Config) -> i32 {
sort_entries(&mut dirs, &config);
for dir in dirs {
if locs.len() > 1 {
if locs.len() > 1 || config.recursive {
let _ = writeln!(out, "\n{}:", dir.p_buf.display());
}
enter_directory(&dir, &config, &mut out);

View file

@ -899,6 +899,12 @@ fn test_ls_recursive() {
scene.ucmd().arg("a").succeeds();
scene.ucmd().arg("a/a").succeeds();
scene
.ucmd()
.arg("z")
.arg("-R")
.succeeds()
.stdout_contains(&"z:");
let result = scene
.ucmd()
.arg("--color=never")