Skip to content

Commit 77bed4b

Browse files
committed
read SHA512SUMS file 1 line at a time
The file can be very large, and we only need part of 1 line from it.
1 parent 0242b4e commit 77bed4b

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

clang-tools-manager/src/downloader/static_dist.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ mod unsupported_platform {
8888
mod supported_platform {
8989
use std::{
9090
fs,
91+
io::{BufRead, BufReader},
9192
ops::RangeInclusive,
9293
path::{Path, PathBuf},
9394
};
@@ -127,13 +128,21 @@ mod supported_platform {
127128
tool: &str,
128129
sha512_path: &Path,
129130
) -> Result<(), StaticDistDownloadError> {
130-
let checksum_file_content = fs::read_to_string(sha512_path)?;
131-
let expected = checksum_file_content
132-
.lines()
133-
.find(|line| line.ends_with(tool))
134-
.and_then(|line| line.split(' ').next())
135-
.ok_or(StaticDistDownloadError::Sha512Corruption)?;
136-
HashAlgorithm::Sha512(expected.to_string()).verify(file_path)?;
131+
let expected = {
132+
let checksum_file_handle = fs::File::open(sha512_path)?;
133+
let checksum_file_content = BufReader::new(checksum_file_handle);
134+
let mut found = None;
135+
for line in checksum_file_content.lines() {
136+
let line = line?;
137+
if line.ends_with(tool) {
138+
found = line.split(' ').next().map(|s| s.trim().to_string());
139+
break;
140+
}
141+
}
142+
found
143+
}
144+
.ok_or(StaticDistDownloadError::Sha512Corruption)?;
145+
HashAlgorithm::Sha512(expected).verify(file_path)?;
137146
Ok(())
138147
}
139148

0 commit comments

Comments
 (0)