/// <summary> /// Checks if we actually need to download of if the disk is up to date. /// </summary> /// <returns>Returns EvaluationResult.Continue if we still need to download, else the result will be what should be returned</returns> private async Task <EvaluationResult> CheckIfDownloadIsNeededAsync(DownloadData downloadData) { try { var downloadFilePath = downloadData.DownloadedFilePath.ToString(m_context.PathTable); // Check if the file already exists and matches the expected hash. if (File.Exists(downloadFilePath)) { var expectedHashType = downloadData.ContentHash.HasValue ? downloadData.ContentHash.Value.HashType : HashTypeParser(downloadData.Settings.Hash); // We don't record the file until we know it is the one used in this build. var recordFileAccess = false; var actualHash = await GetContentHashAsync(downloadData.DownloadedFilePath, expectedHashType, recordFileAccess); // Compare actual hash to compare if we need to download again. // Compare against the static hash value. if (downloadData.ContentHash.HasValue && actualHash == downloadData.ContentHash.Value) { // Record the file with the build's default hasher. m_frontEndHost.Engine.RecordFrontEndFile(downloadData.DownloadedFilePath, Name); return(new EvaluationResult(FileArtifact.CreateSourceFile(downloadData.DownloadedFilePath))); } var incrementalState = await DownloadIncrementalState.TryLoadAsync(m_logger, m_context, downloadData); if (incrementalState != null && incrementalState.ContentHash == actualHash) { // Record the file with the build's default hasher. m_frontEndHost.Engine.RecordFrontEndFile(downloadData.DownloadedFilePath, Name); return(new EvaluationResult(FileArtifact.CreateSourceFile(downloadData.DownloadedFilePath))); } } } catch (IOException e) { m_logger.ErrorCheckingIncrementality(m_context.LoggingContext, downloadData.Settings.ModuleName, e.Message); return(EvaluationResult.Error); } catch (UnauthorizedAccessException e) { m_logger.ErrorCheckingIncrementality(m_context.LoggingContext, downloadData.Settings.ModuleName, e.Message); return(EvaluationResult.Error); } // Download is needed return(EvaluationResult.Continue); }
/// <summary> /// Checks if we actually need to download of if the disk is up to date. /// </summary> /// <returns>Returns EvaluationResult.Continue if we still need to download, else the result will be what should be returned</returns> private async Task <EvaluationResult> CheckIfDownloadIsNeededAsync(DownloadData downloadData) { try { var downloadFilePath = downloadData.DownloadedFilePath.ToString(m_context.PathTable); // Check if the file already exists and matches the exected hash. if (File.Exists(downloadFilePath)) { var expectedHashType = downloadData.ContentHash.HasValue ? downloadData.ContentHash.Value.HashType : HashType.Unknown; // Compare actual hash to compare if we need to download again. var actualHash = await GetContentHashAsync(downloadData.DownloadedFilePath, expectedHashType); // Compare against the static hash value. if (downloadData.ContentHash.HasValue && actualHash == downloadData.ContentHash.Value) { return(new EvaluationResult(FileArtifact.CreateSourceFile(downloadData.DownloadedFilePath))); } var incrementalState = await DownloadIncrementalState.TryLoadAsync(m_logger, m_context, downloadData); if (incrementalState != null && incrementalState.ContentHash == actualHash) { return(new EvaluationResult(FileArtifact.CreateSourceFile(downloadData.DownloadedFilePath))); } } } catch (IOException e) { m_logger.ErrorCheckingIncrementality(m_context.LoggingContext, downloadData.Settings.ModuleName, e.Message); return(EvaluationResult.Error); } catch (UnauthorizedAccessException e) { m_logger.ErrorCheckingIncrementality(m_context.LoggingContext, downloadData.Settings.ModuleName, e.Message); return(EvaluationResult.Error); } // Download is needed return(EvaluationResult.Continue); }