1
0
mirror of https://github.com/jht5945/finding.git synced 2025-12-29 22:20:05 +08:00

add skip link dir

This commit is contained in:
2019-08-03 14:24:23 +08:00
parent 29a1b995ec
commit 8c933a32aa
3 changed files with 39 additions and 10 deletions

16
Cargo.lock generated
View File

@@ -24,7 +24,7 @@ dependencies = [
[[package]] [[package]]
name = "backtrace" name = "backtrace"
version = "0.3.33" version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -99,7 +99,7 @@ name = "failure"
version = "0.1.5" version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"backtrace 0.3.33 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@@ -110,7 +110,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.41 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@@ -217,7 +217,7 @@ dependencies = [
[[package]] [[package]]
name = "rust_util" name = "rust_util"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/jht5945/rust_util#4d38c5150c8f0ee98eea84bb9a457f57bcba0c82" source = "git+https://github.com/jht5945/rust_util#f8dab07f6ca18edddc8beec85d5330225b6a36ae"
dependencies = [ dependencies = [
"term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@@ -234,7 +234,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "syn" name = "syn"
version = "0.15.41" version = "0.15.42"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -249,7 +249,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.41 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@@ -311,7 +311,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392" "checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392"
"checksum argparse 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3f8ebf5827e4ac4fd5946560e6a99776ea73b596d80898f357007317a7141e47" "checksum argparse 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3f8ebf5827e4ac4fd5946560e6a99776ea73b596d80898f357007317a7141e47"
"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba" "checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba"
"checksum backtrace 0.3.33 (registry+https://github.com/rust-lang/crates.io-index)" = "88fb679bc9af8fa639198790a77f52d345fe13656c08b43afa9424c206b731c6" "checksum backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)" = "b5164d292487f037ece34ec0de2fcede2faa162f085dd96d2385ab81b12765ba"
"checksum backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "82a830b4ef2d1124a711c71d263c5abdc710ef8e907bd508c88be475cebc422b" "checksum backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "82a830b4ef2d1124a711c71d263c5abdc710ef8e907bd508c88be475cebc422b"
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" "checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
"checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" "checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400"
@@ -338,7 +338,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rust_util 0.1.0 (git+https://github.com/jht5945/rust_util)" = "<none>" "checksum rust_util 0.1.0 (git+https://github.com/jht5945/rust_util)" = "<none>"
"checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af"
"checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" "checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8"
"checksum syn 0.15.41 (registry+https://github.com/rust-lang/crates.io-index)" = "5f48d3b9d3d5ee64217007ead81e80d40674c80e930cf53ed089f0f809fae31e" "checksum syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)" = "eadc09306ca51a40555dd6fc2b415538e9e18bc9f870e47b1a524a79fe2dcf5e"
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" "checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
"checksum term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" "checksum term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42"
"checksum term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e5b9a66db815dcfd2da92db471106457082577c3c278d4138ab3e3b4e189327" "checksum term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e5b9a66db815dcfd2da92db471106457082577c3c278d4138ab3e3b4e189327"

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "finding" name = "finding"
version = "0.1.0" version = "0.1.1"
authors = ["Hatter Jiang <jht5945@gmail.com>"] authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018" edition = "2018"

View File

@@ -63,7 +63,11 @@ fn get_term_width_message(message: &str, left: usize) -> String {
} }
fn find_huge_files(options: &Options, dir_path: &Path) { 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| {
total_file_count_cell.replace_with(|&mut c| c + 1);
match p.metadata() { match p.metadata() {
Err(err) => { Err(err) => {
if options.verbose { if options.verbose {
@@ -78,6 +82,8 @@ fn find_huge_files(options: &Options, dir_path: &Path) {
Ok(metadata) => { Ok(metadata) => {
let len = metadata.len(); let len = metadata.len();
if len >= options.parsed_huge_file_size { 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);
match p.to_str() { match p.to_str() {
None => (), None => (),
Some(p_str) => { Some(p_str) => {
@@ -91,11 +97,24 @@ fn find_huge_files(options: &Options, dir_path: &Path) {
}, &|p| { }, &|p| {
match p.to_str() { match p.to_str() {
None => (), None => (),
Some(p_str) => print_lastline(&get_term_width_message(&format!("Scanning: {}", p_str), 10)), Some(p_str) => {
if options.skip_link_dir && is_symlink(p) {
if options.verbose {
print_lastline("");
print_message(MessageType::INFO, &format!("Skip link dir: {}", p_str));
}
return false;
}
print_lastline(&get_term_width_message(&format!("Scanning: {}", p_str), 10))
},
} }
true true
}).unwrap_or(()); }).unwrap_or(());
print_lastline(""); print_lastline("");
print_message(MessageType::OK, &format!("Total file count: {}, huge file count: {}, huge file size: {}",
total_file_count_cell.into_inner(),
huge_file_count_cell.into_inner(),
huge_file_size_cell.into_inner()))
} }
fn read_file_content(file: &Path, large_file_len: u64) -> XResult<String> { fn read_file_content(file: &Path, large_file_len: u64) -> XResult<String> {
@@ -246,6 +265,13 @@ fn find_text_files(options: &Options, dir_path: &Path) {
} }
return false; return false;
} }
if options.skip_link_dir && is_symlink(p) {
if options.verbose {
print_lastline("");
print_message(MessageType::INFO, &format!("Skip link dir: {}", p_str));
}
return false;
}
scaned_dir_count_cell.replace_with(|&mut c| c + 1); scaned_dir_count_cell.replace_with(|&mut c| c + 1);
print_lastline(&get_term_width_message(&format!("Scanning: {}", p_str), 10)) print_lastline(&get_term_width_message(&format!("Scanning: {}", p_str), 10))
}, },
@@ -276,6 +302,7 @@ struct Options {
large_line_size: String, large_line_size: String,
parsed_large_line_size: u64, parsed_large_line_size: u64,
scan_dot_git: bool, scan_dot_git: bool,
skip_link_dir: bool,
verbose: bool, verbose: bool,
search_text: String, search_text: String,
} }
@@ -295,6 +322,7 @@ fn main() {
large_line_size: String::from("10KB"), large_line_size: String::from("10KB"),
parsed_large_line_size: 0u64, parsed_large_line_size: 0u64,
scan_dot_git: false, scan_dot_git: false,
skip_link_dir: false,
verbose: false, verbose: false,
search_text: String::new(), search_text: String::new(),
}; };
@@ -310,6 +338,7 @@ fn main() {
ap.refer(&mut options.filter_large_line).add_option(&["--filter-large-line"], StoreTrue, "Filter large line"); ap.refer(&mut options.filter_large_line).add_option(&["--filter-large-line"], StoreTrue, "Filter large line");
ap.refer(&mut options.large_line_size).add_option(&["--large-line-size"], Store, "Large line, default 10KB"); ap.refer(&mut options.large_line_size).add_option(&["--large-line-size"], Store, "Large line, default 10KB");
ap.refer(&mut options.scan_dot_git).add_option(&["--scan-dot-git"], StoreTrue, "Scan dot git"); ap.refer(&mut options.scan_dot_git).add_option(&["--scan-dot-git"], StoreTrue, "Scan dot git");
ap.refer(&mut options.skip_link_dir).add_option(&["--skip-link-dir"], StoreTrue, "Skip link dir");
ap.refer(&mut options.version).add_option(&["-v", "--version"], StoreTrue, "Print version"); ap.refer(&mut options.version).add_option(&["-v", "--version"], StoreTrue, "Print version");
ap.refer(&mut options.verbose).add_option(&["--verbose"], StoreTrue, "Verbose"); ap.refer(&mut options.verbose).add_option(&["--verbose"], StoreTrue, "Verbose");
ap.refer(&mut options.search_text).add_argument("SEARCH TEXT", Store, "Search text"); ap.refer(&mut options.search_text).add_argument("SEARCH TEXT", Store, "Search text");