Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Commit

Permalink
Ignore pacakge with unnormalized version
Browse files Browse the repository at this point in the history
  • Loading branch information
troydai committed Jul 15, 2015
1 parent 677d6c3 commit a8d2d5a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ public IEnumerable<PackageInfo> FindPackagesById(string packageId)
continue;
}
if (!version.IsOriginalStringNormalized())
{
// For a non-http match, if the OriginalVersion string is not normalized that means name of the folder which contains
// the package is not a normalized string. It will cause trouble for file searching in later stage. By invalidating this
// match, it ensures the package will be reinstalled under a correct folder. This change ensures a package installed
// by older version of DNX won't prevent new DNX to install correct package.
continue;
}
var manifestFilePath = _repositoryRoot.GetFiles(versionDir, "*" + Constants.ManifestExtension)
.FirstOrDefault();
if (string.IsNullOrEmpty(manifestFilePath))
Expand Down
21 changes: 21 additions & 0 deletions src/Microsoft.Framework.Runtime/NuGet/SemanticVersionExtensions.cs
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
Expand Up @@ -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"),
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}")));
}
}
}
}

0 comments on commit a8d2d5a

Please sign in to comment.