summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbin Simon <mail@meain.io>2022-03-15 09:58:16 +0530
committerWei Zhang <kweizh@gmail.com>2022-03-15 19:56:06 +0800
commit019e8e424f0935fd2707062bef395fdb62e829a4 (patch)
tree6ea1b5a3fe24a66781cb7fff95ca20bccfd95605
parent7fb9aaf6921a116621edb21ab4e73cfbd62c97e3 (diff)
Don't automatically dereference symlinks in tree/recursive
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/meta/mod.rs18
-rw-r--r--tests/integration.rs36
3 files changed, 48 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 38bc407..dd5be60 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `--group-directories-first` as an alias for `--group-dirs=first` to improve compatibility with `coreutils/ls`
### Fixed
- Support non-bold bright colors [#248](https://github.com/Peltoche/lsd/issues/248) from [meain](https://github.com/meain)
+- Don't automatically dereference symlinks in tree/recursive [#637](https://github.com/Peltoche/lsd/issues/637) from [meain](https://github.com/meain)
## [0.21.0] - 2022-01-16
### Added
diff --git a/src/meta/mod.rs b/src/meta/mod.rs
index d78a6b9..ad531ea 100644
--- a/src/meta/mod.rs
+++ b/src/meta/mod.rs
@@ -129,13 +129,17 @@ impl Meta {
}
}
- match entry_meta.recurse_into(depth - 1, flags) {
- Ok(content) => entry_meta.content = content,
- Err(err) => {
- print_error!("{}: {}.", path.display(), err);
- continue;
- }
- };
+ let dereference =
+ !matches!(entry_meta.file_type, FileType::SymLink { .. }) || flags.dereference.0;
+ if dereference {
+ match entry_meta.recurse_into(depth - 1, flags) {
+ Ok(content) => entry_meta.content = content,
+ Err(err) => {
+ print_error!("{}: {}.", path.display(), err);
+ continue;
+ }
+ };
+ }
content.push(entry_meta);
}
diff --git a/tests/integration.rs b/tests/integration.rs
index 1a760aa..641753d 100644
--- a/tests/integration.rs
+++ b/tests/integration.rs
@@ -504,6 +504,42 @@ fn test_tree_d() {
.stdout(predicate::str::is_match("├── one.d\n│ └── one.d\n└── two.d\n$").unwrap());
}
+#[cfg(unix)]
+#[test]
+fn test_tree_no_dereference() {
+ let tmp = tempdir();
+ tmp.child("one.d").create_dir_all().unwrap();
+ tmp.child("one.d/samplefile").touch().unwrap();
+ let link = tmp.path().join("link");
+ fs::symlink("one.d", &link).unwrap();
+
+ cmd().arg(tmp.path()).arg("--tree").assert().stdout(
+ predicate::str::is_match("├── link ⇒ one.d\n└── one.d\n └── samplefile\n$").unwrap(),
+ );
+}
+
+#[cfg(unix)]
+#[test]
+fn test_tree_dereference() {
+ let tmp = tempdir();
+ tmp.child("one.d").create_dir_all().unwrap();
+ tmp.child("one.d/samplefile").touch().unwrap();
+ let link = tmp.path().join("link");
+ fs::symlink("one.d", &link).unwrap();
+
+ cmd()
+ .arg(tmp.path())
+ .arg("--tree")
+ .arg("-L")
+ .assert()
+ .stdout(
+ predicate::str::is_match(
+ "├── link\n│ └── samplefile\n└── one.d\n └── samplefile\n$",
+ )
+ .unwrap(),
+ );
+}
+
fn cmd() -> Command {
Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap()
}