summaryrefslogtreecommitdiff
path: root/support/pkgcheck/src/utils.rs
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-05-27 03:01:31 +0000
committerNorbert Preining <norbert@preining.info>2022-05-27 03:01:31 +0000
commit84a5593d3fb9d03aac5677678bcc4c92e8c9a9c4 (patch)
tree0212ba38147bcfe80e5c1a853071a6e6a45b87d7 /support/pkgcheck/src/utils.rs
parent02d941fa9c9895bb08a84ac9afe3559abd1ba8ad (diff)
CTAN sync 202205270301
Diffstat (limited to 'support/pkgcheck/src/utils.rs')
-rw-r--r--support/pkgcheck/src/utils.rs85
1 files changed, 39 insertions, 46 deletions
diff --git a/support/pkgcheck/src/utils.rs b/support/pkgcheck/src/utils.rs
index 860b8c223b..b311453b66 100644
--- a/support/pkgcheck/src/utils.rs
+++ b/support/pkgcheck/src/utils.rs
@@ -1,3 +1,5 @@
+use log::*;
+
use std::fs::read_dir;
use std::fs::read_link;
use std::os::unix::fs::PermissionsExt;
@@ -5,18 +7,17 @@ use std::path::Path;
use std::path::PathBuf;
use walkdir::DirEntry;
+use once_cell::sync::Lazy; // 1.3.1
use regex::Regex;
use std::borrow::Cow;
use std::io;
+use std::fs::File;
use std::process::Command;
-
-use colored::*;
+use zip::result::ZipResult;
use std::sync::atomic::Ordering;
use std::fs;
-use zip_extensions::*;
-
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CheckType {
Tds,
@@ -51,44 +52,28 @@ impl Utils {
true
}
+ // we check for the "good" characters, all other characters yield an
+ // error message
pub fn filename_has_bad_chars(&self, entry: &DirEntry, dir_entry_str: &str) {
let s = entry.file_name().to_str().unwrap();
-
for (i, c) in s.char_indices() {
match c {
- '\x00'..='\x1f' => {
- e0001!(c, dir_entry_str, i);
- }
- ' ' | '!' | '"' | '#' | '$' | '%' | '&' | '\'' => {
- e0001!(c, dir_entry_str, i);
- }
- '(' | ')' | '*' => {
- e0001!(c, dir_entry_str, i);
- }
- '+' | ',' | '-' | '.' => (),
- '0'..='9' => (),
- ':' | ';' | '<' | '=' | '>' | '?' | '@' => {
- e0001!(c, dir_entry_str, i);
- }
- 'A'..='Z' => (),
- '[' | '\\' | ']' | '^' => {
- e0001!(c, dir_entry_str, i);
- }
- '_' => (),
- '`' => {
- e0001!(c, dir_entry_str, i);
- }
- 'a'..='z' => (),
- '{' | '|' | '}' | '~' => {
- e0001!(c, dir_entry_str, i);
- }
- '/' => return,
+ 'A'..='Z'
+ | '0'..='9'
+ | 'a'..='z'
+ | '+'
+ | ','
+ | '-'
+ | '.'
+ | '/'
+ | ':'
+ | '='
+ | '@'
+ | '_' => (),
_ => {
- return {
- e0001!(c, dir_entry_str, i);
- }
+ e0001!(c, dir_entry_str, i);
}
- };
+ }
}
}
@@ -136,9 +121,8 @@ impl Utils {
}
pub fn check_for_temporary_file(&self, dir_entry_str: &str) {
- lazy_static! {
- static ref RE: Regex = regex_temporary_file_endings();
- }
+
+ static RE: Lazy<Regex> = Lazy::new(regex_temporary_file_endings);
if RE.is_match(dir_entry_str) {
match self.kind {
@@ -177,11 +161,18 @@ impl Utils {
}
}
- pub fn unzip(&self, zip_archive: &str, out_dir: &str) -> zip::result::ZipResult<()> {
+ // just copied from zip-extensions-rs
+ pub fn zip_extract(archive_file: &Path, target_dir: &Path) -> ZipResult<()> {
+ let file = File::open(archive_file)?;
+ let mut archive = zip::ZipArchive::new(file)?;
+ archive.extract(target_dir)
+ }
+
+ pub fn unzip(&self, zip_archive: &str, out_dir: &str) -> ZipResult<()> {
let archive_file = PathBuf::from(zip_archive);
- let target_dir = PathBuf::from(out_dir);
+ let target_dir = PathBuf::from(out_dir);
- zip_extract(&archive_file, &target_dir)
+ Utils::zip_extract(&archive_file, &target_dir)
}
}
@@ -281,7 +272,9 @@ pub fn temp_file_endings() -> Vec<(String, String)> {
// ( ".lyx~", "LyX related backup file" ),
];
- v.into_iter().map(|(i, j)| (i.to_string(), j.to_string())).collect()
+ v.into_iter()
+ .map(|(i, j)| (i.to_string(), j.to_string()))
+ .collect()
}
pub fn regex_temporary_file_endings() -> Regex {
@@ -408,8 +401,8 @@ fn owner_match(p: u32, m: u32) -> bool {
}
// Formats a permission value to octal for output
-pub fn perms_to_string(p: u32) -> String {
- format!("{:04o}", p & 0o7777)
+pub fn perms_to_string(p: u32) -> Cow<'static, str> {
+ format!("{:04o}", p & 0o7777).into()
}
pub struct CmdReturn {
@@ -470,7 +463,7 @@ pub fn dirname(entry: &str) -> Option<&str> {
if entry.len() == 1 {
return Some(entry);
}
- return Some(stripped)
+ return Some(stripped);
}
let pos = entry.rfind('/');