From cacb3bc9c741a7d41a1085af850cd3ff852307f5 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 10 Feb 2017 16:38:20 -0500 Subject: [PATCH] fix up linkchecker 1. skip png files 2. skip fragments for the book and nomicon, as these are added by JS 3. Actually print the filename for errors --- src/tools/linkchecker/main.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs index f84d685127b..304c722bbe5 100644 --- a/src/tools/linkchecker/main.rs +++ b/src/tools/linkchecker/main.rs @@ -171,6 +171,13 @@ fn check(cache: &mut Cache, } } + if let Some(extension) = path.extension() { + // don't check these files + if extension == "png" { + return; + } + } + // Alright, if we've found a file name then this file had better // exist! If it doesn't then we register and print an error. if path.exists() { @@ -188,7 +195,9 @@ fn check(cache: &mut Cache, let res = load_file(cache, root, path.clone(), FromRedirect(false)); let (pretty_path, contents) = match res { Ok(res) => res, - Err(LoadError::IOError(err)) => panic!(format!("{}", err)), + Err(LoadError::IOError(err)) => { + panic!(format!("error loading {}: {}", path.display(), err)); + } Err(LoadError::BrokenRedirect(target, _)) => { *errors = true; println!("{}:{}: broken redirect to {}", @@ -200,6 +209,13 @@ fn check(cache: &mut Cache, Err(LoadError::IsRedirect) => unreachable!(), }; + // we don't check the book for fragments because they're added via JS + for book in ["book/", "nomicon/"].iter() { + if !pretty_path.to_str().unwrap().starts_with(book) { + return; + } + } + if let Some(ref fragment) = fragment { // Fragments like `#1-6` are most likely line numbers to be // interpreted by javascript, so we're ignoring these