Skip to content

Commit

Permalink
ls: Fix incorrect ordering for . and ..
Browse files Browse the repository at this point in the history
  • Loading branch information
siebenHeaven committed Apr 17, 2021
1 parent 772632f commit 7a533b3
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,27 +1099,30 @@ fn should_display(entry: &DirEntry, config: &Config) -> bool {
}

fn enter_directory(dir: &PathData, config: &Config) {
let mut entries: Vec<_> = safe_unwrap!(fs::read_dir(&dir.p_buf))
let mut entries = if config.files == Files::All {
vec![
PathData::new(dir.p_buf.join("."), config),
PathData::new(dir.p_buf.join(".."), config),
]
} else {
vec![]
};

let mut temp = safe_unwrap!(fs::read_dir(&dir.p_buf))
.map(|res| safe_unwrap!(res))
.filter(|e| should_display(e, config))
.map(|e| PathData::new(DirEntry::path(&e), config))
.collect();
sort_entries(&mut temp, config);

sort_entries(&mut entries, config);

if config.files == Files::All {
let extra_entries: [PathData; 2] = [
PathData::new(dir.p_buf.join(".."), config),
PathData::new(dir.p_buf.join("."), config),
];
display_items(&extra_entries, Some(&dir.p_buf), config);
}
entries.append(&mut temp);

display_items(&entries, Some(&dir.p_buf), config);

if config.recursive {
for e in entries
.iter()
.skip(if config.files == Files::All { 2 } else { 0 })
.filter(|p| p.md.as_ref().map_or(false, |md| md.is_dir()))
{
println!("\n{}:", e.path_string);
Expand Down

0 comments on commit 7a533b3

Please sign in to comment.