File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,12 @@ public struct ApolloCLI {
1313 /// - timeout: The maximum time to wait before indicating that the download timed out, in seconds.
1414 public static func createCLI( cliFolderURL: URL , timeout: Double ) throws -> ApolloCLI {
1515 try CLIDownloader . downloadIfNeeded ( cliFolderURL: cliFolderURL, timeout: timeout)
16+
17+ if !( try CLIExtractor . validateSHASUMOfDownloadedFile ( in: cliFolderURL) ) {
18+ CodegenLogger . log ( " Downloaded zip file has incorrect SHASUM, forcing redownolad " )
19+ try CLIDownloader . forceRedownload ( cliFolderURL: cliFolderURL, timeout: timeout)
20+ }
21+
1622 let binaryFolderURL = try CLIExtractor . extractCLIIfNeeded ( from: cliFolderURL)
1723 return ApolloCLI ( binaryFolderURL: binaryFolderURL)
1824 }
Original file line number Diff line number Diff line change @@ -78,6 +78,22 @@ struct CLIExtractor {
7878 return true
7979 }
8080
81+ static func validateSHASUMOfDownloadedFile( in cliFolderURL: URL , expected: String = CLIExtractor . expectedSHASUM) throws -> Bool {
82+ let zipFileURL = ApolloFilePathHelper . zipFileURL ( fromCLIFolder: cliFolderURL)
83+
84+ do {
85+ try self . validateZipFileSHASUM ( at: zipFileURL)
86+ return true
87+ } catch {
88+ switch error {
89+ case CLIExtractorError . zipFileHasInvalidSHASUM:
90+ return false
91+ default :
92+ throw error
93+ }
94+ }
95+ }
96+
8197 /// Writes the SHASUM of the extracted version of the CLI to a file for faster checks to ensure we have the correct version.
8298 ///
8399 /// - Parameter apolloFolderURL: The URL to the extracted apollo folder.
@@ -119,7 +135,7 @@ struct CLIExtractor {
119135 /// - Parameter expected: The expected SHASUM. Defaults to the real expected SHASUM. This parameter exists mostly for testing.
120136 static func validateZipFileSHASUM( at zipFileURL: URL , expected: String = CLIExtractor . expectedSHASUM) throws {
121137 let shasum = try FileManager . default. apollo. shasum ( at: zipFileURL)
122- print ( " SHASUM: \( shasum) " )
138+ print ( " SHASUM of downloaded file : \( shasum) " )
123139 guard shasum == expected else {
124140 throw CLIExtractorError . zipFileHasInvalidSHASUM ( expectedSHASUM: expected, gotSHASUM: shasum)
125141 }
You can’t perform that action at this time.
0 commit comments