Skip to content

Commit

Permalink
Linux: Installing/Updating packages with uppercase versions (#43988)
Browse files Browse the repository at this point in the history
  • Loading branch information
edvilme authored Oct 24, 2024
1 parent f3b1152 commit c267ab6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
20 changes: 9 additions & 11 deletions src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,10 @@ public async Task<string> DownloadPackageAsync(PackageId packageId,
string.Format(LocalizableStrings.IsNotFoundInNuGetFeeds, packageId, source.Source));
}

string nupkgPath = downloadFolder == null || !downloadFolder.HasValue
? Path.Combine(_packageInstallDir.Value, packageId.ToString(),
resolvedPackageVersion.ToNormalizedString(),
$"{packageId}.{resolvedPackageVersion.ToNormalizedString()}.nupkg")
: Path.Combine(downloadFolder.Value.Value,
$"{packageId}.{resolvedPackageVersion.ToNormalizedString()}.nupkg");

var pathResolver = new VersionFolderPathResolver(downloadFolder == null || !downloadFolder.HasValue ? _packageInstallDir.Value : downloadFolder.Value.Value);
string nupkgPath = pathResolver.GetPackageFilePath(packageId.ToString(), resolvedPackageVersion);
Directory.CreateDirectory(Path.GetDirectoryName(nupkgPath));

using FileStream destinationStream = File.Create(nupkgPath);
bool success = await ExponentialRetry.ExecuteWithRetryOnFailure(async () => await resource.CopyNupkgToStreamAsync(
packageId.ToString(),
Expand Down Expand Up @@ -218,7 +214,10 @@ public async Task<string> GetPackageUrl(PackageId packageId,
SourceRepository repository = GetSourceRepository(source);
if (repository.PackageSource.IsLocal)
{
return Path.Combine(repository.PackageSource.Source, $"{packageId}.{resolvedPackageVersion}.nupkg");
return Path.Combine(
repository.PackageSource.Source,
new VersionFolderPathResolver(repository.PackageSource.Source).GetPackageFileName(packageId.ToString(), resolvedPackageVersion)
);
}

ServiceIndexResourceV3 serviceIndexResource = repository.GetResourceAsync<ServiceIndexResourceV3>().Result;
Expand Down Expand Up @@ -307,9 +306,8 @@ await GetPackageMetadataAsync(packageId.ToString(), packageVersion, packagesSour
return (source, packageVersion);
}

private string GetNupkgUrl(string baseUri, PackageId id, NuGetVersion version) =>
baseUri + id.ToString() + "/" + version.ToNormalizedString() + "/" + id.ToString() +
"." + version.ToNormalizedString() + ".nupkg";
private string GetNupkgUrl(string baseUri, PackageId id, NuGetVersion version) => baseUri + id.ToString() + "/" + version.ToNormalizedString() + "/" + id.ToString() +
"." + version.ToNormalizedString().ToLowerInvariant() + ".nupkg";

internal IEnumerable<FilePath> FindAllFilesNeedExecutablePermission(IEnumerable<string> files,
string targetPath)
Expand Down
6 changes: 3 additions & 3 deletions src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public IToolPackage InstallPackage(PackageLocation packageLocation, PackageId pa
}
NuGetVersion packageVersion = nugetPackageDownloader.GetBestPackageVersionAsync(packageId, versionRange, packageSourceLocation).GetAwaiter().GetResult();

rollbackDirectory = isGlobalTool ? toolDownloadDir.Value: Path.Combine(toolDownloadDir.Value, packageId.ToString(), packageVersion.ToString());
rollbackDirectory = isGlobalTool ? toolDownloadDir.Value: new VersionFolderPathResolver(toolDownloadDir.Value).GetInstallPath(packageId.ToString(), packageVersion);

if (isGlobalTool)
{
NuGetv3LocalRepository nugetPackageRootDirectory = new(Path.Combine(_toolPackageStore.GetRootPackageDirectory(packageId).ToString().Trim('"'), packageVersion.ToString()));
NuGetv3LocalRepository nugetPackageRootDirectory = new(new VersionFolderPathResolver(_toolPackageStore.Root.Value).GetInstallPath(packageId.ToString(), packageVersion));
var globalPackage = nugetPackageRootDirectory.FindPackage(packageId.ToString(), packageVersion);

if (globalPackage != null)
Expand Down Expand Up @@ -303,7 +303,7 @@ private static async Task<NuGetVersion> DownloadAndExtractPackage(
}

// Extract the package
var nupkgDir = Path.Combine(packagesRootPath, packageId.ToString(), version.ToString());
var nupkgDir = new VersionFolderPathResolver(packagesRootPath).GetInstallPath(packageId.ToString(), version);
await nugetPackageDownloader.ExtractPackageAsync(packagePath, new DirectoryPath(nupkgDir));

return version;
Expand Down
8 changes: 5 additions & 3 deletions src/Cli/dotnet/ToolPackage/ToolPackageInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.DotNet.Tools;
using Microsoft.Extensions.EnvironmentAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
using NuGet.ProjectModel;
using NuGet.Versioning;

Expand Down Expand Up @@ -85,7 +86,8 @@ public ToolPackageInstance(PackageId id,
_lockFile =
new Lazy<LockFile>(
() => new LockFileFormat().Read(assetsJsonParentDirectory.WithFile(AssetsFileName).Value));
var toolsPackagePath = Path.Combine(PackageDirectory.Value, Id.ToString(), Version.ToNormalizedString(), "tools");
var installPath = new VersionFolderPathResolver(PackageDirectory.Value).GetInstallPath(Id.ToString(), Version);
var toolsPackagePath = Path.Combine(installPath, "tools");
Frameworks = Directory.GetDirectories(toolsPackagePath)
.Select(path => NuGetFramework.ParseFolder(Path.GetFileName(path)));
}
Expand Down Expand Up @@ -127,7 +129,7 @@ private FilePath LockFileRelativePathToFullFilePath(string lockFileRelativePath,
return PackageDirectory
.WithSubDirectories(
Id.ToString(),
library.Version.ToNormalizedString())
library.Version.ToNormalizedString().ToLowerInvariant())
.WithFile(lockFileRelativePath);
}

Expand Down Expand Up @@ -209,7 +211,7 @@ private ToolConfiguration DeserializeToolConfiguration(LockFileTargetLibrary lib
PackageDirectory
.WithSubDirectories(
Id.ToString(),
library.Version.ToNormalizedString())
library.Version.ToNormalizedString().ToLowerInvariant())
.WithFile(dotnetToolSettings.Path);

var configuration = ToolConfigurationDeserializer.Deserialize(toolConfigurationPath.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal static class AddPackageParser
var allowPrerelease = context.ParseResult.GetValue(PrereleaseOption);
return QueryVersionsForPackage(packageId, context.WordToComplete, allowPrerelease, CancellationToken.None)
.Result
.Select(version => new CompletionItem(version.ToNormalizedString()));
.Select(version => new CompletionItem(version.ToNormalizedString().ToLowerInvariant()));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public string GetPackageDirectory(string packageId, NuGetVersion version)
public string GetPackageDirectory(string packageId, NuGetVersion version, out string packageRoot)
{
packageRoot = _root;
return Path.Combine(_root, packageId, version.ToNormalizedString(), "path");
return Path.Combine(_root, packageId, version.ToNormalizedString().ToLowerInvariant(), "path");
}

public string ResolvePackageAssetPath(LockFileTargetLibrary package, string relativePath) => Path.Combine(GetPackageDirectory(package.Name, package.Version), relativePath);
Expand Down

0 comments on commit c267ab6

Please sign in to comment.