/// <inheritdoc /> /// <remarks> /// This function should ideally queue up the work /// </remarks> public override async Task <Possible <PackageDownloadResult> > DownloadPackage( string weakPackageFingerprint, PackageIdentity package, AbsolutePath packageTargetFolder, Func <Task <Possible <IReadOnlyList <RelativePath> > > > producePackage) { // Check if we can reuse a package that is layed out on disk already. // If the hash file is present packageHash variable will contain the content of it. if (TryGetPackageFromFromDisk(package, packageTargetFolder, weakPackageFingerprint, out var possiblePackageFromDisk, out var packageHash)) { return(possiblePackageFromDisk); } // Slower path: checking the cache first var targetLocation = packageTargetFolder.ToString(PathTable); var friendlyName = package.GetFriendlyName(); using (var pm = PerformanceMeasurement.StartWithoutStatistic( LoggingContext, nestedLoggingContext => m_logger.StartRetrievingPackage(nestedLoggingContext, friendlyName, targetLocation), nestedLoggingContext => m_logger.EndRetrievingPackage(nestedLoggingContext, friendlyName))) { var loggingContext = pm.LoggingContext; // Getting the package content from the cache var packageFromCache = await TryGetPackageFromCache(loggingContext, weakPackageFingerprint, package, packageTargetFolder, packageHash); if (!packageFromCache.Succeeded || packageFromCache.Result.IsValid) { // Cache failure or package was successfully obtained from the cache. return(packageFromCache); } // Cache miss m_logger.PackageNotFoundInCacheAndStartedDownloading(loggingContext, package.Id, package.Version); // Step: We couldn't retrieve the package from the cache, or some blobs were missing, generate the package with the given function var possiblePackageContents = await producePackage(); if (!possiblePackageContents.Succeeded) { return(possiblePackageContents.Failure); } // Now we can save the content to the cache Analysis.IgnoreResult( await TryAddPackageToCache( loggingContext, weakPackageFingerprint, package, packageTargetFolder, possiblePackageContents.Result), justification: "Okay to ignore putting in cache failure, will happen next time" ); // Step: Return descriptor indicating it wasn't restored from the cache return(PackageDownloadResult.FromRemote(package, packageTargetFolder, possiblePackageContents.Result)); } }
private bool TryGetPackageFromFromDisk(PackageIdentity package, AbsolutePath packageFolder, string weakPackageFingerprint, out Possible <PackageDownloadResult> possibleResult, out PackageHashFile?packageHash) { // There are two options that control this behavior: // /forcePopulatePackageCache and /usePackagesFromFileSystemOnly if (FrontEndConfiguration.UsePackagesFromFileSystem()) { if (TryGetPackageFromFromDiskOnly(package, packageFolder, out var fromFile, out packageHash)) { possibleResult = fromFile; } else { possibleResult = new PackageShouldBeOnDiskFailure(package.GetFriendlyName(), packageFolder.ToString(PathTable)); } // If /usePackagesFromFileSystemOnly is specified, nothing except file check should happen. // Return true to stop the other lookups (like cache or nuget). return(true); }