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