Skip to content

Commit

Permalink
Rollup merge of rust-lang#93897 - schopin-pro:linkchecker-symlink, r=…
Browse files Browse the repository at this point in the history
…Mark-Simulacrum

linkchecker: fix panic on directory symlinks

In Debian and Ubuntu, there are some patches that change the rustc/fonts
directory to a symlink to the system fonts. This triggers a latent bug
in linkchecker, as the DirEntry filetype isn't a dir but later on the
file itself, when opened, is one, triggering an unreachable!() clause.

This patch fixes the situation by using std::fs::metadata, which goes
through symlinks.

I'd have added a test case but `tidy` doesn't seem to like symlinks, and
moreover I'm not sure how Git deals with symlinks on Windows.

Signed-off-by: Simon Chopin <[email protected]>
  • Loading branch information
matthiaskrgr authored Feb 12, 2022
2 parents f30f6de + 3a1ffea commit 475b45f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/tools/linkchecker/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ impl Checker {
fn walk(&mut self, dir: &Path, report: &mut Report) {
for entry in t!(dir.read_dir()).map(|e| t!(e)) {
let path = entry.path();
let kind = t!(entry.file_type());
if kind.is_dir() {
// Goes through symlinks
let metadata = t!(fs::metadata(&path));
if metadata.is_dir() {
self.walk(&path, report);
} else {
self.check(&path, report);
Expand Down

0 comments on commit 475b45f

Please sign in to comment.