Skip to content

Commit

Permalink
finally lord have mercy
Browse files Browse the repository at this point in the history
  • Loading branch information
MordechaiHadad committed Aug 8, 2024
1 parent 21b3e52 commit 22717c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
17 changes: 9 additions & 8 deletions src/handlers/install_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,15 @@ pub async fn start(
let downloaded_checksum = download_version(client, version, root, config, true).await?;

if let PostDownloadVersionType::Standard(downloaded_checksum) = downloaded_checksum {
info!("{} {}", downloaded_archive.file_name, downloaded_archive.file_format);
info!("{} {}", downloaded_checksum.file_name, downloaded_checksum.file_format);
let archive_path = root
.join(&downloaded_archive.file_name)
.with_extension(&downloaded_archive.file_format);
let checksum_path = root
.join(&downloaded_checksum.file_name)
.with_extension(&downloaded_checksum.file_format);
let mut archive_path = root
.join(&downloaded_archive.file_name);

archive_path.set_file_name(format!("{}.{}", archive_path.file_name().unwrap().to_string_lossy(), downloaded_archive.file_format));

let mut checksum_path = root
.join(&downloaded_checksum.file_name);

checksum_path.set_file_name(format!("{}.{}", checksum_path.file_name().unwrap().to_string_lossy(), downloaded_checksum.file_format));

if !sha256cmp(&archive_path, &checksum_path)? {
tokio::fs::remove_file(archive_path).await?;
Expand Down
6 changes: 0 additions & 6 deletions src/helpers/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,15 @@ use std::{fs, io};
/// This function returns a `Result` that contains a `bool` indicating whether the checksum of the file at path 'a' matches the checksum saved in the file at path 'b'.
/// If there is an error opening or reading the files, the function returns `Err(error)`.
pub fn sha256cmp(a: &Path, b: &Path) -> Result<bool> {
info!("Checking checksum of file at path: {:?}", a);
warn!("{} exists? {}", a.display(), a.exists());
warn!("{} exists? {}", b.display(), b.exists());
let checksum = fs::read_to_string(b)?;
let checksum = checksum.split(' ').next().unwrap();

let mut hasher = Sha256::new();
let mut file = fs::File::open(a)?;
io::copy(&mut file, &mut hasher)?;
info!("Checksum of file at path {:?} is: {:?}", a, hasher);

let hash = hasher.finalize();
let hash = format!("{:x}", hash);

info!("Checksum of file at path {:?} is: {:?}", a, hash);

Ok(hash == checksum)
}

0 comments on commit 22717c0

Please sign in to comment.