From 78532146805619b4616500c2ece2e18a46a8a95e Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 2 May 2020 13:08:20 +0800 Subject: [PATCH] fix clippy --- src/util_file.rs | 14 ++++++-------- src/util_msg.rs | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/util_file.rs b/src/util_file.rs index 894e487..ea4cbd8 100644 --- a/src/util_file.rs +++ b/src/util_file.rs @@ -42,7 +42,7 @@ pub fn get_absolute_path(path: &str) -> Option { pub fn read_file_content(file: &str) -> XResult { match get_absolute_path(file) { - None => return Err(new_box_ioerror(&format!("File not found: {}", file))), + None => Err(new_box_ioerror(&format!("File not found: {}", file))), Some(p) => util_io::read_to_string(&mut fs::File::open(p)?), } } @@ -89,14 +89,12 @@ fn walk_dir_with_depth_check(depth: &mut u32, dir: &P let sub_dir = path_buf.as_path(); if sub_dir.is_file() { func_process_file(&sub_dir); - } else if sub_dir.is_dir() { - if func_filter_dir(&sub_dir) { - *depth += 1; - if let Err(err) = walk_dir_with_depth_check(depth, &sub_dir, func_walk_error, func_process_file, func_filter_dir) { - func_walk_error(&sub_dir, err); - } - *depth -= 1; + } else if sub_dir.is_dir() && func_filter_dir(&sub_dir) { + *depth += 1; + if let Err(err) = walk_dir_with_depth_check(depth, &sub_dir, func_walk_error, func_process_file, func_filter_dir) { + func_walk_error(&sub_dir, err); } + *depth -= 1; } // should process else ? not file, dir } Ok(()) diff --git a/src/util_msg.rs b/src/util_msg.rs index c79247e..c441d2d 100644 --- a/src/util_msg.rs +++ b/src/util_msg.rs @@ -5,7 +5,7 @@ use std::{ lazy_static! { pub static ref IS_ATTY: bool = is_atty(); - static ref PRINT_MESSAGE_LOCK: Arc> = Arc::new(Mutex::new(0)); + static ref PRINT_MESSAGE_LOCK: Arc> = Arc::new(Mutex::new(())); } pub enum MessageType { INFO, OK, WARN, ERROR, DEBUG, } @@ -40,7 +40,7 @@ pub fn print_message_ex(color: Option, h: &str, message: &st let mut lock = PRINT_MESSAGE_LOCK.lock().unwrap(); print_color(color, true, h); println!(" {}", message); - *lock += 1; + *lock = (); } pub fn print_message(mt: MessageType, message: &str) {