public LocalPackageInfo FindPackage(string packageId, NuGetVersion version) { var package = FindPackageImpl(packageId, version); if (package == null) { return(null); } // Check for an exact match on casing if (StringComparer.Ordinal.Equals(packageId, package.Id) && EqualityUtility.SequenceEqualWithNullCheck(version.ReleaseLabels, package.Version.ReleaseLabels, StringComparer.Ordinal)) { return(package); } // nuspec var nuspec = _packageFileCache.GetOrAddNuspec(package.ManifestPath, package.ExpandedPath); // files var files = _packageFileCache.GetOrAddFiles(package.ExpandedPath); // sha512 var sha512 = _packageFileCache.GetOrAddSha512(package.Sha512Path); // runtime.json var runtimeGraph = _packageFileCache.GetOrAddRuntimeGraph(package.ExpandedPath); // Create a new info to match the given id/version return(new LocalPackageInfo( packageId, version, package.ExpandedPath, package.ManifestPath, package.ZipPath, package.Sha512Path, nuspec, files, sha512, runtimeGraph)); }
public async Task PluginCacheEntry_DoesNotDeleteAnOpenedFile() { var list = new List <OperationClaim>() { OperationClaim.Authentication }; using (var testDirectory = TestDirectory.Create()) { var entry = new PluginCacheEntry(testDirectory.Path, "a", "b"); entry.LoadFromFile(); entry.OperationClaims = list; await entry.UpdateCacheFileAsync(); var CacheFileName = Path.Combine( Path.Combine(testDirectory.Path, CachingUtility.RemoveInvalidFileNameChars(CachingUtility.ComputeHash("a", false))), CachingUtility.RemoveInvalidFileNameChars(CachingUtility.ComputeHash("b", false)) + ".dat"); Assert.True(File.Exists(CacheFileName)); using (var fileStream = new FileStream( CacheFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None, CachingUtility.BufferSize, useAsync: true)) { list.Add(OperationClaim.DownloadPackage); entry.OperationClaims = list; await entry.UpdateCacheFileAsync(); // this should not update } entry.LoadFromFile(); Assert.True(EqualityUtility.SequenceEqualWithNullCheck(entry.OperationClaims, new List <OperationClaim>() { OperationClaim.Authentication })); } }
public bool Equals(PackageSpec other) { if (other == null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } // Name and FilePath are not used for comparison since they are not serialized to JSON. return(Title == other.Title && EqualityUtility.EqualsWithNullCheck(Version, other.Version) && IsDefaultVersion == other.IsDefaultVersion && HasVersionSnapshot == other.HasVersionSnapshot && Description == other.Description && Summary == other.Summary && ReleaseNotes == other.ReleaseNotes && EqualityUtility.SequenceEqualWithNullCheck(Authors, other.Authors) && EqualityUtility.SequenceEqualWithNullCheck(Owners, other.Owners) && ProjectUrl == other.ProjectUrl && IconUrl == other.IconUrl && LicenseUrl == other.LicenseUrl && RequireLicenseAcceptance == other.RequireLicenseAcceptance && Copyright == other.Copyright && Language == other.Language && EqualityUtility.EqualsWithNullCheck(BuildOptions, other.BuildOptions) && EqualityUtility.SequenceEqualWithNullCheck(Tags, other.Tags) && EqualityUtility.SequenceEqualWithNullCheck(ContentFiles, other.ContentFiles) && EqualityUtility.SequenceEqualWithNullCheck(Dependencies, other.Dependencies) && EqualityUtility.DictionaryOfSequenceEquals(Scripts, other.Scripts) && EqualityUtility.DictionaryEquals(PackInclude, other.PackInclude, (s, o) => StringComparer.Ordinal.Equals(s, o)) && EqualityUtility.EqualsWithNullCheck(PackOptions, other.PackOptions) && EqualityUtility.SequenceEqualWithNullCheck(TargetFrameworks, other.TargetFrameworks) && EqualityUtility.EqualsWithNullCheck(RuntimeGraph, other.RuntimeGraph) && EqualityUtility.EqualsWithNullCheck(RestoreMetadata, other.RestoreMetadata)); }
public async Task PluginCacheEntry_RoundTripsValuesAsync(string[] values) { var list = new List <OperationClaim>(); foreach (var val in values) { Enum.TryParse(val, out OperationClaim result); list.Add(result); } using (var testDirectory = TestDirectory.Create()) { var entry = new PluginCacheEntry(testDirectory.Path, "a", "b"); entry.LoadFromFile(); entry.OperationClaims = list; await entry.UpdateCacheFileAsync(); var newEntry = new PluginCacheEntry(testDirectory.Path, "a", "b"); newEntry.LoadFromFile(); Assert.True(EqualityUtility.SequenceEqualWithNullCheck(entry.OperationClaims, newEntry.OperationClaims)); } }
public bool Equals(ProjectRestoreMetadata other) { if (other == null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } StringComparer osStringComparer = PathUtility.GetStringComparerBasedOnOS(); return(ProjectStyle == other.ProjectStyle && osStringComparer.Equals(ProjectPath, other.ProjectPath) && osStringComparer.Equals(ProjectJsonPath, other.ProjectJsonPath) && osStringComparer.Equals(OutputPath, other.OutputPath) && osStringComparer.Equals(ProjectName, other.ProjectName) && osStringComparer.Equals(ProjectUniqueName, other.ProjectUniqueName) && Sources.OrderedEquals(other.Sources.Distinct(), source => source.Source, StringComparer.OrdinalIgnoreCase) && osStringComparer.Equals(PackagesPath, other.PackagesPath) && ConfigFilePaths.OrderedEquals(other.ConfigFilePaths, filePath => filePath, osStringComparer, osStringComparer) && FallbackFolders.OrderedEquals(other.FallbackFolders, fallbackFolder => fallbackFolder, osStringComparer, osStringComparer) && EqualityUtility.OrderedEquals(TargetFrameworks, other.TargetFrameworks, dep => dep.TargetAlias, StringComparer.OrdinalIgnoreCase) && OriginalTargetFrameworks.OrderedEquals(other.OriginalTargetFrameworks, fw => fw, StringComparer.OrdinalIgnoreCase, StringComparer.OrdinalIgnoreCase) && CrossTargeting == other.CrossTargeting && LegacyPackagesDirectory == other.LegacyPackagesDirectory && ValidateRuntimeAssets == other.ValidateRuntimeAssets && SkipContentFileWrite == other.SkipContentFileWrite && EqualityUtility.SequenceEqualWithNullCheck(Files, other.Files) && EqualityUtility.EqualsWithNullCheck(ProjectWideWarningProperties, other.ProjectWideWarningProperties) && EqualityUtility.EqualsWithNullCheck(RestoreLockProperties, other.RestoreLockProperties) && EqualityUtility.EqualsWithNullCheck(CentralPackageVersionsEnabled, other.CentralPackageVersionsEnabled) && EqualityUtility.EqualsWithNullCheck(CentralPackageVersionOverrideDisabled, other.CentralPackageVersionOverrideDisabled) && EqualityUtility.EqualsWithNullCheck(CentralPackageTransitivePinningEnabled, other.CentralPackageTransitivePinningEnabled)); }
/// <summary> /// Creates a plugin from the discovered plugin. /// We firstly check the cache for the operation claims for the given request key. /// If there is a valid cache entry, and it does contain the requested operation claim, then we start the plugin, and if need be update the cache value itself. /// If there is a valid cache entry, and it does NOT contain the requested operation claim, then we return a null. /// If there is no valid cache entry or an invalid one, we start the plugin as normally, return an active plugin even if the requested claim is not available, and write a cache entry. /// </summary> /// <param name="result">plugin discovery result</param> /// <param name="requestedOperationClaim">The requested operation claim</param> /// <param name="requestKey">plugin request key</param> /// <param name="packageSourceRepository">package source repository</param> /// <param name="serviceIndex">service index</param> /// <param name="cancellationToken">cancellation token</param> /// <returns>A plugin creation result, null if the requested plugin cannot handle the given operation claim</returns> private async Task <Tuple <bool, PluginCreationResult> > TryCreatePluginAsync( PluginDiscoveryResult result, OperationClaim requestedOperationClaim, PluginRequestKey requestKey, string packageSourceRepository, JObject serviceIndex, CancellationToken cancellationToken) { PluginCreationResult pluginCreationResult = null; var cacheEntry = new PluginCacheEntry(_pluginsCacheDirectoryPath.Value, result.PluginFile.Path, requestKey.PackageSourceRepository); ConcurrencyUtilities.ExecuteWithFileLocked(cacheEntry.CacheFileName, cacheEntry.LoadFromFile); if (cacheEntry.OperationClaims == null || cacheEntry.OperationClaims.Contains(requestedOperationClaim)) { try { if (result.PluginFile.State.Value == PluginFileState.Valid) { var plugin = await _pluginFactory.GetOrCreateAsync( result.PluginFile.Path, PluginConstants.PluginArguments, new RequestHandlers(), _connectionOptions, cancellationToken); var utilities = await PerformOneTimePluginInitializationAsync(plugin, cancellationToken); // We still make the GetOperationClaims call even if we have the operation claims cached. This is a way to self-update the cache. var operationClaims = await _pluginOperationClaims.GetOrAdd( requestKey, key => new Lazy <Task <IReadOnlyList <OperationClaim> > >(() => GetPluginOperationClaimsAsync( plugin, packageSourceRepository, serviceIndex, cancellationToken))).Value; if (!EqualityUtility.SequenceEqualWithNullCheck(operationClaims, cacheEntry.OperationClaims)) { cacheEntry.OperationClaims = operationClaims; await utilities.Value.DoOncePerPluginLifetimeAsync( nameof(PluginCacheEntry), () => ConcurrencyUtilities.ExecuteWithFileLockedAsync( cacheEntry.CacheFileName, action: async lockedToken => { await cacheEntry.UpdateCacheFileAsync(); return(Task.FromResult <object>(null)); }, token: cancellationToken), cancellationToken); } pluginCreationResult = new PluginCreationResult( plugin, utilities.Value, operationClaims); } else { pluginCreationResult = new PluginCreationResult(result.Message); } } catch (Exception e) { pluginCreationResult = new PluginCreationResult( string.Format(CultureInfo.CurrentCulture, Strings.Plugin_ProblemStartingPlugin, result.PluginFile.Path, e.Message), e); } } return(new Tuple <bool, PluginCreationResult>(pluginCreationResult != null, pluginCreationResult)); }