Skip to content

Commit

Permalink
refactor(report): removed the ChecksumReport::new
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon9991 committed May 4, 2024
1 parent d17b25e commit edc601f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
9 changes: 3 additions & 6 deletions src/file_integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
18 changes: 6 additions & 12 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down

0 comments on commit edc601f

Please sign in to comment.