Skip to content

Commit

Permalink
(chocolatey#3174) Apply version number normalizing consistently
Browse files Browse the repository at this point in the history
Went through all references to `ToStringSafe` which were being called on
a NuGetVersion instance and changed them all to
`ToNormalizedStringChecked`.

Additionally, found a place in the upgrade dry-run code that was just
missing a call to this method and outputting a non-normalized version
string and added it.
  • Loading branch information
vexx32 committed May 31, 2023
1 parent cff06ee commit 07058c6
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 107 deletions.
68 changes: 34 additions & 34 deletions src/chocolatey.tests.integration/scenarios/InstallScenarios.cs

Large diffs are not rendered by default.

114 changes: 57 additions & 57 deletions src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void Run(PackageResult packageResult, ChocolateyConfiguration config)

foreach (var key in registryKeys.OrEmpty())
{
var packageCacheLocation = _fileSystem.CombinePaths(_fileSystem.GetFullPath(config.CacheLocation), package.Id, package.Version.ToStringSafe());
var packageCacheLocation = _fileSystem.CombinePaths(_fileSystem.GetFullPath(config.CacheLocation), package.Id, package.Version.ToNormalizedStringChecked());
Remove(key, config, packageResult, packageCacheLocation);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void Save(ChocolateyPackageInformation packageInformation)
{
var versionOverrideFile = _fileSystem.CombinePaths(pkgStorePath, VersionOverrideFile);
if (_fileSystem.FileExists(versionOverrideFile)) _fileSystem.DeleteFile(versionOverrideFile);
_fileSystem.WriteFile(versionOverrideFile, packageInformation.VersionOverride.ToStringSafe());
_fileSystem.WriteFile(versionOverrideFile, packageInformation.VersionOverride.ToNormalizedStringChecked());
}
else
{
Expand Down Expand Up @@ -266,7 +266,7 @@ private static string GetStorePath(IFileSystem fileSystem, string id, NuGetVersi
return preferredStorePath;
}

var pkgStorePath = fileSystem.CombinePaths(ApplicationParameters.ChocolateyPackageInfoStoreLocation, "{0}.{1}".FormatWith(id, version.ToStringSafe()));
var pkgStorePath = fileSystem.CombinePaths(ApplicationParameters.ChocolateyPackageInfoStoreLocation, "{0}.{1}".FormatWith(id, version.ToNormalizedStringChecked()));

if (fileSystem.DirectoryExists(pkgStorePath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ public virtual void HandlePackageUninstall(PackageResult packageResult, Chocolat
{
if (!_fileSystem.DirectoryExists(packageResult.InstallLocation))
{
packageResult.InstallLocation += ".{0}".FormatWith(packageResult.PackageMetadata.Version.ToStringSafe());
packageResult.InstallLocation += ".{0}".FormatWith(packageResult.PackageMetadata.Version.ToNormalizedStringChecked());
}

//These items only apply to windows systems.
Expand Down
10 changes: 5 additions & 5 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ public virtual ConcurrentDictionary<string, PackageResult> Upgrade(ChocolateyCon
}
else
{
this.Log().Info("{0}|{1}|{2}|{3}".FormatWith(installedPackage.PackageMetadata.Id, installedPackage.Version, availablePackage.Identity.Version, isPinned.ToStringSafe().ToLowerSafe()));
this.Log().Info("{0}|{1}|{2}|{3}".FormatWith(installedPackage.PackageMetadata.Id, installedPackage.Version, availablePackage.Identity.Version.ToNormalizedStringChecked(), isPinned.ToStringSafe().ToLowerSafe()));
}
}

Expand Down Expand Up @@ -1858,7 +1858,7 @@ public virtual void BackupChangedFiles(string packageInstallPath, ChocolateyConf
{
if (packageInfo == null || packageInfo.Package == null) return;

var version = packageInfo.Package.Version.ToStringSafe();
var version = packageInfo.Package.Version.ToNormalizedStringChecked();

if (packageInfo.FilesSnapshot == null || packageInfo.FilesSnapshot.Files.Count == 0)
{
Expand Down Expand Up @@ -1923,7 +1923,7 @@ private void RemoveShimgenDirectors(IPackageMetadata installedPackage)
private void RemovePackageFromCache(ChocolateyConfiguration config, IPackageMetadata installedPackage)
{
this.Log().Debug(ChocolateyLoggers.Verbose, "Ensuring removal of package cache files.");
var cacheDirectory = _fileSystem.CombinePaths(config.CacheLocation, installedPackage.Id, installedPackage.Version.ToStringSafe());
var cacheDirectory = _fileSystem.CombinePaths(config.CacheLocation, installedPackage.Id, installedPackage.Version.ToNormalizedStringChecked());

if (!_fileSystem.DirectoryExists(cacheDirectory)) return;

Expand Down Expand Up @@ -1952,8 +1952,8 @@ protected void RemovePackageFromNugetCache(IPackageSearchMetadata installedPacka
FaultTolerance.TryCatchWithLoggingException(
() =>
{
var packageFolderPath = _fileSystem.CombinePaths(tempFolder, "{0}/{1}".FormatWith(installedPackage.Identity.Id, installedPackage.Identity.Version.ToStringSafe()));
var nugetCachedFile = _fileSystem.CombinePaths(packageFolderPath, "{0}.{1}.nupkg".FormatWith(installedPackage.Identity.Id, installedPackage.Identity.Version.ToStringSafe()));
var packageFolderPath = _fileSystem.CombinePaths(tempFolder, "{0}/{1}".FormatWith(installedPackage.Identity.Id, installedPackage.Identity.Version.ToNormalizedStringChecked()));
var nugetCachedFile = _fileSystem.CombinePaths(packageFolderPath, "{0}.{1}.nupkg".FormatWith(installedPackage.Identity.Id, installedPackage.Identity.Version.ToNormalizedStringChecked()));
var nupkgMetaDataFile = _fileSystem.CombinePaths(packageFolderPath, ".nupkg.metadata");
var nupkgShaFile = nugetCachedFile + ".sha512";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ public void PreparePowerShellEnvironment(IPackageSearchMetadata package, Chocola
Environment.SetEnvironmentVariable("packageName", package.Identity.Id);
Environment.SetEnvironmentVariable("chocolateyPackageTitle", package.Title);
Environment.SetEnvironmentVariable("packageTitle", package.Title);
Environment.SetEnvironmentVariable("chocolateyPackageVersion", package.Identity.Version.ToStringSafe());
Environment.SetEnvironmentVariable("packageVersion", package.Identity.Version.ToStringSafe());
Environment.SetEnvironmentVariable("chocolateyPackageVersion", package.Identity.Version.ToNormalizedStringChecked());
Environment.SetEnvironmentVariable("packageVersion", package.Identity.Version.ToNormalizedStringChecked());
Environment.SetEnvironmentVariable("chocolateyPackageVersionPrerelease", package.Identity.Version.Release.ToStringSafe());
Environment.SetEnvironmentVariable("chocolateyPackageVersionPackageRelease", package.Identity.Version.Version.ToStringSafe());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ protected void ListCustomTemplateInformation(ChocolateyConfiguration configurati

var templateInstalledViaPackage = (pkg != null);

var pkgVersion = templateInstalledViaPackage ? pkg.Identity.Version.ToStringSafe() : "0.0.0";
var pkgVersion = templateInstalledViaPackage ? pkg.Identity.Version.ToNormalizedStringChecked() : "0.0.0";
var pkgTitle = templateInstalledViaPackage ? pkg.Title : "{0} (Unmanaged)".FormatWith(configuration.TemplateCommand.Name);
var pkgSummary = templateInstalledViaPackage ?
(pkg.Summary != null && !string.IsNullOrWhiteSpace(pkg.Summary.ToStringSafe()) ? "{0}".FormatWith(pkg.Summary.EscapeCurlyBraces().ToStringSafe()) : string.Empty) : string.Empty;
Expand Down
8 changes: 4 additions & 4 deletions src/chocolatey/infrastructure/results/PackageResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ public void ResetMetadata(IPackageMetadata metadata, IPackageSearchMetadata sear
PackageMetadata = metadata;
SearchMetadata = search;
Name = metadata.Id;
Version = metadata.Version.ToStringSafe();
Version = metadata.Version.ToNormalizedStringChecked();
}

public PackageResult(IPackageMetadata packageMetadata, string installLocation, string source = null) : this(packageMetadata.Id, packageMetadata.Version.ToStringSafe(), installLocation)
public PackageResult(IPackageMetadata packageMetadata, string installLocation, string source = null) : this(packageMetadata.Id, packageMetadata.Version.ToNormalizedStringChecked(), installLocation)
{
PackageMetadata = packageMetadata;
Source = source;
}

public PackageResult(IPackageSearchMetadata packageSearch, string installLocation, string source = null) : this(packageSearch.Identity.Id, packageSearch.Identity.Version.ToStringSafe(), installLocation)
public PackageResult(IPackageSearchMetadata packageSearch, string installLocation, string source = null) : this(packageSearch.Identity.Id, packageSearch.Identity.Version.ToNormalizedStringChecked(), installLocation)
{
SearchMetadata = packageSearch;
Source = source;
Expand Down Expand Up @@ -103,7 +103,7 @@ public PackageResult(IPackageSearchMetadata packageSearch, string installLocatio
*/
}

public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source = null) : this(packageMetadata.Id, packageMetadata.Version.ToStringSafe(), installLocation)
public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source = null) : this(packageMetadata.Id, packageMetadata.Version.ToNormalizedStringChecked(), installLocation)
{
SearchMetadata = packageSearch;
PackageMetadata = packageMetadata;
Expand Down

0 comments on commit 07058c6

Please sign in to comment.