Don't automatically dereference symlinks in tree/recursive

This commit is contained in:
Abin Simon
2022-03-15 09:58:16 +05:30
committed by Wei Zhang
parent 7fb9aaf692
commit 019e8e424f
3 changed files with 48 additions and 7 deletions

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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()
}