diff options
author | Norbert Preining <norbert@preining.info> | 2022-01-16 03:01:19 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-01-16 03:01:19 +0000 |
commit | a574e957682cad50981ddb567c2a106213dc8672 (patch) | |
tree | cd02ecf7773fd7bad8e7b6cdb07cf2ff437ba59f /support/pkgcheck/src | |
parent | 0cb730e5737ffa35f797eaf75c2613e5ac88617c (diff) |
CTAN sync 202201160301
Diffstat (limited to 'support/pkgcheck/src')
-rw-r--r-- | support/pkgcheck/src/linkcheck.rs | 20 | ||||
-rw-r--r-- | support/pkgcheck/src/main.rs | 55 | ||||
-rw-r--r-- | support/pkgcheck/src/messages/errorsd.rs | 1 | ||||
-rw-r--r-- | support/pkgcheck/src/messages/mod.rs | 263 | ||||
-rw-r--r-- | support/pkgcheck/src/utils.rs | 12 |
5 files changed, 194 insertions, 157 deletions
diff --git a/support/pkgcheck/src/linkcheck.rs b/support/pkgcheck/src/linkcheck.rs index cc7aa36e31..b0b33fb3b2 100644 --- a/support/pkgcheck/src/linkcheck.rs +++ b/support/pkgcheck/src/linkcheck.rs @@ -161,6 +161,22 @@ fn get_links(fname: &str) -> Option<Vec<String>> { None } +fn resolve_entities(url: &str) -> String { + if !url.contains('&') { + return String::from(url); + } + + let v = vec![ + ("ö", "ö"), + ("ü", "ü"), + ]; + let mut url_new = String::from(url); + for (e,r) in v { + url_new = url_new.replace(e, r); + } + url_new +} + // retrieves links in a string and then checks those links fn get_links_inner(s: &str) -> Option<Vec<String>> { let mut finder = LinkFinder::new(); @@ -177,9 +193,9 @@ fn get_links_inner(s: &str) -> Option<Vec<String>> { } // This is a workaround to prevent URLs ending with certain characters - let url = r.trim_end_matches(|c| c == '。' || c == '`'); + let url = resolve_entities(r.trim_end_matches(|c| c == '。' || c == '`')); - links.push(String::from(url)); + links.push(url); } if !links.is_empty() { Some(links) diff --git a/support/pkgcheck/src/main.rs b/support/pkgcheck/src/main.rs index bb8e90b76e..b18fd8793b 100644 --- a/support/pkgcheck/src/main.rs +++ b/support/pkgcheck/src/main.rs @@ -49,7 +49,6 @@ use std::path::Path; use std::path::PathBuf; use std::sync::atomic::{AtomicBool, Ordering}; -use blake2::{Blake2b, Digest}; use rustc_hash::{FxHashMap, FxHashSet}; use std::sync::mpsc::{channel, Sender}; @@ -80,14 +79,14 @@ const BLOCKSIZE: usize = 4096; fn hash_file_inner(path: &Path) -> io::Result<Vec<u8>> { let mut buf = [0u8; BLOCKSIZE]; let mut fp = File::open(&path)?; - let mut digest = Blake2b::default(); + let mut digest = blake3::Hasher::new(); loop { match fp.read(&mut buf)? { 0 => break, - n => digest.update(&buf[..n]), + n => { digest.update(&buf[..n]); }, } } - Ok(digest.finalize().to_vec()) + Ok(digest.finalize().as_bytes().to_vec()) } fn hash_file(fsize: u64, path: PathBuf, tx: &HashSender) { @@ -576,22 +575,22 @@ fn check_tds_archive_name(tds_zip: &Option<String>) -> Option<String> { } } -fn unzip_tds_archive(tds_zip: &str, tmp_dir: &str) { - match run_cmd("unzip", &["-q", "-d", tmp_dir, tds_zip]) { - CmdReturn { status: true, .. } => (), - CmdReturn { - status: false, - output: out, - } => { - if let Some(o) = out { - e0033!(&tds_zip, o); - } else { - e0033!(&tds_zip, "<no error given"); - } - process::exit(1); - } - } -} +// fn unzip_tds_archive(tds_zip: &str, tmp_dir: &str) { +// match run_cmd("unzip", &["-q", "-d", tmp_dir, tds_zip]) { +// CmdReturn { status: true, .. } => (), +// CmdReturn { +// status: false, +// output: out, +// } => { +// if let Some(o) = out { +// e0033!(&tds_zip, o); +// } else { +// e0033!(&tds_zip, "<no error given"); +// } +// process::exit(1); +// } +// } +// } fn check_tds_archive(pkg_name: &str, tds_zip: &str, hashes: &DupHashes) { i0003!(tds_zip); @@ -619,11 +618,13 @@ fn check_tds_archive(pkg_name: &str, tds_zip: &str, hashes: &DupHashes) { let mut pkg_replacements: FxHashMap<&str, &str> = FxHashMap::default(); pkg_replacements.insert("babel-base", "babel"); pkg_replacements.insert("latex-base", "latex"); + pkg_replacements.insert("latex-lab", "latex"); pkg_replacements.insert("latex-tools", "latex"); pkg_replacements.insert("latex-graphics", "latex"); pkg_replacements.insert("latex-amsmath", "latex"); pkg_replacements.insert("latex-firstaid", "latex/firstaid"); pkg_replacements.insert("latex-base-dev", "latex-dev"); + pkg_replacements.insert("latex-lab-dev", "latex-dev"); pkg_replacements.insert("latex-tools-dev", "latex-dev"); pkg_replacements.insert("latex-graphics-dev", "latex-dev"); pkg_replacements.insert("latex-amsmath-dev", "latex-dev"); @@ -643,7 +644,17 @@ fn check_tds_archive(pkg_name: &str, tds_zip: &str, hashes: &DupHashes) { }; let tmp_dir_offset = tmp_dir.path().to_str().unwrap().len() + 1; - unzip_tds_archive(tds_zip, tmp_dir.path().to_str().unwrap()); + let tmp_dir_str = tmp_dir.path().to_str().unwrap(); + // unzip the TDS zip archive into a temporary directory + match ut.unzip(tds_zip, tmp_dir_str) { + Ok(_) => {}, + Err(e) => { + println!("Could not unpack `{}` into directory `{}`", tds_zip, tmp_dir_str); + println!("Error from unzip: {}", e); + e0033!(&tds_zip, e); + process::exit(1) + } + } // in order to compare the package files with the content of the // tds zip archive we need to checksum the files in the tds zip @@ -896,7 +907,7 @@ fn fix_perms(entry: &str) { } i0005!(entry); - let rc = run_cmd("/bin/chmod", &["-v", "ug=rwX,o=rX", entry]); + let rc = run_cmd("chmod", &["-v", "ug=rwX,o=rX", entry]); if rc.status { if let Some(op) = rc.output { diff --git a/support/pkgcheck/src/messages/errorsd.rs b/support/pkgcheck/src/messages/errorsd.rs index 6ef9eed62e..0ea42eb23f 100644 --- a/support/pkgcheck/src/messages/errorsd.rs +++ b/support/pkgcheck/src/messages/errorsd.rs @@ -486,4 +486,3 @@ fonts/map/dvips. "# ) } - diff --git a/support/pkgcheck/src/messages/mod.rs b/support/pkgcheck/src/messages/mod.rs index e3ec350143..f6819f1120 100644 --- a/support/pkgcheck/src/messages/mod.rs +++ b/support/pkgcheck/src/messages/mod.rs @@ -53,57 +53,57 @@ macro_rules! msgid { } macro_rules! f0001 { - () => { + () => {{ error_occured!(); print!( "{} Specify a directory to check (use option -d)\n", msgid!("F0001") ); - }; + }}; } macro_rules! f0002 { - ($fmt1:expr) => { + ($fmt1:expr) => {{ error_occured!(); print!( "{} Specified directory {} does not exist. Exiting...\n", msgid!("F0002"), $fmt1 ); - }; + }}; } macro_rules! f0003 { - ($fmt1:expr) => { + ($fmt1:expr) => {{ error_occured!(); print!( "{} Specified TDS archive {} does not exist or is no file. Exiting...\n", msgid!("F0003"), $fmt1 ); - }; + }}; } macro_rules! f0004 { - ($fmt1:expr) => { + ($fmt1:expr) => {{ error_occured!(); print!( "{} File {} specified as TDS archive is no zip archive. Exiting...\n", msgid!("F0004"), $fmt1 ); - }; + }}; } macro_rules! f0005 { - ($fmt1:expr) => { + ($fmt1:expr) => {{ error_occured!(); print!( "{} Bad filename {} for the tds.zip archive. Exiting...\n", msgid!("F0005"), $fmt1 ); - }; + }}; } // macro_rules! f0006 { @@ -118,18 +118,18 @@ macro_rules! f0005 { // } macro_rules! f0007 { - ($fmt1:expr) => { + ($fmt1:expr) => {{ error_occured!(); print!( "{} Unable to create temporary directory for unzipping the TDS zip archive: {}. Exiting...\n", msgid!("F0007"), $fmt1 ); - }; + }}; } macro_rules! e0001 { - ($fmt1:expr, $fmt2:expr, $fmt3:expr) => { + ($fmt1:expr, $fmt2:expr, $fmt3:expr) => {{ error_occured!(); print!( "{} Bad character {} ({:#02x}) found in file name {} at offset {}\n", @@ -139,11 +139,11 @@ macro_rules! e0001 { $fmt2, $fmt3 ); - }; + }}; } macro_rules! e0002 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!( "{} File {} has bad permissions: {}\n", @@ -151,102 +151,102 @@ macro_rules! e0002 { $fmt1, $fmt2 ); - }; + }}; } macro_rules! e0003 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} {} is no text file\n", msgid!("E0003"), $fmt); - }; + }}; } macro_rules! e0004 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} Empty directory {} detected\n", msgid!("E0004"), $fmt); - }; + }}; } macro_rules! e0005 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} Empty file {} detected\n", msgid!("E0005"), $fmt); - }; + }}; } macro_rules! e0006 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} Hidden directory {} detected\n", msgid!("E0006"), $fmt); - }; + }}; } macro_rules! e0006t { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} Hidden directory {} detected in TDS zip archive\n", msgid!("E0006"), $fmt ); - }; + }}; } macro_rules! e0007 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} Hidden file {} detected\n", msgid!("E0007"), $fmt); - }; + }}; } macro_rules! e0007t { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} Hidden file {} detected in TDS zip archive\n", msgid!("E0007"), $fmt ); - }; + }}; } macro_rules! e0008 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} Temporary file {} detected\n", msgid!("E0008"), $fmt); - }; + }}; } macro_rules! e0008t { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} Temporary file {} detected in TDS zip archive\n", msgid!("E0008"), $fmt ); - }; + }}; } macro_rules! e0009 { - () => { + () => {{ error_occured!(); print!( "{} One of README/README.md/README.txt must exist\n", msgid!("E0009") ); - }; + }}; } macro_rules! e0010 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} {} is a broken symlink\n", msgid!("E0010"), $fmt); - }; + }}; } macro_rules! e0011 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!( "{} Directory {} has bad permissions: {}\n", @@ -254,72 +254,72 @@ macro_rules! e0011 { $fmt1, $fmt2 ); - }; + }}; } macro_rules! e0012 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} File {} has CRLF line endings\n", msgid!("E0012"), $fmt ); - }; + }}; } macro_rules! e0013 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} {} is a socket special file\n", msgid!("E0013"), $fmt); - }; + }}; } macro_rules! e0014 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} {} is a fifo file\n", msgid!("E0014"), $fmt); - }; + }}; } macro_rules! e0015 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} {} is a block device file\n", msgid!("E0015"), $fmt); - }; + }}; } macro_rules! e0016 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} {} is a character device file\n", msgid!("E0016"), $fmt ); - }; + }}; } macro_rules! e0017 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} PDF error detected in {}\n", msgid!("E0017"), $fmt); - }; + }}; } macro_rules! e0018 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} Unwanted directory {} detected\n", msgid!("E0018"), $fmt ); - }; + }}; } macro_rules! e0019 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!( "{} {} generated by {} exists\n", @@ -327,22 +327,22 @@ macro_rules! e0019 { $fmt1, $fmt2 ); - }; + }}; } macro_rules! e0020 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} Unwanted directory `{}` detected in the top level directory of a TDS archive\n", msgid!("E0020"), $fmt ); - }; + }}; } macro_rules! e0021 { - ($fmt1:expr, $fmt2:expr, $fmt3:expr) => { + ($fmt1:expr, $fmt2:expr, $fmt3:expr) => {{ error_occured!(); print!( "{} File {} : Error reading in line {}: {}\n", @@ -351,25 +351,24 @@ macro_rules! e0021 { $fmt2, $fmt3 ); - }; + }}; } macro_rules! e0022 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!("{} {}: `{}`\n", msgid!("E0022"), $fmt1, $fmt2); - }; + }}; } - macro_rules! e0023 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} {}\n", msgid!("E0023"), $fmt); - }; + }}; } macro_rules! e0024 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!( "{} The TDS zip archive {} has bad permissions: {}\n", @@ -377,33 +376,33 @@ macro_rules! e0024 { $fmt1, $fmt2 ); - }; + }}; } macro_rules! e0025 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} Duplicate names when ignoring letter case for: {}\n", msgid!("E0025"), $fmt ); - }; + }}; } macro_rules! e0026 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} {} : file not in TDS or different in TDS and non-install tree\n", msgid!("E0026"), $fmt ); - }; + }}; } macro_rules! e0027 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!( "{} {}: An I/O error occured -> {}\n", @@ -411,11 +410,11 @@ macro_rules! e0027 { $fmt1, $fmt2 ); - }; + }}; } macro_rules! e0028 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!( "{} No directory {} (= package name) found in path {}\n", @@ -423,11 +422,11 @@ macro_rules! e0028 { $fmt1, $fmt2 ); - }; + }}; } macro_rules! e0029 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!( "{} {}: {} encoding with BOM detected\n", @@ -435,11 +434,11 @@ macro_rules! e0029 { $fmt1, $fmt2 ); - }; + }}; } macro_rules! e0030 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!( "{} Symlink {} points to {} which is outside of the package directory tree\n", @@ -447,22 +446,22 @@ macro_rules! e0030 { $fmt1, $fmt2 ); - }; + }}; } macro_rules! e0031 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} File name {} contains invalid UTF-8 character(s)\n", msgid!("E0031"), $fmt ); - }; + }}; } macro_rules! e0033 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!( "{} Error `{}` when unpacking tds archive {}. Exiting...\n", @@ -470,51 +469,51 @@ macro_rules! e0033 { $fmt2, $fmt1 ); - }; + }}; } macro_rules! e0034 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} Unwanted file `{}` detected in the top level directory of a TDS archive\n", msgid!("E0034"), $fmt ); - }; + }}; } macro_rules! e0035 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} Unwanted TDS archive `{}` detected in package directory tree\n", msgid!("E0035"), $fmt ); - }; + }}; } macro_rules! e0036 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} File `{}` not below `source/` or `doc/` top level directory in TDS zip archive\n", msgid!("E0036"), $fmt ); - }; + }}; } macro_rules! e0037 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!("{} File {} has CR line endings\n", msgid!("E0037"), $fmt); - }; + }}; } macro_rules! e0038 { - ($fmt1:expr, $fmt2:expr, $fmt3:expr, $fmt4:expr) => { + ($fmt1:expr, $fmt2:expr, $fmt3:expr, $fmt4:expr) => {{ error_occured!(); print!( "{} File {} has inconsistent line endings: CR={}, LF={}, CRLF={}\n", @@ -524,60 +523,62 @@ macro_rules! e0038 { $fmt3, $fmt4 ); - }; + }}; } macro_rules! e0039 { - () => { + () => {{ error_occured!(); print!("{} No doc/ directory found\n", msgid!("E0039")); - }; + }}; } macro_rules! e0040 { - () => { + () => {{ error_occured!(); - print!("{} Too few top level directories in the TDS zip archive\n", msgid!("E0040")); - }; + print!( + "{} Too few top level directories in the TDS zip archive\n", + msgid!("E0040") + ); + }}; } macro_rules! e0041 { - () => { + () => {{ error_occured!(); print!("{} One or more map file found for the package but none of them is in a path starting with fonts/map/dvips\n", msgid!("E0041")); - }; + }}; } - macro_rules! w0001 { - ($fmt:expr) => { + ($fmt:expr) => {{ print!( "{} Archive as package file detected: {}\n", msgid!("W0001"), $fmt ); - }; + }}; } macro_rules! w0002 { - () => { + () => {{ print!("{} Duplicate files detected\n", msgid!("W0002"),); - }; + }}; } macro_rules! w0003 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} Same named files detected in the package directory tree: {}\n", msgid!("W0003"), $fmt ); - }; + }}; } macro_rules! w0004 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!( "{} {}: {} encoding with BOM detected\n", @@ -585,115 +586,115 @@ macro_rules! w0004 { $fmt1, $fmt2 ); - }; + }}; } macro_rules! w0005 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!( "{} Very large file {} with size {}MiB detected\n", msgid!("W0005"), $fmt1, $fmt2 - ); - }; + ) + }}; } macro_rules! w0006 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ error_occured!(); print!( "{} Very large file {} with size {}MiB detected in TDS zip archive\n", msgid!("W0006"), $fmt1, $fmt2 - ); - }; + ) + }}; } macro_rules! w0007 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} Empty directory {} detected in TDS zip archive\n", msgid!("W0007"), $fmt ); - }; + }}; } macro_rules! w0008 { - ($fmt:expr) => { + ($fmt:expr) => {{ error_occured!(); print!( "{} Windows file {} has Unix line endings\n", msgid!("W0008"), $fmt ); - }; + }}; } macro_rules! i0002 { - ($fmt:expr) => { + ($fmt:expr) => {{ print!( "{} {} {}\n", msgid!("I0002"), "Checking package files in directory", $fmt ); - }; + }}; } macro_rules! i0003 { - ($fmt:expr) => { + ($fmt:expr) => {{ print!( "{} {} {}\n", msgid!("I0003"), "Checking TDS zip archive", $fmt ); - }; + }}; } macro_rules! i0004 { - ($fmt:expr) => { + ($fmt:expr) => {{ print!( "{} Correcting line endings for file {}\n", msgid!("I0004"), $fmt ); - }; + }}; } macro_rules! i0005 { - ($fmt:expr) => { + ($fmt:expr) => {{ print!( "{} Correcting permissions for {}\n", msgid!("I0005"), $fmt ); - }; + }}; } macro_rules! i0006 { - () => { + () => {{ print!( "{} Files having one of the following file name endings are regarded as temporary\n", msgid!("I0006") ); - }; + }}; } macro_rules! i0007 { - ($fmt1:expr, $fmt2:expr) => { + ($fmt1:expr, $fmt2:expr) => {{ print!( "{} {}: Successfully corrected wrong line endings to {}\n", msgid!("I0007"), $fmt1, $fmt2 ); - }; + }}; } pub fn explains(err: &str) { diff --git a/support/pkgcheck/src/utils.rs b/support/pkgcheck/src/utils.rs index a8f2d56c0f..860b8c223b 100644 --- a/support/pkgcheck/src/utils.rs +++ b/support/pkgcheck/src/utils.rs @@ -15,6 +15,8 @@ use std::sync::atomic::Ordering; use std::fs; +use zip_extensions::*; + #[derive(Debug, Clone, PartialEq, Eq)] pub enum CheckType { Tds, @@ -174,6 +176,13 @@ impl Utils { } } } + + pub fn unzip(&self, zip_archive: &str, out_dir: &str) -> zip::result::ZipResult<()> { + let archive_file = PathBuf::from(zip_archive); + let target_dir = PathBuf::from(out_dir); + + zip_extract(&archive_file, &target_dir) + } } pub fn temp_file_endings() -> Vec<(String, String)> { @@ -267,6 +276,7 @@ pub fn temp_file_endings() -> Vec<(String, String)> { (".w18", "temporary file for the ifplatform package"), (".xdv", "intermediate document"), (".xref", "htlatex related"), + (".xray", "dump of \\show output"), ("~", "a file name ending with ~ (tilde) is temporary anyway"), // ( ".lyx~", "LyX related backup file" ), ]; @@ -414,7 +424,7 @@ pub fn run_cmd(cmd: &str, argument: &[&str]) -> CmdReturn { let output = Command::new(cmd) .args(argument.iter()) .output() - .expect("Failed to execute process"); + .unwrap_or_else(|_| panic!("Failed to execute process `{}`", cmd)); if output.status.success() { CmdReturn { |