From dc41a2bc7216e658b3df25f0d9b5afc10e6e1114 Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Wed, 1 May 2024 15:36:26 +0900 Subject: [PATCH 01/15] wip(Report): structs for report + new fn --- src/report.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/report.rs diff --git a/src/report.rs b/src/report.rs new file mode 100644 index 0000000..9a72179 --- /dev/null +++ b/src/report.rs @@ -0,0 +1,25 @@ +use std::collections::HashSet; + +#[derive(Debug, PartialEq, Eq, Hash)] +struct ChecksumReport { + file_name: String, + matching: bool, + got: String, +} + +#[derive(Debug, PartialEq, Eq, Hash)] +struct Report { + files_checksums: HashSet, +} + +impl Report { + pub fn new() -> Self { + Self { + files_checksums: HashSet::new(), + } + } + + pub fn set_file_checksum(&mut self, checksum_report: ChecksumReport) { + self.files_checksums + } +} From d8a633f1bf29e3d0bade9214d54b9eecd8597e9c Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Wed, 1 May 2024 16:26:53 +0900 Subject: [PATCH 02/15] feat(Report): can generate a file report, yay --- Cargo.toml | 1 + src/main.rs | 11 ++++++++--- src/report.rs | 45 ++++++++++++++++++++++++++++++++++++++------- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5077fe3..5eba4ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ hex = "0.4.3" serde = { version = "1.0.198", features = ["derive"] } sha2 = "0.10.8" thiserror = "1.0.59" +time = "0.3.36" toml = "0.8.12" tracing = "0.1.40" tracing-subscriber = "0.3.18" diff --git a/src/main.rs b/src/main.rs index af340ff..78bfe6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ use config::Config; use file_integrity::FileIntegrity; +use report::Report; mod config; mod file_integrity; +mod report; fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::fmt() @@ -9,9 +11,12 @@ fn main() -> anyhow::Result<()> { .init(); match FileIntegrity::new(&Config::new()?) { - Ok(app) => { - let res = app.check(); - println!("File check result: {}", res); + Ok(_app) => { + // let res = app.check(); + // println!("File check result: {}", res); + + let report = Report::new(); + report.generate_report()?; } Err(e) => { tracing::error!("Failed to initialize the application. Error: {:?}", e); diff --git a/src/report.rs b/src/report.rs index 9a72179..91a817c 100644 --- a/src/report.rs +++ b/src/report.rs @@ -1,25 +1,56 @@ -use std::collections::HashSet; +use std::{collections::HashSet, io::Write}; -#[derive(Debug, PartialEq, Eq, Hash)] -struct ChecksumReport { +use thiserror::Error; +use anyhow::Result; +use time::OffsetDateTime; + +/// A specific report of a file's checksum results. +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub struct ChecksumReport { file_name: String, matching: bool, got: String, } -#[derive(Debug, PartialEq, Eq, Hash)] -struct Report { +/// A report of all the tool's analysis results. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Report { files_checksums: HashSet, } impl Report { + /// Creates an empty report. pub fn new() -> Self { Self { files_checksums: HashSet::new(), } } - pub fn set_file_checksum(&mut self, checksum_report: ChecksumReport) { - self.files_checksums + /// Adds a file's checksum results to the report. + pub fn set_file_checksum(&mut self, checksum_report: &ChecksumReport) { + self.files_checksums.insert(checksum_report.clone()); + } + + /// Writes the report to disk. + pub fn generate_report(&self) -> Result<(), ReportError> { + const REPORT_FOLDER: &str = "./results/"; + + let utc_date = OffsetDateTime::now_utc().to_string(); + let file_path = format!("{}{}", REPORT_FOLDER, utc_date); + + std::fs::create_dir_all(REPORT_FOLDER)?; + + let mut file = std::fs::File::create(file_path)?; + file.write("hello world".as_bytes())?; + + Ok(()) + } } + +/// An error that can occur when generating a report. +#[derive(Debug, Error)] +pub enum ReportError { + #[error("Failed to build report due to IO error: {0}")] + IoError(#[from] std::io::Error), +} From 1ba432e10bbfead0ce09f15e52c6cb6d449e4972 Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Wed, 1 May 2024 16:27:15 +0900 Subject: [PATCH 03/15] chore(Cargo.toml): added urlencoding crate --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 5eba4ef..1026ae7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ time = "0.3.36" toml = "0.8.12" tracing = "0.1.40" tracing-subscriber = "0.3.18" +urlencoding = "2.1.3" From 191f9b67a7d856a7e222f7a95809dd18c8232ff7 Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Wed, 1 May 2024 16:36:53 +0900 Subject: [PATCH 04/15] chore(.gitignore): added results folder to ignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 0e57224..b3f32b4 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ Cargo.lock # MacOS .DS_Store *.dSYM + +# App related +results/ From 7a0f6a5879cb46466b15db40326041e4e1e30180 Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Wed, 1 May 2024 16:37:14 +0900 Subject: [PATCH 05/15] feat(Report): file name is date + time UTC --- src/report.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/report.rs b/src/report.rs index 91a817c..9517c35 100644 --- a/src/report.rs +++ b/src/report.rs @@ -35,8 +35,22 @@ impl Report { pub fn generate_report(&self) -> Result<(), ReportError> { const REPORT_FOLDER: &str = "./results/"; - let utc_date = OffsetDateTime::now_utc().to_string(); - let file_path = format!("{}{}", REPORT_FOLDER, utc_date); + let utc_date = OffsetDateTime::now_utc(); + let utc_string = { + let mut s = String::new(); + + // date + s.push_str(&utc_date.date().to_string()); + s.push('_'); + // time + let time = utc_date.time(); + s.push_str(&time.hour().to_string()); + s.push(':'); + s.push_str(&time.minute().to_string()); + s + }; + + let file_path = format!("{}{}.report", REPORT_FOLDER, utc_string); std::fs::create_dir_all(REPORT_FOLDER)?; From d43756ec68db33bda9bf71ce0dd373258a19a6b8 Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Wed, 1 May 2024 16:45:27 +0900 Subject: [PATCH 06/15] refactor(Report): added whitespace --- src/report.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/report.rs b/src/report.rs index 9517c35..df48628 100644 --- a/src/report.rs +++ b/src/report.rs @@ -7,7 +7,7 @@ use time::OffsetDateTime; /// A specific report of a file's checksum results. #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct ChecksumReport { - file_name: String, + file_path: String, matching: bool, got: String, } @@ -42,11 +42,13 @@ impl Report { // date s.push_str(&utc_date.date().to_string()); s.push('_'); + // time let time = utc_date.time(); s.push_str(&time.hour().to_string()); s.push(':'); s.push_str(&time.minute().to_string()); + s }; @@ -54,8 +56,10 @@ impl Report { std::fs::create_dir_all(REPORT_FOLDER)?; + + let mut file = std::fs::File::create(file_path)?; - file.write("hello world".as_bytes())?; + file.write("hello world\n".as_bytes())?; Ok(()) From 80999038e452088b2e8942d6523e475096017e83 Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Wed, 1 May 2024 16:45:45 +0900 Subject: [PATCH 07/15] chore(Cargo.toml): added bincode crate --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 1026ae7..f172315 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] anyhow = "1.0.82" +bincode = "1.3.3" hex = "0.4.3" serde = { version = "1.0.198", features = ["derive"] } sha2 = "0.10.8" From 62a314ad8c853c140589d512f33ade7b0306f5c7 Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Sat, 4 May 2024 07:42:40 +0900 Subject: [PATCH 08/15] chore(Report): removed trailing spaces due to VSCode! --- src/report.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/report.rs b/src/report.rs index df48628..83181e5 100644 --- a/src/report.rs +++ b/src/report.rs @@ -1,7 +1,7 @@ use std::{collections::HashSet, io::Write}; -use thiserror::Error; use anyhow::Result; +use thiserror::Error; use time::OffsetDateTime; /// A specific report of a file's checksum results. @@ -42,27 +42,24 @@ impl Report { // date s.push_str(&utc_date.date().to_string()); s.push('_'); - + // time let time = utc_date.time(); s.push_str(&time.hour().to_string()); s.push(':'); s.push_str(&time.minute().to_string()); - + s }; - + let file_path = format!("{}{}.report", REPORT_FOLDER, utc_string); std::fs::create_dir_all(REPORT_FOLDER)?; - - let mut file = std::fs::File::create(file_path)?; file.write("hello world\n".as_bytes())?; Ok(()) - } } From d17b25ea92acd41566893dc8c42a1e3892555170 Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Sat, 4 May 2024 10:36:36 +0900 Subject: [PATCH 09/15] feat(Report): generated report now has incorrect checksum list --- src/file_integrity.rs | 14 ++++++++++++-- src/main.rs | 6 +++--- src/report.rs | 21 ++++++++++++++++++++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/file_integrity.rs b/src/file_integrity.rs index 555b48e..e4ba6f5 100644 --- a/src/file_integrity.rs +++ b/src/file_integrity.rs @@ -6,7 +6,10 @@ use std::{ }; use thiserror::Error; -use crate::config::Config; +use crate::{ + config::Config, + report::{ChecksumReport, Report}, +}; /// TODO: how to retrieve the actual pure checksum (reference value) @@ -106,12 +109,19 @@ impl FileIntegrity { } /// Checking if EVERY file is actully matching the expected checksum - pub fn check(&self) -> bool { + pub fn check(&self, report: &mut Report) -> bool { let mut res = true; for f in self.game_files.iter() { if !f.checksums_match() { + report.set_file_checksum(&ChecksumReport::new( + f.path.to_str().unwrap().to_string(), + false, + f.compute_real_checksum().to_string(), // wouldn't it be better to change + // return type instead of calling twice this fn? + )); res = false; + return res; // to be removed later, this is to stop the loop } } res diff --git a/src/main.rs b/src/main.rs index 78bfe6b..78c3f92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,11 +11,11 @@ fn main() -> anyhow::Result<()> { .init(); match FileIntegrity::new(&Config::new()?) { - Ok(_app) => { - // let res = app.check(); + Ok(app) => { + let mut report = Report::new(); + let _res = app.check(&mut report); // println!("File check result: {}", res); - let report = Report::new(); report.generate_report()?; } Err(e) => { diff --git a/src/report.rs b/src/report.rs index 83181e5..54a4803 100644 --- a/src/report.rs +++ b/src/report.rs @@ -12,6 +12,16 @@ pub struct ChecksumReport { got: String, } +impl ChecksumReport { + pub fn new(file_path: String, matching: bool, got: String) -> Self { + Self { + file_path, + matching, + got, + } + } +} + /// A report of all the tool's analysis results. #[derive(Clone, Debug, PartialEq, Eq)] pub struct Report { @@ -57,7 +67,16 @@ impl Report { std::fs::create_dir_all(REPORT_FOLDER)?; let mut file = std::fs::File::create(file_path)?; - file.write("hello world\n".as_bytes())?; + + writeln!(file, "Report generated on: {}\n\n## Checksums", utc_date)?; + + for checksum_report in &self.files_checksums { + writeln!( + file, + "[incorrect] --> {}: {}", + checksum_report.file_path, checksum_report.got + )?; + } Ok(()) } From edc601f3d5cebd94753514b041e582541019ed5a Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Sat, 4 May 2024 11:43:53 +0900 Subject: [PATCH 10/15] refactor(report): removed the ChecksumReport::new --- src/file_integrity.rs | 9 +++------ src/report.rs | 18 ++++++------------ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/file_integrity.rs b/src/file_integrity.rs index e4ba6f5..318f181 100644 --- a/src/file_integrity.rs +++ b/src/file_integrity.rs @@ -6,10 +6,7 @@ use std::{ }; use thiserror::Error; -use crate::{ - config::Config, - report::{ChecksumReport, Report}, -}; +use crate::{config::Config, report::Report}; /// TODO: how to retrieve the actual pure checksum (reference value) @@ -114,12 +111,12 @@ impl FileIntegrity { for f in self.game_files.iter() { if !f.checksums_match() { - report.set_file_checksum(&ChecksumReport::new( + report.set_file_checksum( f.path.to_str().unwrap().to_string(), false, f.compute_real_checksum().to_string(), // wouldn't it be better to change // return type instead of calling twice this fn? - )); + ); res = false; return res; // to be removed later, this is to stop the loop } diff --git a/src/report.rs b/src/report.rs index 54a4803..fb10dcf 100644 --- a/src/report.rs +++ b/src/report.rs @@ -12,16 +12,6 @@ pub struct ChecksumReport { got: String, } -impl ChecksumReport { - pub fn new(file_path: String, matching: bool, got: String) -> Self { - Self { - file_path, - matching, - got, - } - } -} - /// A report of all the tool's analysis results. #[derive(Clone, Debug, PartialEq, Eq)] pub struct Report { @@ -37,8 +27,12 @@ impl Report { } /// Adds a file's checksum results to the report. - pub fn set_file_checksum(&mut self, checksum_report: &ChecksumReport) { - self.files_checksums.insert(checksum_report.clone()); + pub fn set_file_checksum(&mut self, file_path: String, matching: bool, got: String) { + self.files_checksums.insert(ChecksumReport { + file_path, + matching, + got, + }); } /// Writes the report to disk. From 8f5d39b70098a28cf25f36365662c81ab849056b Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Sat, 4 May 2024 11:49:13 +0900 Subject: [PATCH 11/15] chore(report): added TODO comment for the future --- src/report.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/report.rs b/src/report.rs index fb10dcf..a0464ce 100644 --- a/src/report.rs +++ b/src/report.rs @@ -13,6 +13,7 @@ pub struct ChecksumReport { } /// A report of all the tool's analysis results. +/// TODO: Add PC specs, connected hardware, PID of opened programs, etc. #[derive(Clone, Debug, PartialEq, Eq)] pub struct Report { files_checksums: HashSet, From 473101c41a73cededc721b799dbb29ad8063b865 Mon Sep 17 00:00:00 2001 From: Barrett Date: Fri, 3 May 2024 21:54:29 -0500 Subject: [PATCH 12/15] ci: Only run Actions on a push --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd45e70..b053540 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,6 @@ name: Rust CI on: push: - pull_request: env: CARGO_TERM_COLOR: always From 8dc8db3a32ebec86ba7e4c29f87ad7dbd5e41371 Mon Sep 17 00:00:00 2001 From: Barrett Date: Fri, 3 May 2024 22:53:59 -0500 Subject: [PATCH 13/15] refactor(report): Clarified checksum handling letsssss goooooo oooooo simon --- src/file_integrity.rs | 76 +++++++++++++++++++++++++++++-------------- src/main.rs | 6 ++-- src/report.rs | 29 +++++++---------- 3 files changed, 66 insertions(+), 45 deletions(-) diff --git a/src/file_integrity.rs b/src/file_integrity.rs index 318f181..1fe3480 100644 --- a/src/file_integrity.rs +++ b/src/file_integrity.rs @@ -6,16 +6,21 @@ use std::{ }; use thiserror::Error; -use crate::{config::Config, report::Report}; +use crate::{config::Config, report::ChecksumReport}; /// TODO: how to retrieve the actual pure checksum (reference value) /// Fictional struct for the moment / prob use an external library -#[derive(Clone, Debug, PartialEq, PartialOrd, Hash)] +#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)] pub struct Checksum { value: Vec, } +impl Checksum { + /// A checksum with no stored data. + pub const UNIT_CHECKSUM: Checksum = Checksum { value: vec![] }; +} + impl std::fmt::Display for Checksum { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", hex::encode(&self.value)) @@ -27,35 +32,57 @@ impl std::fmt::Display for Checksum { struct GameFile { path: PathBuf, expected_checksum: Checksum, + computed_checksum: Checksum, } impl GameFile { - pub fn compute_real_checksum(&self) -> Checksum { + pub fn compute_real_checksum(&mut self) -> Checksum { let mut hasher = Sha256::new(); let bytes = match fs::read(&self.path) { Ok(bytes) => bytes, - Err(_) => return Checksum { value: vec![] }, + Err(_) => return Checksum::UNIT_CHECKSUM, }; hasher.update(&bytes); - let res = hasher.finalize(); + // the checksum we get from the file + let checksum_bytes = hasher.finalize(); // dbg variables - let hex_to_str: String = res.to_vec().iter().fold(String::new(), |mut out, b| { - write!(out, "{:02x}", b).expect("Checksum hex string"); - out - }); + let hex_to_str: String = + checksum_bytes + .to_vec() + .iter() + .fold(String::new(), |mut out, b| { + write!(out, "{:02x}", b).expect("Checksum hex string"); + out + }); dbg!(&self.path, hex_to_str); // end of dbg + self.computed_checksum = Checksum { + value: checksum_bytes.to_vec(), + }; + Checksum { - value: res.to_vec(), + value: checksum_bytes.to_vec(), } } - pub fn checksums_match(&self) -> bool { - self.expected_checksum == self.compute_real_checksum() + /// Makes a `ChecksumReport` for this GameFile. + pub fn get_report(&mut self) -> ChecksumReport { + // make the report + ChecksumReport { + file_path: self.path.clone(), + is_matching: self.checksums_match(), + got: self.computed_checksum.clone(), + } + } + + /// Checks if the checksums are equal + compute the checksum of the file + pub fn checksums_match(&mut self) -> bool { + let real_checksum = self.compute_real_checksum(); + self.expected_checksum == real_checksum } } @@ -93,7 +120,8 @@ impl FileIntegrity { } else { let g_file: GameFile = GameFile { path: p.to_path_buf(), - expected_checksum: Checksum { value: vec![] }, // Placeholder + expected_checksum: Checksum::UNIT_CHECKSUM, // Placeholder + computed_checksum: Checksum::UNIT_CHECKSUM, // Placeholder }; game_files.push(g_file); } @@ -106,22 +134,20 @@ impl FileIntegrity { } /// Checking if EVERY file is actully matching the expected checksum - pub fn check(&self, report: &mut Report) -> bool { - let mut res = true; + pub fn check(&mut self) -> Result<(), Vec> { + let mut failed_files = vec![]; - for f in self.game_files.iter() { + for f in self.game_files.iter_mut() { if !f.checksums_match() { - report.set_file_checksum( - f.path.to_str().unwrap().to_string(), - false, - f.compute_real_checksum().to_string(), // wouldn't it be better to change - // return type instead of calling twice this fn? - ); - res = false; - return res; // to be removed later, this is to stop the loop + failed_files.push(f.get_report()); } } - res + + if failed_files.is_empty() { + Ok(()) // no failures :3 + } else { + Err(failed_files) + } } } diff --git a/src/main.rs b/src/main.rs index 78c3f92..6eb9ba7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,9 +11,9 @@ fn main() -> anyhow::Result<()> { .init(); match FileIntegrity::new(&Config::new()?) { - Ok(app) => { - let mut report = Report::new(); - let _res = app.check(&mut report); + Ok(mut app) => { + let report = Report::new(); + let _res = app.check(); // println!("File check result: {}", res); report.generate_report()?; diff --git a/src/report.rs b/src/report.rs index a0464ce..f583dc4 100644 --- a/src/report.rs +++ b/src/report.rs @@ -1,41 +1,35 @@ -use std::{collections::HashSet, io::Write}; +use std::{collections::HashSet, io::Write, path::PathBuf}; use anyhow::Result; use thiserror::Error; use time::OffsetDateTime; +use crate::file_integrity::Checksum; + /// A specific report of a file's checksum results. #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct ChecksumReport { - file_path: String, - matching: bool, - got: String, + pub file_path: PathBuf, + /// Whether or not the checksums are matching. If false, assume the user is a cheating loser. + pub is_matching: bool, + pub got: Checksum, } /// A report of all the tool's analysis results. /// TODO: Add PC specs, connected hardware, PID of opened programs, etc. #[derive(Clone, Debug, PartialEq, Eq)] pub struct Report { - files_checksums: HashSet, + incorrect_file_checksums: HashSet, } impl Report { /// Creates an empty report. pub fn new() -> Self { Self { - files_checksums: HashSet::new(), + incorrect_file_checksums: HashSet::new(), } } - /// Adds a file's checksum results to the report. - pub fn set_file_checksum(&mut self, file_path: String, matching: bool, got: String) { - self.files_checksums.insert(ChecksumReport { - file_path, - matching, - got, - }); - } - /// Writes the report to disk. pub fn generate_report(&self) -> Result<(), ReportError> { const REPORT_FOLDER: &str = "./results/"; @@ -65,11 +59,12 @@ impl Report { writeln!(file, "Report generated on: {}\n\n## Checksums", utc_date)?; - for checksum_report in &self.files_checksums { + for checksum_report in &self.incorrect_file_checksums { writeln!( file, "[incorrect] --> {}: {}", - checksum_report.file_path, checksum_report.got + checksum_report.file_path.to_string_lossy(), + checksum_report.got )?; } From 08bd407e4885675debc38f0bd249e7562d125f7b Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Sat, 4 May 2024 13:14:38 +0900 Subject: [PATCH 14/15] fix(report): reports have the first 10 files found instead of empty --- src/file_integrity.rs | 3 ++- src/main.rs | 12 +++++++++--- src/report.rs | 5 +++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/file_integrity.rs b/src/file_integrity.rs index 1fe3480..0ac9f6f 100644 --- a/src/file_integrity.rs +++ b/src/file_integrity.rs @@ -137,7 +137,8 @@ impl FileIntegrity { pub fn check(&mut self) -> Result<(), Vec> { let mut failed_files = vec![]; - for f in self.game_files.iter_mut() { + // TODO: remove the [..10] slice + for f in self.game_files[..10].iter_mut() { if !f.checksums_match() { failed_files.push(f.get_report()); } diff --git a/src/main.rs b/src/main.rs index 6eb9ba7..d48cb64 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,10 +12,16 @@ fn main() -> anyhow::Result<()> { match FileIntegrity::new(&Config::new()?) { Ok(mut app) => { - let report = Report::new(); - let _res = app.check(); - // println!("File check result: {}", res); + let mut report = Report::new(); + match app.check() { + Ok(_) => { + // we will not do anything, just continue program + } + Err(checksum_reports) => { + report.set_incorrect_file_checksums(checksum_reports); + } + } report.generate_report()?; } Err(e) => { diff --git a/src/report.rs b/src/report.rs index f583dc4..fedb5b5 100644 --- a/src/report.rs +++ b/src/report.rs @@ -30,6 +30,11 @@ impl Report { } } + /// Sets the `incorrect_file_checksums` field from a Vec. + pub fn set_incorrect_file_checksums(&mut self, incorrect_file_checksums: Vec) { + self.incorrect_file_checksums = incorrect_file_checksums.into_iter().collect(); + } + /// Writes the report to disk. pub fn generate_report(&self) -> Result<(), ReportError> { const REPORT_FOLDER: &str = "./results/"; From 718093d065cdb1350f75e5d4b42d5e84494d7aa1 Mon Sep 17 00:00:00 2001 From: Simon9991 Date: Sat, 4 May 2024 13:16:12 +0900 Subject: [PATCH 15/15] chore(report): added a todo for generated report style --- src/report.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/report.rs b/src/report.rs index fedb5b5..0187de0 100644 --- a/src/report.rs +++ b/src/report.rs @@ -36,6 +36,7 @@ impl Report { } /// Writes the report to disk. + /// TODO: choose the generatted style (markdown, json, etc) pub fn generate_report(&self) -> Result<(), ReportError> { const REPORT_FOLDER: &str = "./results/";