diff options
author | Jason Malinowski <jason.malinowski@microsoft.com> | 2016-06-14 22:28:01 +0300 |
---|---|---|
committer | Jason Malinowski <jason.malinowski@microsoft.com> | 2016-06-15 02:19:53 +0300 |
commit | 536f11796b2cf17bbdec4d38a5185c21734121e5 (patch) | |
tree | 050e82e5f5f96d70e11f84b655063c5a865e48bd /src | |
parent | d37c9176cf0b93ab86367675719fa61bbf757d2d (diff) |
Correct check for whether a package exists in a package folder
Diffstat (limited to 'src')
-rw-r--r-- | src/Microsoft.NuGet.Build.Tasks.Tests/NuGetTestHelpers.cs | 18 | ||||
-rw-r--r-- | src/Microsoft.NuGet.Build.Tasks/Delegates.cs | 1 | ||||
-rw-r--r-- | src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs | 12 |
3 files changed, 20 insertions, 11 deletions
diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/NuGetTestHelpers.cs b/src/Microsoft.NuGet.Build.Tasks.Tests/NuGetTestHelpers.cs index 03df913..690a64d 100644 --- a/src/Microsoft.NuGet.Build.Tasks.Tests/NuGetTestHelpers.cs +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/NuGetTestHelpers.cs @@ -55,13 +55,23 @@ namespace Microsoft.NuGet.Build.Tasks.Tests filesInPackages.Add(fileInPackage); } } + else + { + // We will assume there is a location in the lock file we're using + var lockFile = JObject.Parse(projectLockJsonFileContents); + var firstLocation = ((JObject)lockFile["packageFolders"]).Properties().First().Name; + + foreach (var fileInPackage in GetFakeFileNamesFromPackages(projectLockJsonFileContents, firstLocation)) + { + filesInPackages.Add(fileInPackage); + } + } // Don't require the packages be restored on the machine ResolveNuGetPackageAssets task = null; - DirectoryExists directoryExists = path => task.GetPackageFolders().Any(l => path.StartsWith(l)) || Directory.Exists(path); FileExists fileExists = path => filesInPackages.Contains(path) || File.Exists(path); - task = new ResolveNuGetPackageAssets(directoryExists, fileExists, tryGetRuntimeVersion); + task = new ResolveNuGetPackageAssets(fileExists, tryGetRuntimeVersion); var sw = new StringWriter(); task.BuildEngine = new MockBuildEngine(sw); @@ -105,6 +115,10 @@ namespace Microsoft.NuGet.Build.Tasks.Tests yield return Path.Combine(packagesDirectory, library.Name, file).Replace('/', '\\'); } } + + // Some earlier versions of NuGet didn't include the hash file in the file list, so fake that + // in here. + yield return Path.Combine(packagesDirectory, library.Name.Replace('/', '\\'), library.Name.Replace('/', '.') + ".nupkg.sha512"); } } } diff --git a/src/Microsoft.NuGet.Build.Tasks/Delegates.cs b/src/Microsoft.NuGet.Build.Tasks/Delegates.cs index 56a3dba..5eed529 100644 --- a/src/Microsoft.NuGet.Build.Tasks/Delegates.cs +++ b/src/Microsoft.NuGet.Build.Tasks/Delegates.cs @@ -3,7 +3,6 @@ namespace Microsoft.NuGet.Build.Tasks { - internal delegate bool DirectoryExists(string path); internal delegate bool FileExists(string path); internal delegate string TryGetRuntimeVersion(string path); }
\ No newline at end of file diff --git a/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs b/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs index eb425a3..8574db9 100644 --- a/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs +++ b/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs @@ -49,19 +49,13 @@ namespace Microsoft.NuGet.Build.Tasks private readonly Dictionary<string, string> _projectReferencesToOutputBasePaths = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); #region UnitTestSupport - private readonly DirectoryExists _directoryExists = new DirectoryExists(Directory.Exists); private readonly FileExists _fileExists = new FileExists(File.Exists); private readonly TryGetRuntimeVersion _tryGetRuntimeVersion = new TryGetRuntimeVersion(TryGetRuntimeVersion); private readonly bool _reportExceptionsToMSBuildLogger = true; - internal ResolveNuGetPackageAssets(DirectoryExists directoryExists, FileExists fileExists, TryGetRuntimeVersion tryGetRuntimeVersion) + internal ResolveNuGetPackageAssets(FileExists fileExists, TryGetRuntimeVersion tryGetRuntimeVersion) : this() { - if (directoryExists != null) - { - _directoryExists = directoryExists; - } - if (fileExists != null) { _fileExists = fileExists; @@ -894,7 +888,9 @@ namespace Microsoft.NuGet.Build.Tasks { string packagePath = Path.Combine(packagesFolder, packageId, packageVersion); - if (_directoryExists(packagePath)) + // The proper way to check if a package is available is to look for the hash file, since that's the last + // file written as a part of the restore process. If it's not there, it means something failed part way through. + if (_fileExists(Path.Combine(packagePath, $"{packageId}.{packageVersion}.nupkg.sha512"))) { return packagePath; } |