/// <nodoc /> private async Task <EvaluationResult> ValidateAndStoreIncrementalDownloadStateAsync(DownloadData downloadData) { // If the hash is given in the download setting, use the corresponding hashType(hash algorithm) to get the content hash of the downloaded file. var downloadedHash = await GetContentHashAsync(downloadData.DownloadedFilePath, HashTypeParser(downloadData.Settings.Hash)); if (downloadData.ContentHash.HasValue) { // Validate downloaded hash if specified if (downloadData.ContentHash != downloadedHash) { m_logger.DownloadMismatchedHash( m_context.LoggingContext, downloadData.Settings.ModuleName, downloadData.Settings.Url, downloadData.Settings.Hash, downloadedHash.ToString()); return(EvaluationResult.Error); } } else { try { var incrementalState = new DownloadIncrementalState(downloadData, downloadedHash); await incrementalState.SaveAsync(m_context); } catch (BuildXLException e) { m_logger.ErrorStoringIncrementality(m_context.LoggingContext, downloadData.Settings.ModuleName, e.Message); return(EvaluationResult.Error); } } return(new EvaluationResult(FileArtifact.CreateSourceFile(downloadData.DownloadedFilePath))); }
/// <nodoc /> private async Task <EvaluationResult> ValidateAndStoreIncrementalDownloadStateAsync(DownloadData downloadData) { // If the hash is given in the download setting, use the corresponding hashType(hash algorithm) to get the content hash of the downloaded file. // We don't record the file until we know it is the correct one and will be used in this build. var recordFileAccess = false; var downloadedHash = await GetContentHashAsync(downloadData.DownloadedFilePath, HashTypeParser(downloadData.Settings.Hash), recordFileAccess); if (downloadData.ContentHash.HasValue) { // Validate downloaded hash if specified if (downloadData.ContentHash != downloadedHash) { m_logger.DownloadMismatchedHash( m_context.LoggingContext, downloadData.Settings.ModuleName, downloadData.Settings.Url, downloadData.Settings.Hash, downloadedHash.ToString()); return(EvaluationResult.Error); } } else { try { var incrementalState = new DownloadIncrementalState(downloadData, downloadedHash); await incrementalState.SaveAsync(m_context); } catch (BuildXLException e) { m_logger.ErrorStoringIncrementality(m_context.LoggingContext, downloadData.Settings.ModuleName, e.Message); return(EvaluationResult.Error); } } // Record the file with the build's default hasher. m_frontEndHost.Engine.RecordFrontEndFile(downloadData.DownloadedFilePath, Name); return(new EvaluationResult(FileArtifact.CreateSourceFile(downloadData.DownloadedFilePath))); }