-
Notifications
You must be signed in to change notification settings - Fork 224
Ignore pacakge with unnormalized version #2251
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace NuGet | ||
{ | ||
public static class SemanticVersionExtensions | ||
{ | ||
/// <summary> | ||
/// Returns true if the original version string is normalized | ||
/// | ||
/// For an installed package, it's original version string represents the folder name | ||
/// contains the pacakge, the path of which is {id}/{version}/. By checking if the | ||
/// package's original version string is normalized, it be prevented from failing the | ||
/// package path resolving because of a miss version string. | ||
/// </summary> | ||
public static bool IsOriginalStringNormalized(this SemanticVersion version) | ||
{ | ||
return version.GetNormalizedVersionString() == version.OriginalString; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,5 +189,51 @@ public void DnuRestore_ReinstallsCorruptedPackage(string flavor, string os, stri | |
Assert.True(File.Exists(nuspecPath)); | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(RuntimeComponents))] | ||
public void DnuRestore_ReinstallsPackageWithNormalizedVersion(string flavor, string os, string architecture) | ||
{ | ||
var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); | ||
using (var tempDir = new DisposableDir()) | ||
{ | ||
var projectDir = Path.Combine(tempDir, "project"); | ||
var packagesDir = Path.Combine(tempDir, "packages"); | ||
var projectJson = Path.Combine(projectDir, Runtime.Project.ProjectFileName); | ||
|
||
Directory.CreateDirectory(projectDir); | ||
File.WriteAllText(projectJson, @" | ||
{ | ||
""dependencies"": { | ||
""alpha"": ""0.1.0"" | ||
} | ||
}"); | ||
DnuTestUtils.ExecDnu( | ||
runtimeHomePath, | ||
subcommand: "restore", | ||
arguments: $"{projectDir} -s {_fixture.PackageSource} --packages {packagesDir}"); | ||
|
||
// rename package folder to an unnormalized string | ||
Directory.Move(Path.Combine(packagesDir, "alpha", "0.1.0"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible that the folder can be normalized but the sha file and nupkg inside isn't or that that not possible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's actually not possible. Either both normalized or not. https://github.com/aspnet/dnx/blob/dev/src/Microsoft.Framework.PackageManager/Utils/NuGetPackageUtils.cs#L30 But the simplified model used by test is sufficient because the version of a package on disk is parsed from it's folder name: https://github.com/aspnet/dnx/blob/dev/src/Microsoft.Framework.Runtime/NuGet/Repositories/PackageRepository.cs#L102. |
||
Path.Combine(packagesDir, "alpha", "0.1.0.0")); | ||
|
||
// ensure the directory is renamed | ||
Assert.False(Directory.Exists(Path.Combine(packagesDir, "alpha", "0.1.0"))); | ||
|
||
string stdOut, stdErr; | ||
var exitCode = DnuTestUtils.ExecDnu( | ||
runtimeHomePath, | ||
subcommand: "restore", | ||
arguments: $"{projectDir} -s {_fixture.PackageSource} --packages {packagesDir}", | ||
stdOut: out stdOut, | ||
stdErr: out stdErr); | ||
|
||
Assert.Equal(0, exitCode); | ||
Assert.Empty(stdErr); | ||
Assert.Contains($"Installing alpha.0.1.0", stdOut); | ||
Assert.True(Directory.Exists(Path.Combine(packagesDir, "alpha", "0.1.0"))); | ||
Assert.True(File.Exists(Path.Combine(packagesDir, "alpha", "0.1.0", $"alpha{Constants.ManifestExtension}"))); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By invalidating this