mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
fix(ls): place dot dirs on top in version sorting
Also fixes the fact that version sorting had incorrect edge cases due to wrong name passing.
This commit is contained in:
committed by
Daniel Hofstetter
parent
e4a2ab3955
commit
f774940451
+11
-2
@@ -979,6 +979,15 @@ impl<'a> PathData<'a> {
|
||||
PathDataDisplayName::Custom(ref cow) => cow,
|
||||
}
|
||||
}
|
||||
|
||||
fn file_name(&self) -> &OsStr {
|
||||
match self.display_name {
|
||||
PathDataDisplayName::SelfReferential => {
|
||||
self.p_buf.file_name().unwrap_or(self.p_buf.as_os_str())
|
||||
}
|
||||
PathDataDisplayName::Custom(ref cow) => cow,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Colorable for PathData<'_> {
|
||||
@@ -1477,8 +1486,8 @@ fn sort_entries(entries: &mut [PathData], config: &Config) {
|
||||
Sort::Name => entries.sort_unstable_by(|a, b| a.display_name().cmp(b.display_name())),
|
||||
Sort::Version => entries.sort_unstable_by(|a, b| {
|
||||
version_cmp(
|
||||
os_str_as_bytes_lossy(a.path().as_os_str()).as_ref(),
|
||||
os_str_as_bytes_lossy(b.path().as_os_str()).as_ref(),
|
||||
os_str_as_bytes_lossy(a.file_name()).as_ref(),
|
||||
os_str_as_bytes_lossy(b.file_name()).as_ref(),
|
||||
)
|
||||
.then(a.path().cmp(b.path()))
|
||||
}),
|
||||
|
||||
@@ -3661,7 +3661,7 @@ fn test_ls_version_sort() {
|
||||
);
|
||||
|
||||
let result = scene.ucmd().arg("-a1v").succeeds();
|
||||
expected.insert(expected.len() - 1, "..");
|
||||
expected.insert(0, "..");
|
||||
expected.insert(0, ".");
|
||||
assert_eq!(
|
||||
result.stdout_str().split('\n').collect::<Vec<_>>(),
|
||||
|
||||
Reference in New Issue
Block a user