From c8763e4861f9aa87eae37750ae558c4714e660a1 Mon Sep 17 00:00:00 2001 From: johnataylor Date: Wed, 2 Sep 2015 17:30:19 -0700 Subject: [PATCH] skip packages that have bad nuspecs --- .../Repositories/ExpandedPackageRepository.cs | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Core/Repositories/ExpandedPackageRepository.cs b/src/Core/Repositories/ExpandedPackageRepository.cs index 031c98fea..41d39dd80 100644 --- a/src/Core/Repositories/ExpandedPackageRepository.cs +++ b/src/Core/Repositories/ExpandedPackageRepository.cs @@ -1,7 +1,10 @@ -using System.Collections.Generic; +using NuGet.Resources; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Xml; namespace NuGet { @@ -95,7 +98,12 @@ public IEnumerable FindPackagesById(string packageId) if (SemanticVersion.TryParse(versionDirectoryName, out version) && Exists(packageId, version)) { - yield return GetPackageInternal(packageId, version); + var package = GetPackageInternal(packageId, version); + if (package == null) + { + continue; + } + yield return package; } } } @@ -117,9 +125,24 @@ private static string GetPackageRoot(string packageId, SemanticVersion version) private IPackage GetPackageInternal(string packageId, SemanticVersion version) { - var packagePath = GetPackagePath(packageId, version); - var manifestPath = Path.Combine(GetPackageRoot(packageId, version), packageId + Constants.ManifestExtension); - return new ZipPackage(() => _fileSystem.OpenFile(packagePath), () => _fileSystem.OpenFile(manifestPath)); + var manifestPath = string.Empty; + try + { + var packagePath = GetPackagePath(packageId, version); + manifestPath = Path.Combine(GetPackageRoot(packageId, version), packageId + Constants.ManifestExtension); + return new ZipPackage(() => _fileSystem.OpenFile(packagePath), () => _fileSystem.OpenFile(manifestPath)); + } + catch (XmlException ex) + { + _fileSystem.Logger.Log(MessageLevel.Warning, ex.Message); + } + catch (IOException ex) + { + _fileSystem.Logger.Log(MessageLevel.Warning, ex.Message); + } + + _fileSystem.Logger.Log(MessageLevel.Warning, NuGetResources.Manifest_NotFound, manifestPath); + return null; } private static string GetPackagePath(string packageId, SemanticVersion version)