summaryrefslogtreecommitdiff
path: root/support/pkgcheck/src/linkcheck.rs
diff options
context:
space:
mode:
Diffstat (limited to 'support/pkgcheck/src/linkcheck.rs')
-rw-r--r--support/pkgcheck/src/linkcheck.rs31
1 files changed, 15 insertions, 16 deletions
diff --git a/support/pkgcheck/src/linkcheck.rs b/support/pkgcheck/src/linkcheck.rs
index b0b33fb3b2..ba0cd73cea 100644
--- a/support/pkgcheck/src/linkcheck.rs
+++ b/support/pkgcheck/src/linkcheck.rs
@@ -1,3 +1,5 @@
+use log::*;
+
use threadpool::ThreadPool;
use colored::*;
@@ -6,10 +8,10 @@ use linkify::{LinkFinder, LinkKind};
use std::fs::File;
use std::io::prelude::*;
-
use reqwest::header;
use std::time::Duration;
+use std::borrow::Cow;
use std::sync::Arc;
use std::sync::Mutex;
@@ -104,7 +106,7 @@ fn check_link(url: &str, fname: &str, urlhash: &Arc<Mutex<UrlHash>>, print_all:
}
UrlStatus::UrlOk => {
if print_all {
- print_ok(no_colors!(), &url, &f);
+ print_ok(super::ARGS.no_colors, &url, &f);
};
}
UrlStatus::UrlError(e) => {
@@ -122,7 +124,7 @@ fn check_link(url: &str, fname: &str, urlhash: &Arc<Mutex<UrlHash>>, print_all:
if let Some(mut hs) = urlhash.get_mut(&url) {
if print_all {
for p in hs.paths.iter() {
- print_ok(no_colors!(), &url, p);
+ print_ok(super::ARGS.no_colors, &url, p);
}
}
hs.status = UrlStatus::UrlOk;
@@ -152,29 +154,26 @@ fn get_links(fname: &str) -> Option<Vec<String>> {
Ok(_bytes_read) => {
return get_links_inner(&String::from_utf8_lossy(&buf));
}
- Err(e) => println!("Error reading file {}: {:?}", fname, e),
+ Err(e) => error!("Error reading file {}: {:?}", fname, e),
}
}
- Err(e) => println!("Error opening file {}: {}", fname, e),
+ Err(e) => error!("Error opening file {}: {}", fname, e),
}
None
}
-fn resolve_entities(url: &str) -> String {
+fn resolve_entities(url: &str) -> Cow<'static, str> {
if !url.contains('&') {
- return String::from(url);
+ return String::from(url).into();
}
- let v = vec![
- ("&ouml;", "ö"),
- ("&uuml;", "ü"),
- ];
+ let v = vec![("&ouml;", "ö"), ("&uuml;", "ü")];
let mut url_new = String::from(url);
- for (e,r) in v {
+ for (e, r) in v {
url_new = url_new.replace(e, r);
}
- url_new
+ url_new.into()
}
// retrieves links in a string and then checks those links
@@ -195,7 +194,7 @@ fn get_links_inner(s: &str) -> Option<Vec<String>> {
// This is a workaround to prevent URLs ending with certain characters
let url = resolve_entities(r.trim_end_matches(|c| c == '。' || c == '`'));
- links.push(url);
+ links.push(url.into());
}
if !links.is_empty() {
Some(links)
@@ -264,9 +263,9 @@ fn check_link_inner(l: &str, head: bool) -> UrlStatus {
fn print_ok(no_colors: bool, url: &str, f: &str) {
if no_colors {
- println!("✔ {} in {}", &url, f);
+ info!("✔ {} in {}", &url, f);
} else {
// println!("✔ {} in {}", &url, f);
- println!("{} {} in {}", "✔".bright_green().bold(), url, f);
+ info!("{} {} in {}", "✔".bright_green().bold(), url, f);
}
}