ls: Fix issue with Windows and dangling symbolic links

- Windows hidden file attribute determination would assume symbolic link
  to be valid and would panic
- Check symbolic link's attributes if the link points to non-existing
  file
This commit is contained in:
Anup Mahindre 2021-06-20 16:56:25 +05:30
parent d0039df8c3
commit 3b641afadc

View file

@ -1270,7 +1270,8 @@ fn sort_entries(entries: &mut Vec<PathData>, config: &Config) {
#[cfg(windows)]
fn is_hidden(file_path: &DirEntry) -> bool {
let metadata = fs::metadata(file_path.path()).unwrap();
let path = file_path.path();
let metadata = fs::metadata(&path).unwrap_or_else(|_| fs::symlink_metadata(&path).unwrap());
let attr = metadata.file_attributes();
(attr & 0x2) > 0
}