Skip to content

Commit b40bfcd

Browse files
author
Kyohei Uto
committed
Add fs::symlink_metadata to detect broken symlinks
1 parent 337d417 commit b40bfcd

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,11 @@ fn fill_todo(
854854
} else {
855855
path.join(&s)
856856
};
857-
if (special && is_dir) || (!special && fs::metadata(&next_path).is_ok()) {
857+
if (special && is_dir)
858+
|| (!special
859+
&& (fs::metadata(&next_path).is_ok()
860+
|| fs::symlink_metadata(&next_path).is_ok()))
861+
{
858862
add(todo, next_path);
859863
}
860864
}
@@ -1091,15 +1095,13 @@ mod test {
10911095
// check windows absolute paths with host/device components
10921096
let root_with_device = current_dir()
10931097
.ok()
1094-
.and_then(|p| {
1095-
match p.components().next().unwrap() {
1096-
Component::Prefix(prefix_component) => {
1097-
let path = Path::new(prefix_component.as_os_str());
1098-
path.join("*");
1099-
Some(path.to_path_buf())
1100-
}
1101-
_ => panic!("no prefix in this path"),
1098+
.and_then(|p| match p.components().next().unwrap() {
1099+
Component::Prefix(prefix_component) => {
1100+
let path = Path::new(prefix_component.as_os_str());
1101+
path.join("*");
1102+
Some(path.to_path_buf())
11021103
}
1104+
_ => panic!("no prefix in this path"),
11031105
})
11041106
.unwrap();
11051107
// FIXME (#9639): This needs to handle non-utf8 paths

0 commit comments

Comments
 (0)