diff --git a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs index f345412bc8..9fb89fd800 100644 --- a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs +++ b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs @@ -36,5 +36,6 @@ public ChocolateyPackageInformation(IPackageMetadata package) public bool HasSilentUninstall { get; set; } public bool IsPinned { get; set; } public string ExtraInformation { get; set; } + public string DeploymentLocation { get; set; } } } diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs index 6eb0d7d715..4eaab3b165 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs @@ -44,6 +44,7 @@ public class ChocolateyPackageInformationService : IChocolateyPackageInformation private const string ArgsFile = ".arguments"; private const string ExtraFile = ".extra"; private const string VersionOverrideFile = ".version"; + private const string DeploymentLocationFile = ".deploymentLocation"; // We need to store the package identifiers we have warned about // to prevent duplicated outputs. @@ -179,6 +180,20 @@ has errored attempting to read it. This file will be renamed to ); } + var locationFile = _fileSystem.CombinePaths(pkgStorePath, DeploymentLocationFile); + if (_fileSystem.FileExists(locationFile)) + { + FaultTolerance.TryCatchWithLoggingException( + () => + { + packageInformation.DeploymentLocation = _fileSystem.ReadFile(locationFile); + }, + "Unable to read deployment location file", + throwError: false, + logWarningInsteadOfError: true + ); + } + return packageInformation; } @@ -280,6 +295,21 @@ public void Save(ChocolateyPackageInformation packageInformation) { _fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, PinFile)); } + + if (!string.IsNullOrWhiteSpace(packageInformation.DeploymentLocation)) + { + var locationFile = _fileSystem.CombinePaths(pkgStorePath, DeploymentLocationFile); + if (_fileSystem.FileExists(locationFile)) + { + _fileSystem.DeleteFile(locationFile); + } + + _fileSystem.WriteFile(locationFile, packageInformation.DeploymentLocation); + } + else + { + _fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, DeploymentLocationFile)); + } } public void Remove(IPackageMetadata package) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 93e1a1b338..fc9b292606 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -566,6 +566,8 @@ public virtual void HandlePackageResult(PackageResult packageResult, ChocolateyC } } + pkgInfo.DeploymentLocation = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation); + UpdatePackageInformation(pkgInfo); EnsureBadPackagesPathIsClean(packageResult); EventManager.Publish(new HandlePackageResultCompletedMessage(packageResult, config, commandName)); @@ -601,11 +603,10 @@ public virtual void HandlePackageResult(PackageResult packageResult, ChocolateyC this.Log().Info(ChocolateyLoggers.Important, " The {0} of {1} was successful.".FormatWith(commandName.ToStringSafe(), packageResult.Name)); - var installLocation = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation); var installerDetected = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallerType); - if (!string.IsNullOrWhiteSpace(installLocation)) + if (!string.IsNullOrWhiteSpace(pkgInfo.DeploymentLocation)) { - this.Log().Info(ChocolateyLoggers.Important, " Software installed to '{0}'".FormatWith(installLocation.EscapeCurlyBraces())); + this.Log().Info(ChocolateyLoggers.Important, " Deployed to '{0}'".FormatWith(pkgInfo.DeploymentLocation.EscapeCurlyBraces())); } else if (!string.IsNullOrWhiteSpace(installerDetected)) {