From 24e6335e0a73a24ba7138e5510b3db7ce5d19051 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Sun, 14 Feb 2021 21:46:31 +0530 Subject: [PATCH] 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 .. . --- CHANGELOG.md | 1 + src/meta/mod.rs | 3 ++- tests/integration.rs | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d364a3..88d0830 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/meta/mod.rs b/src/meta/mod.rs index d29fcee..83d3112 100644 --- a/src/meta/mod.rs +++ b/src/meta/mod.rs @@ -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); diff --git a/tests/integration.rs b/tests/integration.rs index 8d34eb6..b65ff03 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -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();