Skip to content

Commit

Permalink
ls --dired -R: missing indent for the second directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Sep 21, 2023
1 parent 87741ca commit 48fc80d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/uu/ls/src/dired.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn print_dired_output(
out: &mut BufWriter<Stdout>,
) -> UResult<()> {
out.flush()?;
if !dired.dired_positions.is_empty() {
if !dired.just_printed_total {
print_positions("//DIRED//", &dired.dired_positions);
}
if config.recursive {
Expand Down
16 changes: 14 additions & 2 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,10 @@ impl PathData {
}
}

fn show_dir_name(dir: &Path, out: &mut BufWriter<Stdout>) {
write!(out, "{}:", dir.display()).unwrap();
}

pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> {
let mut files = Vec::<PathData>::new();
let mut dirs = Vec::<PathData>::new();
Expand Down Expand Up @@ -1924,7 +1928,8 @@ pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> {
dired::calculate_subdired(&mut dired, path_data.display_name.len());
}
} else {
writeln!(out, "\n{}:", path_data.p_buf.display())?;
write!(out, "\n").unwrap();
show_dir_name(&path_data.p_buf, &mut out);
}
}
let mut listed_ancestors = HashSet::new();
Expand Down Expand Up @@ -2131,7 +2136,14 @@ fn enter_directory(
if listed_ancestors
.insert(FileInformation::from_path(&e.p_buf, e.must_dereference)?)
{
writeln!(out, "\n{}:", e.p_buf.display())?;
// when listing several directories in recursive mode, we show
// "dirname:" at the beginning of the file list
write!(out, "\n")?;
if config.dired {
dired::indent(out)?;
}
show_dir_name(&e.p_buf, out);
write!(out, "\n")?;
enter_directory(e, rd, config, out, listed_ancestors, dired)?;
listed_ancestors
.remove(&FileInformation::from_path(&e.p_buf, e.must_dereference)?);
Expand Down
24 changes: 24 additions & 0 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3551,6 +3551,30 @@ fn test_ls_dired_recursive() {
.stdout_contains("//DIRED-OPTIONS// --quoting-style");
}

#[test]
fn test_ls_dired_recursive_several() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

at.mkdir("d");
at.mkdir("d/d1");
at.mkdir("d/d2");

let result = scene
.ucmd()
.arg("--dired")
.arg("-l")
.arg("-R")
.arg("d")
.succeeds()
.stdout_does_not_contain("//DIRED//")
.stdout_contains(" d/d1:")
.stdout_contains(" d/d2:")
.stdout_contains(" total 0")
.stdout_contains("//SUBDIRED// 2 3")
.stdout_contains("//DIRED-OPTIONS// --quoting-style");
}

#[test]
fn test_ls_dired_simple() {
let scene = TestScenario::new(util_name!());
Expand Down

0 comments on commit 48fc80d

Please sign in to comment.