Fix sorting with almost-all flag and a folder

With a folder structure (a folder `z` with a file `a`), if we do `lsd
-a` it used to be:

. a ..

instead of

. .. a

This was caused to the the parent meta having full path and us using
z/.. to sort .. entry. This should now be fixed with manually changing
the name to a .. .
This commit is contained in:
Abin Simon 2021-02-14 21:46:31 +05:30
parent 0ca699ee2f
commit 24e6335e0a
3 changed files with 18 additions and 1 deletions

View file

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Not showing `.` and `..` when `--tree` with `--all` from [zwpaper](https://github.com/zwpaper) [#477](https://github.com/Peltoche/lsd/issues/477)
### Fixed
- Fix handling blocks passed without -l in cli from [meain](https://github.com/meain)
- Fixed sorting of . and .. when used with folder from [meain](https://github.com/meain)
## [0.19.0] - 2020-12-13
### Added

View file

@ -87,8 +87,9 @@ impl Meta {
current_meta = self.clone();
current_meta.name.name = ".".to_owned();
let parent_meta =
let mut parent_meta =
Self::from_path(&self.path.join(Component::ParentDir), flags.dereference.0)?;
parent_meta.name.name = "..".to_owned();
content.push(current_meta);
content.push(parent_meta);

View file

@ -97,6 +97,21 @@ fn test_list_all_populated_directory() {
.stdout(predicate::str::is_match("\\.\n\\.\\.\none\ntwo\n$").unwrap());
}
#[test]
fn test_almost_sort_with_folder() {
let tmp = tempdir();
tmp.child("z").create_dir_all().unwrap();
tmp.child("z/a").touch().unwrap();
cmd()
.current_dir(tmp.path())
.arg("-a")
.arg("--ignore-config")
.arg("z")
.assert()
.stdout(predicate::str::is_match("\\.\n\\.\\.\na\n$").unwrap());
}
#[test]
fn test_list_inode_populated_directory() {
let dir = tempdir();