Fix case sensitivity of tool package identifiers.
This commit fixes the case sensitivity of tool package identifiers. Previously the install and uninstall commands unintentionally required the tool package ids to specified in all lowercase for the install / uninstall to work. Fixes #8682.
This commit is contained in:
parent
4490fd5aa8
commit
5ebbd618ec
44 changed files with 629 additions and 179 deletions
|
@ -2,12 +2,16 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.Tools;
|
||||
using Microsoft.Extensions.EnvironmentAbstractions;
|
||||
using NuGet.Versioning;
|
||||
|
||||
namespace Microsoft.DotNet.ToolPackage
|
||||
{
|
||||
internal class ToolPackageStore : IToolPackageStore
|
||||
{
|
||||
public const string StagingDirectory = ".stage";
|
||||
|
||||
public ToolPackageStore(DirectoryPath root)
|
||||
{
|
||||
Root = root;
|
||||
|
@ -15,17 +19,45 @@ namespace Microsoft.DotNet.ToolPackage
|
|||
|
||||
public DirectoryPath Root { get; private set; }
|
||||
|
||||
public IEnumerable<IToolPackage> GetInstalledPackages(string packageId = null)
|
||||
public DirectoryPath GetRandomStagingDirectory()
|
||||
{
|
||||
if (packageId != null)
|
||||
{
|
||||
return EnumerateVersions(packageId);
|
||||
}
|
||||
|
||||
return EnumerateAllPackages().SelectMany(p => p);
|
||||
return Root.WithSubDirectories(StagingDirectory, Path.GetRandomFileName());
|
||||
}
|
||||
|
||||
private IEnumerable<IEnumerable<IToolPackage>> EnumerateAllPackages()
|
||||
public NuGetVersion GetStagedPackageVersion(DirectoryPath stagingDirectory, PackageId packageId)
|
||||
{
|
||||
if (NuGetVersion.TryParse(
|
||||
Path.GetFileName(
|
||||
Directory.EnumerateDirectories(
|
||||
stagingDirectory.WithSubDirectories(packageId.ToString()).Value).FirstOrDefault()),
|
||||
out var version))
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
throw new ToolPackageException(
|
||||
string.Format(
|
||||
CommonLocalizableStrings.FailedToFindStagedToolPackage,
|
||||
packageId));
|
||||
}
|
||||
|
||||
public DirectoryPath GetRootPackageDirectory(PackageId packageId)
|
||||
{
|
||||
return Root.WithSubDirectories(packageId.ToString());
|
||||
}
|
||||
|
||||
public DirectoryPath GetPackageDirectory(PackageId packageId, NuGetVersion version)
|
||||
{
|
||||
if (version == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(version));
|
||||
}
|
||||
|
||||
return GetRootPackageDirectory(packageId)
|
||||
.WithSubDirectories(version.ToNormalizedString().ToLowerInvariant());
|
||||
}
|
||||
|
||||
public IEnumerable<IToolPackage> EnumeratePackages()
|
||||
{
|
||||
if (!Directory.Exists(Root.Value))
|
||||
{
|
||||
|
@ -34,19 +66,25 @@ namespace Microsoft.DotNet.ToolPackage
|
|||
|
||||
foreach (var subdirectory in Directory.EnumerateDirectories(Root.Value))
|
||||
{
|
||||
var packageId = Path.GetFileName(subdirectory);
|
||||
if (packageId == ToolPackageInstaller.StagingDirectory)
|
||||
var name = Path.GetFileName(subdirectory);
|
||||
var packageId = new PackageId(name);
|
||||
|
||||
// Ignore the staging directory and any directory that isn't the same as the package id
|
||||
if (name == StagingDirectory || name != packageId.ToString())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return EnumerateVersions(packageId);
|
||||
foreach (var package in EnumeratePackageVersions(packageId))
|
||||
{
|
||||
yield return package;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<IToolPackage> EnumerateVersions(string packageId)
|
||||
public IEnumerable<IToolPackage> EnumeratePackageVersions(PackageId packageId)
|
||||
{
|
||||
var packageRootDirectory = Root.WithSubDirectories(packageId);
|
||||
var packageRootDirectory = Root.WithSubDirectories(packageId.ToString());
|
||||
if (!Directory.Exists(packageRootDirectory.Value))
|
||||
{
|
||||
yield break;
|
||||
|
@ -54,13 +92,27 @@ namespace Microsoft.DotNet.ToolPackage
|
|||
|
||||
foreach (var subdirectory in Directory.EnumerateDirectories(packageRootDirectory.Value))
|
||||
{
|
||||
var version = Path.GetFileName(subdirectory);
|
||||
yield return new ToolPackageInstance(
|
||||
this,
|
||||
packageId,
|
||||
version,
|
||||
packageRootDirectory.WithSubDirectories(version));
|
||||
NuGetVersion.Parse(Path.GetFileName(subdirectory)),
|
||||
new DirectoryPath(subdirectory));
|
||||
}
|
||||
}
|
||||
|
||||
public IToolPackage GetPackage(PackageId packageId, NuGetVersion version)
|
||||
{
|
||||
if (version == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(version));
|
||||
}
|
||||
|
||||
var directory = GetPackageDirectory(packageId, version);
|
||||
if (!Directory.Exists(directory.Value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ToolPackageInstance(this, packageId, version, directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue