From d94b7a8c132734a1bc4046d54a75c7882c4c2619 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Wed, 2 Oct 2019 03:01:29 +0000 Subject: CTAN sync 201910020301 --- support/pkgcheck/src/main.rs | 40 ++++++++++++++++++++++-------- support/pkgcheck/src/messages/mod.rs | 28 +++++++++++++++++++++ support/pkgcheck/src/messages/warningsd.rs | 22 ++++++++++++++++ 3 files changed, 80 insertions(+), 10 deletions(-) (limited to 'support/pkgcheck/src') diff --git a/support/pkgcheck/src/main.rs b/support/pkgcheck/src/main.rs index a7be277330..c69423252d 100644 --- a/support/pkgcheck/src/main.rs +++ b/support/pkgcheck/src/main.rs @@ -103,17 +103,17 @@ fn filename_has_bad_chars(entry: &DirEntry) -> Option<(usize, char)> { for (i, c) in s.char_indices() { match c { - '\x00'...'\x1f' => return Some((i, c)), + '\x00'..='\x1f' => return Some((i, c)), ' ' | '!' | '"' | '#' | '$' | '%' | '&' | '\'' => return Some((i, c)), '(' | ')' | '*' => return Some((i, c)), '+' | ',' | '-' | '.' => (), - '0'...'9' => (), + '0'..='9' => (), ':' | ';' | '<' | '=' | '>' | '?' | '@' => return Some((i, c)), - 'A'...'Z' => (), + 'A'..='Z' => (), '[' | '\\' | ']' | '^' => return Some((i, c)), '_' => (), '`' => return Some((i, c)), - 'a'...'z' => (), + 'a'..='z' => (), '{' | '|' | '}' | '~' => return Some((i, c)), '/' => return None, _ => return Some((i, c)), @@ -519,7 +519,6 @@ fn check_generated_files(entry: &str, generated: &mut HashMap) } Err(e) => println!("Error opening file {}: {:?}", entry, e), } - return; } fn x_bit_set(p: u32) -> bool { @@ -582,6 +581,19 @@ fn check_tds_archive( } }; + // We have a discrepancy between + // TDS zip archive name: babel-base.tds.zip + // and package name: babel + // which yields a false test when checking for the package name + // the path names of the TDS zip archive files. + // Therefore, we correct here. + let real_pkg_name = if pkg_name == "babel-base" { + "babel" + } else { + pkg_name + }; + + let tmp_dir = TempDir::new("pkgcheck")?; let tmp_dir_offset = tmp_dir.path().to_str().unwrap().len() + 1; unzip_tds_archive(tds_zip, tmp_dir.path().to_str().unwrap()); @@ -682,13 +694,16 @@ fn check_tds_archive( if is_temporary_file(&dir_entry_str) { e0008!(dir_entry_display); } + if fsize > 40 * 1024 * 1024 { + w0006!(dir_entry_display, fsize / 1024 / 1024); + } // if the path doesn't contain a man page... if dir_entry_str.find("/man/").is_none() { - let pkg_name_s = format!("/{}/", pkg_name); + let pkg_name_s = format!("/{}/", real_pkg_name); // ...then we want to have the package name in the path if dir_entry_str.find(&pkg_name_s).is_none() { - e0028!(pkg_name, dir_entry_display); + e0028!(real_pkg_name, dir_entry_display); } } @@ -833,8 +848,8 @@ fn check_package(root: &str, tds_zip: &Option) -> Option { i0002!(root); // This hash contains all package file names. - // - // PathBuf: the full path starting at the directory specified at the command line + // + // PathBuf: the full path starting at the directory specified at the command line // Metadata: the meta data of the file // String: the file name without any directory part // ReadmeKind: is it a certain README, file or symlink? @@ -871,7 +886,7 @@ fn check_package(root: &str, tds_zip: &Option) -> Option { continue; } - // this is the file_name without the directory part + // this is the file_name without the directory part // unwrap() is ok here as we covered potential UTF-8 related errors // above in the definition of dir_entry_str let file_name = dir_entry.file_name().to_str().unwrap().to_string(); @@ -992,6 +1007,7 @@ fn check_package(root: &str, tds_zip: &Option) -> Option { .push(PathBuf::from(dir_entry_str)); } + // detecting large files in package directory if is_readme(&dir_entry) { // We want to deal with README files only if they are @@ -1084,6 +1100,10 @@ fn check_package(root: &str, tds_zip: &Option) -> Option { e0005!(dir_entry_str); continue; } + if fsize > 40 * 1024 * 1024 { + w0005!(dir_entry_str, fsize / 1024 / 1024); + continue; + } let p = get_perms(&path); if !owner_has(p, 4) { diff --git a/support/pkgcheck/src/messages/mod.rs b/support/pkgcheck/src/messages/mod.rs index c63b6e2cec..0a77e14c1e 100644 --- a/support/pkgcheck/src/messages/mod.rs +++ b/support/pkgcheck/src/messages/mod.rs @@ -476,6 +476,30 @@ macro_rules! w0004 { }; } +macro_rules! w0005 { + ($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) => { + error_occured!(); + print!( + "{} Very large file {} with size {}MiB detected in TDS zip archive\n", + msgid!("W0006"), + $fmt1, + $fmt2 + ); + }; +} + macro_rules! i0002 { ($fmt:expr) => { print!( @@ -593,6 +617,8 @@ pub fn explains(err: &str) { "W0002" => w0002d(), "W0003" => w0003d(), "W0004" => w0004d(), + "W0005" => w0005d(), + "W0006" => w0006d(), e => println!( "F0006 Unknown error code `{}` specified with option -e resp. --explain. Exiting...", @@ -654,4 +680,6 @@ pub fn explains_all() { explains("W0002"); explains("W0003"); explains("W0004"); + explains("W0005"); + explains("W0006"); } diff --git a/support/pkgcheck/src/messages/warningsd.rs b/support/pkgcheck/src/messages/warningsd.rs index 588144968d..b8a1aa8ef3 100644 --- a/support/pkgcheck/src/messages/warningsd.rs +++ b/support/pkgcheck/src/messages/warningsd.rs @@ -56,3 +56,25 @@ that in some future time this could be reagarded as an error. ) } +pub fn w0005d() { + println!( + r#" +W0005 -- Very large file with size detected in package + +(Experimental) We issue the message if there is a file is larger than +40MiB in the package directory tree. +"# + ) +} + +pub fn w0006d() { + println!( + r#" +W0006 -- Very large file with size detected in TDS zip archive + +(Experimental) We issue the message if there is a file larger than 40MiB +in the TDS zip archive. +"# + ) +} + -- cgit v1.2.3