Skip to content

Commit bc66634

Browse files
mkzwsauyer
authored andcommitted
feat: support for multiple sums in file
1 parent 817b43e commit bc66634

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

libprotonup/src/downloads.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,21 @@ impl Release {
4343
};
4444
for asset in &self.assets {
4545
if asset.name.contains("sha512") {
46+
download.file_name = asset.name.clone();
4647
download.hash_sum = Some(hashing::HashSums {
4748
sum_content: asset.browser_download_url.clone(),
4849
sum_type: hashing::HashSumType::Sha512,
4950
})
5051
} else if asset.name.contains("sha256") {
52+
download.file_name = asset.name.clone();
5153
download.hash_sum = Some(hashing::HashSums {
5254
sum_content: asset.browser_download_url.clone(),
5355
sum_type: hashing::HashSumType::Sha256,
5456
})
5557
} else if compat_tool.filter_asset(asset.dowload_file_name().as_str())
5658
&& files::check_supported_extension(asset.name.clone()).is_ok()
5759
{
60+
download.file_name = asset.name.clone();
5861
download
5962
.download_url
6063
.clone_from(&asset.browser_download_url);
@@ -107,6 +110,8 @@ pub async fn list_releases(compat_tool: &CompatTool) -> Result<ReleaseList, reqw
107110
/// Contains all the information needed to download the corresponding release from GitHub
108111
#[derive(Default, Debug, PartialEq, Clone)]
109112
pub struct Download {
113+
/// file name should be used to verify checksums if available
114+
pub file_name: String,
110115
/// for what app this dowload is
111116
pub for_app: apps::AppInstallations,
112117
/// the tag from the Forge
@@ -233,6 +238,7 @@ mod tests {
233238
// "GE-Proton
234239
(
235240
Download {
241+
file_name: "GE-Proton9-27.tar.gz".to_owned(),
236242
version: "GE-Proton9-27".to_owned(),
237243
hash_sum: None,
238244
for_app: apps::AppInstallations::Steam,
@@ -245,6 +251,7 @@ mod tests {
245251
// WineGE
246252
(
247253
Download {
254+
file_name: "wine-lutris-GE-Proton8-26-x86_64.tar.xz".to_owned(),
248255
version: "GE-Proton8-26".to_owned(),
249256
for_app: apps::AppInstallations::Steam,
250257
hash_sum: None,

libprotonup/src/files.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ mod test {
390390
);
391391

392392
let d = Download {
393+
file_name: "test".to_owned(),
393394
for_app: AppInstallations::Steam,
394395
version: "new_top_123".to_owned(),
395396
hash_sum: None,

libprotonup/src/hashing.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ pub enum HashSumType {
1717

1818
/// Checks the downloaded file integrity with the sha512sum
1919
pub async fn hash_check_file<R: AsyncRead + Unpin + ?Sized>(
20+
file_name: &str,
2021
reader: &mut R,
2122
git_hash: HashSums,
2223
) -> Result<bool> {
23-
// TODO: this assumes there is only one file in the checksum
24-
let (expected_hash, _) = git_hash
24+
// find line with the file name
25+
let expeted_hash_line = git_hash
2526
.sum_content
26-
.as_str()
27+
.lines()
28+
.find(|line| line.contains(file_name));
29+
30+
let (expected_hash, _) = expeted_hash_line
31+
// if no line found with the file name, assume the content is only the sum
32+
.unwrap_or(&git_hash.sum_content)
2733
.rsplit_once(' ')
34+
// if the split fails, assume the content is only the sum without any spaces
2835
.unwrap_or((&git_hash.sum_content, ""));
2936

3037
match git_hash.sum_type {
@@ -88,6 +95,7 @@ mod test {
8895

8996
assert!(
9097
super::hash_check_file(
98+
"",
9199
&mut &test_data[..],
92100
HashSums {
93101
sum_content: hash,
@@ -103,6 +111,7 @@ mod test {
103111

104112
assert!(
105113
super::hash_check_file(
114+
"",
106115
&mut &test_data[..],
107116
HashSums {
108117
sum_content: hash,

libprotonup/src/sources.ron

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
forge: GitHub,
7070
repository_account: "kron4ek",
7171
repository_name: "Wine-Builds",
72-
tool_type: Runtime,
72+
tool_type: WineBased,
7373
compatible_applications: [Lutris],
7474
release_asset_filter : Some(r"^wine-\d+\.\d+(?:\.\d+)?-amd64\.tar\.xz$"),
7575
file_name_template: Some("kron4ek-wine-{version}")

protonup-rs/src/download.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub(crate) async fn download_file(
106106
}
107107

108108
pub(crate) async fn validate_file(
109+
file_name: &str,
109110
path: &Path,
110111
hash: hashing::HashSums,
111112
multi_progress: MultiProgress,
@@ -117,6 +118,7 @@ pub(crate) async fn validate_file(
117118
let hash_progress_bar = init_hash_progress(path, multi_progress).await?;
118119

119120
if !hashing::hash_check_file(
121+
file_name,
120122
&mut hash_progress_bar.wrap_async_read(BufReader::new(file)),
121123
hash,
122124
)
@@ -368,7 +370,7 @@ async fn download_validate_unpack(
368370
sum_type: git_hash_sum.sum_type,
369371
};
370372

371-
validate_file(&file, hash_sum, multi_progress.clone()).await?;
373+
validate_file(&download.file_name, &file, hash_sum, multi_progress.clone()).await?;
372374
}
373375
None => {
374376
println!("No sum files available, skipping");

0 commit comments

Comments
 (0)