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

Ignore pacakge with unnormalized version #2251

Merged
merged 1 commit into from
Jul 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By invalidating this

// 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"),
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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}")));
}
}
}
}