public async Task LocalPackageFileCache_UpdateLastAccessTimestampVerifyOnce() { using (var pathContext = new SimpleTestPathContext()) { var cache = new LocalPackageFileCache(); var pathResolver = new VersionFolderPathResolver(pathContext.PackageSource); var identity = new PackageIdentity("X", NuGetVersion.Parse("1.0.0")); var path = pathResolver.GetInstallPath(identity.Id, identity.Version); await SimpleTestPackageUtility.CreateFolderFeedV3Async( pathContext.PackageSource, identity); var metadataPath = pathResolver.GetNupkgMetadataPath(identity.Id, identity.Version); cache.UpdateLastAccessTime(metadataPath); var lastAccess = File.GetLastAccessTimeUtc(metadataPath); cache.UpdateLastAccessTime(metadataPath); // Verify the last access timestamp was cached Assert.Equal(lastAccess, File.GetLastAccessTimeUtc(metadataPath)); } }
private LocalPackageInfo GetPackage(string packageId, NuGetVersion version, string path) { if (!_packageCache.TryGetValue(path, out var package)) { var nupkgMetadataPath = PathResolver.GetNupkgMetadataPath(packageId, version); var hashPath = PathResolver.GetHashPath(packageId, version); var zipPath = PathResolver.GetPackageFilePath(packageId, version); // The nupkg metadata file is written last. If this file does not exist then the package is // incomplete and should not be used. if (_packageFileCache.Sha512Exists(nupkgMetadataPath)) { package = CreateLocalPackageInfo(packageId, version, path, nupkgMetadataPath, zipPath); } // if hash file exists and it's not a fallback folder then we generate nupkg metadata file else if (!_isFallbackFolder && _packageFileCache.Sha512Exists(hashPath)) { LocalFolderUtility.GenerateNupkgMetadataFile(zipPath, path, hashPath, nupkgMetadataPath); package = CreateLocalPackageInfo(packageId, version, path, nupkgMetadataPath, zipPath); } if (package != null) { // Cache the package, if it is valid it will not change // for the life of this restore. // Locking is done at a higher level around the id _packageCache.TryAdd(path, package); if (!_isFallbackFolder && _updateLastAccessTime) { _packageFileCache.UpdateLastAccessTime(nupkgMetadataPath); } } } return(package); }