1
0
mirror of https://github.com/jht5945/finding.git synced 2025-12-27 13:20:03 +08:00

opt to_str

This commit is contained in:
2020-04-29 08:17:50 +08:00
parent 0e4024337f
commit f9d873659e

View File

@@ -51,27 +51,28 @@ fn find_huge_files(options: &Options, dir_path: &Path) {
let total_file_count_cell = RefCell::new(0u64);
let huge_file_count_cell = RefCell::new(0u64);
let huge_file_size_cell = RefCell::new(0u64);
walk_dir(&dir_path, &|_, _| (/* do not process error */), &|p| {
walk_dir(&dir_path, &|_, _| (/* do not process error */), &|p| { // process file
total_file_count_cell.replace_with(|&mut c| c + 1);
let p_str = match p.to_str() {
Some(s) => s, None => return,
};
match p.metadata() {
Err(err) => if options.verbose {
if let Some(p_str) = p.to_str() {
clear_n_print_message(MessageType::WARN, &format!("Read file {} meta failed: {}", p_str, err));
}
},
Ok(metadata) => {
let len = metadata.len();
if len >= options.parsed_huge_file_size {
huge_file_count_cell.replace_with(|&mut c| c + 1);
huge_file_size_cell.replace_with(|&mut c| c + len);
if let Some(p_str) = p.to_str() {
clear_n_print_message(MessageType::OK, &format!("{} [{}]", p_str, get_display_size(len as i64)));
}
}
},
}
}, &|p| {
if let Some(p_str) = p.to_str() {
}, &|p| { // process path
let p_str = match p.to_str() {
Some(s) => s, None => return false,
};
if options.skip_link_dir && is_symlink(p) {
if options.verbose {
clear_n_print_message(MessageType::INFO, &format!("Skip link dir: {}", p_str));
@@ -79,7 +80,6 @@ fn find_huge_files(options: &Options, dir_path: &Path) {
return false;
}
print_lastline(&get_term_width_message(&format!("Scanning: {}", p_str), 10));
}
true
}).ok();
clear_n_print_message(MessageType::OK, &format!("Total file count: {}, huge file count: {}, total huge file size: {}",
@@ -152,7 +152,7 @@ fn find_text_files(options: &Options, dir_path: &Path) {
let matched_file_count_cell = RefCell::new(0u64);
let total_dir_count_cell = RefCell::new(0u64);
let scaned_dir_count_cell = RefCell::new(0u64);
walk_dir(&dir_path, &|_, _| (/* do not process error */), &|p| {
walk_dir(&dir_path, &|_, _| (/* do not process error */), &|p| { // process file
total_file_count_cell.replace_with(|&mut c| c + 1);
let p_str = match p.to_str() {
Some(s) => s, None => return,
@@ -173,9 +173,11 @@ fn find_text_files(options: &Options, dir_path: &Path) {
if match_lines(p_str, &file_content, &options) {
matched_file_count_cell.replace_with(|&mut c| c + 1);
}
}, &|p| {
}, &|p| { // process path
total_dir_count_cell.replace_with(|&mut c| c + 1);
if let Some(p_str) = p.to_str() {
let p_str = match p.to_str() {
Some(s) => s, None => return false,
};
if (!options.scan_dot_git_dir) && p_str.ends_with("/.git") {
if options.verbose { clear_n_print_message(MessageType::INFO, &format!("Skip .git dir: {}", p_str)); }
return false;
@@ -194,7 +196,6 @@ fn find_text_files(options: &Options, dir_path: &Path) {
}
scaned_dir_count_cell.replace_with(|&mut c| c + 1);
print_lastline(&get_term_width_message(&format!("Scanning: {}", p_str), 10));
}
true
}).ok();
print_lastline(EMPTY);