Skip to content

Commit fa1111f

Browse files
authored
Merge pull request #3316 from TheCakeIsNaOH/gh3315-remember-location
(#3315) Save software installation location
2 parents 2fd17fc + c8c2c65 commit fa1111f

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ public ChocolateyPackageInformation(IPackageMetadata package)
3636
public bool HasSilentUninstall { get; set; }
3737
public bool IsPinned { get; set; }
3838
public string ExtraInformation { get; set; }
39+
public string DeploymentLocation { get; set; }
3940
}
4041
}

src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class ChocolateyPackageInformationService : IChocolateyPackageInformation
4444
private const string ArgsFile = ".arguments";
4545
private const string ExtraFile = ".extra";
4646
private const string VersionOverrideFile = ".version";
47+
private const string DeploymentLocationFile = ".deploymentLocation";
4748

4849
// We need to store the package identifiers we have warned about
4950
// to prevent duplicated outputs.
@@ -179,6 +180,20 @@ has errored attempting to read it. This file will be renamed to
179180
);
180181
}
181182

183+
var locationFile = _fileSystem.CombinePaths(pkgStorePath, DeploymentLocationFile);
184+
if (_fileSystem.FileExists(locationFile))
185+
{
186+
FaultTolerance.TryCatchWithLoggingException(
187+
() =>
188+
{
189+
packageInformation.DeploymentLocation = _fileSystem.ReadFile(locationFile);
190+
},
191+
"Unable to read deployment location file",
192+
throwError: false,
193+
logWarningInsteadOfError: true
194+
);
195+
}
196+
182197
return packageInformation;
183198
}
184199

@@ -280,6 +295,21 @@ public void Save(ChocolateyPackageInformation packageInformation)
280295
{
281296
_fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, PinFile));
282297
}
298+
299+
if (!string.IsNullOrWhiteSpace(packageInformation.DeploymentLocation))
300+
{
301+
var locationFile = _fileSystem.CombinePaths(pkgStorePath, DeploymentLocationFile);
302+
if (_fileSystem.FileExists(locationFile))
303+
{
304+
_fileSystem.DeleteFile(locationFile);
305+
}
306+
307+
_fileSystem.WriteFile(locationFile, packageInformation.DeploymentLocation);
308+
}
309+
else
310+
{
311+
_fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, DeploymentLocationFile));
312+
}
283313
}
284314

285315
public void Remove(IPackageMetadata package)

src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ public virtual void HandlePackageResult(PackageResult packageResult, ChocolateyC
566566
}
567567
}
568568

569+
pkgInfo.DeploymentLocation = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation);
570+
569571
UpdatePackageInformation(pkgInfo);
570572
EnsureBadPackagesPathIsClean(packageResult);
571573
EventManager.Publish(new HandlePackageResultCompletedMessage(packageResult, config, commandName));
@@ -601,11 +603,10 @@ public virtual void HandlePackageResult(PackageResult packageResult, ChocolateyC
601603

602604
this.Log().Info(ChocolateyLoggers.Important, " The {0} of {1} was successful.".FormatWith(commandName.ToStringSafe(), packageResult.Name));
603605

604-
var installLocation = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation);
605606
var installerDetected = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallerType);
606-
if (!string.IsNullOrWhiteSpace(installLocation))
607+
if (!string.IsNullOrWhiteSpace(pkgInfo.DeploymentLocation))
607608
{
608-
this.Log().Info(ChocolateyLoggers.Important, " Software installed to '{0}'".FormatWith(installLocation.EscapeCurlyBraces()));
609+
this.Log().Info(ChocolateyLoggers.Important, " Deployed to '{0}'".FormatWith(pkgInfo.DeploymentLocation.EscapeCurlyBraces()));
609610
}
610611
else if (!string.IsNullOrWhiteSpace(installerDetected))
611612
{

0 commit comments

Comments
 (0)