Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade linkchecker to url 1.2.0. #35638

Merged
merged 1 commit into from
Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions src/tools/linkchecker/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/tools/linkchecker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Alex Crichton <alex@alexcrichton.com>"]

[dependencies]
url = "0.5"
url = "1.2"

[[bin]]
name = "linkchecker"
Expand Down
23 changes: 9 additions & 14 deletions src/tools/linkchecker/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use std::path::{Path, PathBuf};
use std::collections::{HashMap, HashSet};
use std::collections::hash_map::Entry;

use url::{Url, UrlParser};
use url::Url;

use Redirect::*;

Expand Down Expand Up @@ -92,7 +92,7 @@ fn walk(cache: &mut Cache, root: &Path, dir: &Path, url: &mut Url, errors: &mut
for entry in t!(dir.read_dir()).map(|e| t!(e)) {
let path = entry.path();
let kind = t!(entry.file_type());
url.path_mut().unwrap().push(entry.file_name().into_string().unwrap());
url.path_segments_mut().unwrap().push(entry.file_name().to_str().unwrap());
if kind.is_dir() {
walk(cache, root, &path, url, errors);
} else {
Expand All @@ -104,7 +104,7 @@ fn walk(cache: &mut Cache, root: &Path, dir: &Path, url: &mut Url, errors: &mut
entry.source = String::new();
}
}
url.path_mut().unwrap().pop();
url.path_segments_mut().unwrap().pop();
}
}

Expand Down Expand Up @@ -138,9 +138,6 @@ fn check(cache: &mut Cache,
return None;
}

let mut parser = UrlParser::new();
parser.base_url(base);

let res = load_file(cache, root, PathBuf::from(file), SkipRedirect);
let (pretty_file, contents) = match res {
Ok(res) => res,
Expand All @@ -162,7 +159,7 @@ fn check(cache: &mut Cache,
}
// Once we've plucked out the URL, parse it using our base url and
// then try to extract a file path.
let (parsed_url, path) = match url_to_file_path(&parser, url) {
let (parsed_url, path) = match url_to_file_path(&base, url) {
Some((url, path)) => (url, PathBuf::from(path)),
None => {
*errors = true;
Expand Down Expand Up @@ -203,7 +200,7 @@ fn check(cache: &mut Cache,
Err(LoadError::IsRedirect) => unreachable!(),
};

if let Some(ref fragment) = parsed_url.fragment {
if let Some(ref fragment) = parsed_url.fragment() {
// Fragments like `#1-6` are most likely line numbers to be
// interpreted by javascript, so we're ignoring these
if fragment.splitn(2, '-')
Expand All @@ -214,7 +211,7 @@ fn check(cache: &mut Cache,
let entry = &mut cache.get_mut(&pretty_path).unwrap();
entry.parse_ids(&pretty_path, &contents, errors);

if !entry.ids.contains(fragment) {
if !entry.ids.contains(*fragment) {
*errors = true;
print!("{}:{}: broken link fragment ",
pretty_file.display(),
Expand Down Expand Up @@ -271,10 +268,8 @@ fn load_file(cache: &mut Cache,
}
};
let base = Url::from_file_path(&file).unwrap();
let mut parser = UrlParser::new();
parser.base_url(&base);

match maybe_redirect.and_then(|url| url_to_file_path(&parser, &url)) {
match maybe_redirect.and_then(|url| url_to_file_path(&base, &url)) {
Some((_, redirect_file)) => {
let path = PathBuf::from(redirect_file);
load_file(cache, root, path, FromRedirect(true))
Expand All @@ -299,8 +294,8 @@ fn maybe_redirect(source: &str) -> Option<String> {
})
}

fn url_to_file_path(parser: &UrlParser, url: &str) -> Option<(Url, PathBuf)> {
parser.parse(url)
fn url_to_file_path(parser: &Url, url: &str) -> Option<(Url, PathBuf)> {
parser.join(url)
.ok()
.and_then(|parsed_url| parsed_url.to_file_path().ok().map(|f| (parsed_url, f)))
}
Expand Down