move eprints to debug, catch err on file open
This commit is contained in:
parent
59e22e31c8
commit
4a04560124
3 changed files with 19 additions and 18 deletions
|
@ -8,15 +8,6 @@ pub fn warning(msg: String) {
|
|||
eprintln!("{} {}", "warning:".yellow().bold(), msg)
|
||||
}
|
||||
|
||||
pub fn verbose(level: u8, msg_lvl: u8, msg: String) {
|
||||
if level < msg_lvl {
|
||||
return;
|
||||
};
|
||||
let mut prefix = String::new();
|
||||
for _ in 0..msg_lvl {
|
||||
prefix += "=";
|
||||
}
|
||||
|
||||
prefix += "> ";
|
||||
eprintln!("{}{}", prefix.purple().bold(), msg);
|
||||
pub fn debug(msg: String) {
|
||||
eprintln!("{} {}", "debug:".purple().bold(), msg);
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ use md5::Md5;
|
|||
use std::fs::File;
|
||||
use std::io;
|
||||
|
||||
use crate::common;
|
||||
|
||||
pub fn hash_md5(mut file: File) -> String {
|
||||
let mut hasher = Md5::new();
|
||||
_ = io::copy(&mut file, &mut hasher);
|
||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -101,14 +101,26 @@ fn hash(info: ThreadInfo) -> Result<(), String> {
|
|||
};
|
||||
|
||||
if !*info.quiet && *info.debug {
|
||||
eprintln!(
|
||||
common::debug(format!(
|
||||
"thread {} is hashing file '{}'",
|
||||
info.thread_id,
|
||||
filename.as_path().display()
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
let file = File::open(&filename).unwrap();
|
||||
if filename.is_dir() {
|
||||
common::error(format!("{}: Is a directory", filename.as_path().display()));
|
||||
continue;
|
||||
}
|
||||
|
||||
let file = match File::open(&filename) {
|
||||
Err(e) => {
|
||||
common::error(format!("{}: {}", filename.as_path().display(), e));
|
||||
continue;
|
||||
},
|
||||
Ok(f) => f
|
||||
};
|
||||
|
||||
let res = match &*info.algorithm.as_str() {
|
||||
"sha256" => hashers::hash_sha256(file),
|
||||
"sha384" => hashers::hash_sha384(file),
|
||||
|
@ -123,7 +135,7 @@ fn hash(info: ThreadInfo) -> Result<(), String> {
|
|||
}
|
||||
|
||||
if !*info.quiet && *info.debug {
|
||||
eprintln!("thread {} has ran out of work", info.thread_id);
|
||||
common::debug(format!("thread {} has ran out of work", info.thread_id));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -150,7 +162,7 @@ fn main() {
|
|||
};
|
||||
|
||||
if args.debug {
|
||||
eprintln!("Starting psha using algorithm {} with {} threads", args.algorithm, cpus)
|
||||
common::debug(format!("Starting psha using algorithm {} with {} threads", args.algorithm, cpus));
|
||||
}
|
||||
|
||||
if UNSECURE_ALGORITHMS.contains(&args.algorithm.as_str()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue