Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,9 @@ impl LsOutput for TextOutput<'_> {
if !is_first {
writeln!(self.state.out)?;
if config.dired {
self.dired.line_offset += 1; // account for the blank line before recursive directory headings
self.dired.padding = 0;
// Account for the blank line before the heading. Keep the padding: after a
// directory that listed no entry it still holds that heading and "total" line.
self.dired.line_offset += 1;
}
}
if config.dired {
Expand Down
34 changes: 34 additions & 0 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6256,6 +6256,40 @@ fn names_at_offsets(output: &str, tag: &str) -> Vec<String> {
.collect()
}

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

at.mkdir("d");
at.mkdir("d/empty");
at.mkdir("d/hidden");
at.touch("d/hidden/.dot");
at.mkdir("d/zfull");
at.touch("d/zfull/f");

// Directories listing no entry must still count their heading and "total" line.
let result = scene
.ucmd()
.args(&["--dired", "-l", "d/empty", "d/hidden", "d/zfull"])
.succeeds();
assert_eq!(dired_names(result.stdout_str()), ["f"]);
assert_eq!(
subdired_names(result.stdout_str()),
["d/empty", "d/hidden", "d/zfull"]
);

let result = scene.ucmd().args(&["--dired", "-lR", "d"]).succeeds();
assert_eq!(
dired_names(result.stdout_str()),
["empty", "hidden", "zfull", "f"]
);
assert_eq!(
subdired_names(result.stdout_str()),
["d", "d/empty", "d/hidden", "d/zfull"]
);
}

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