nu-glob: add fs::symlink_metadata to detect broken symlinks (#5537)

* nu-glob: add fs::symlink_metadata to detect broken symlinks

* fix join result
This commit is contained in:
Herlon Aguiar 2022-05-14 02:56:26 +02:00 committed by GitHub
parent f818193b53
commit 3cef94ba39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -782,7 +782,11 @@ fn fill_todo(
} else {
path.join(&s)
};
if (special && is_dir) || (!special && fs::metadata(&next_path).is_ok()) {
if (special && is_dir)
|| (!special
&& (fs::metadata(&next_path).is_ok()
|| fs::symlink_metadata(&next_path).is_ok()))
{
add(todo, next_path);
}
}
@ -966,7 +970,7 @@ mod test {
.and_then(|p| match p.components().next().unwrap() {
Component::Prefix(prefix_component) => {
let path = Path::new(prefix_component.as_os_str()).join("*");
Some(path)
Some(path.to_path_buf())
}
_ => panic!("no prefix in this path"),
})