File tree Expand file tree Collapse file tree
clang-tools-manager/src/downloader Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ mod unsupported_platform {
8888mod 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
You can’t perform that action at this time.
0 commit comments