Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
Add tracking of empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Stein committed Feb 19, 2021
1 parent 1084975 commit 9ff8fba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::io::Write;
use super::objects;

static OUTPUT_FILE: &'static str = "fs-scan_output.csv";
static FILE_FIRST_LINE: &'static str = "Path,Files,Directories,4K,4K_8K,8K_16K,16K_32K,32K_64K,64K_128K,128K_256K,256K_512K,512K_1M,1M_10M,10M_100M,100M_1G,1G";
static FILE_FIRST_LINE: &'static str = "Path,Files,Directories,0,less_than_4K,4K_8K,8K_16K,16K_32K,32K_64K,64K_128K,128K_256K,256K_512K,512K_1M,1M_10M,10M_100M,100M_1G,1G";

pub fn save(res: &objects::Result) {
match check_file() {
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ fn main() {
println!("Scan took {}", HumanDuration(starting_point.elapsed()));
println!("Files -> {}", nice_number(res.files));
println!("Directories -> {}", nice_number(res.directories));
println!("Empty files -> {}", nice_number(res.empty_file));
println!("Less than 4K -> {}", nice_number(res.less_than_4_k));
println!(
"Between 4KB and 8KB -> {}",
Expand Down Expand Up @@ -218,7 +219,9 @@ fn handle_dir(path: PathBuf, ch: Sender<objects::ChanResponse>, bar: &ProgressBa
}

fn handle_file(len: u64, res: &mut objects::Result) {
if len < 4_000 {
if len == 0 {
res.empty_file = res.empty_file + 1;
} else if len < 4_000 {
res.less_than_4_k = res.less_than_4_k + 1;
} else if len < 8_000 {
res.between_4_k_8_k = res.between_4_k_8_k + 1;
Expand Down
5 changes: 4 additions & 1 deletion src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub struct Result {
pub path: String,
pub files: usize,
pub directories: usize,
pub empty_file: usize,
pub less_than_4_k: usize,
pub between_4_k_8_k: usize,
pub between_8_k_16_k: usize,
Expand All @@ -25,6 +26,7 @@ pub fn build_result(path: &str) -> Result {
files: 0,
directories: 0,

empty_file: 0,
less_than_4_k: 0,
between_4_k_8_k: 0,
between_8_k_16_k: 0,
Expand All @@ -44,10 +46,11 @@ pub fn build_result(path: &str) -> Result {
impl Result {
pub fn result_to_string(&self) -> String {
format!(
"{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}",
"{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}",
&self.path,
&self.files,
&self.directories,
&self.empty_file,
&self.less_than_4_k,
&self.between_4_k_8_k,
&self.between_8_k_16_k,
Expand Down

0 comments on commit 9ff8fba

Please sign in to comment.