Skip to content

Commit

Permalink
Merge pull request #279 from sarpt/fix-file-truncation-after-failed-hash
Browse files Browse the repository at this point in the history
Fix file being written with incorrect size after failed hash verification
  • Loading branch information
RainbowCookie32 authored Jan 6, 2025
2 parents d91712e + 0be30e1 commit 109baab
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rusty-psn"
version = "0.5.5"
version = "0.5.6"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
9 changes: 7 additions & 2 deletions src/psn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod manifest_parser;
use std::{path::PathBuf, str::FromStr};

use reqwest::Url;
use tokio::io::AsyncWriteExt;
use tokio::io::{SeekFrom, AsyncSeekExt, AsyncWriteExt};
use tokio::sync::mpsc::Sender;
use utils::{copy_pkg_file, get_platform_variant, get_update_info_url, PlaformVariant};

Expand Down Expand Up @@ -289,10 +289,15 @@ impl PackageInfo {

if !crate::utils::hash_file(&mut pkg_file, &self.sha1sum, self.hash_whole_file).await? {
if let Err(e) = pkg_file.set_len(0).await {
error!("Failed to set file lenght to 0: {e}");
error!("Failed to set file length to 0: {e}");
return Err(DownloadError::Tokio(e));
}

if let Err(e) = pkg_file.seek(SeekFrom::Start(0)).await {
error!("Failed to set the package file cursor at position 0: {e}");
return Err(DownloadError::Tokio(e));
};

let mut received_data = 0;

while let Some(download_chunk) = response.chunk().await.map_err(DownloadError::Reqwest)? {
Expand Down

0 comments on commit 109baab

Please sign in to comment.