Skip to content

Commit 6833723

Browse files
committed
Persist .lastUpdated in package info
Add support for reading and writing the .lastUpdated file for package information. • Add LastUpdated property to ChocolateyPackageInformation domain. • Read .lastUpdated in ChocolateyPackageInformationService.Get using the same FaultTolerance.TryCatchWithLoggingException pattern as DeploymentLocation. • Persist or remove .lastUpdated in ChocolateyPackageInformationService.Save to fetch DateTime.Now from the NugetService
1 parent ee85b50 commit 6833723

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ public ChocolateyPackageInformation(IPackageMetadata package)
3838
public string ExtraInformation { get; set; }
3939
public string DeploymentLocation { get; set; }
4040
public string SourceInstalledFrom { get; set; }
41+
public string LastUpdated { get; set; }
4142
}
4243
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class ChocolateyPackageInformationService : IChocolateyPackageInformation
4646
private const string VersionOverrideFile = ".version";
4747
private const string DeploymentLocationFile = ".deploymentLocation";
4848
private const string SourceInstalledFromFile = ".sourceInstalledFrom";
49+
private const string LastUpdated = ".lastUpdated";
4950

5051
// We need to store the package identifiers we have warned about
5152
// to prevent duplicated outputs.
@@ -208,6 +209,20 @@ has errored attempting to read it. This file will be renamed to
208209
logWarningInsteadOfError: true
209210
);
210211
}
212+
213+
var lastUpdated = _fileSystem.CombinePaths(pkgStorePath, LastUpdated);
214+
if (_fileSystem.FileExists(lastUpdated))
215+
{
216+
FaultTolerance.TryCatchWithLoggingException(
217+
() =>
218+
{
219+
packageInformation.LastUpdated = _fileSystem.ReadFile(lastUpdated);
220+
},
221+
"Unable to read last updated from file",
222+
throwError: false,
223+
logWarningInsteadOfError: true
224+
);
225+
}
211226

212227
return packageInformation;
213228
}
@@ -340,6 +355,23 @@ public void Save(ChocolateyPackageInformation packageInformation)
340355
{
341356
_fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, SourceInstalledFromFile));
342357
}
358+
359+
if (!string.IsNullOrWhiteSpace(packageInformation.LastUpdated))
360+
{
361+
var lastUpdatedDate = _fileSystem.CombinePaths(pkgStorePath, LastUpdated);
362+
if (_fileSystem.FileExists(lastUpdatedDate))
363+
{
364+
_fileSystem.DeleteFile(lastUpdatedDate);
365+
}
366+
367+
_fileSystem.WriteFile(lastUpdatedDate, packageInformation.LastUpdated);
368+
}
369+
else
370+
{
371+
_fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, LastUpdated));
372+
}
373+
374+
343375
}
344376

345377
public void Remove(IPackageMetadata package)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ public virtual void HandlePackageResult(PackageResult packageResult, ChocolateyC
566566

567567
pkgInfo.DeploymentLocation = Environment.GetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation);
568568
pkgInfo.SourceInstalledFrom = packageResult.SourceInstalledFrom;
569+
pkgInfo.LastUpdated = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
569570

570571
UpdatePackageInformation(pkgInfo);
571572
EnsureBadPackagesPathIsClean(packageResult);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ it is possible that incomplete package lists are returned from a command
219219
string packageInstallLocation = null;
220220
string deploymentlocation = null;
221221
string sourceInstalledFrom = null;
222+
string lastUpdated = null;
222223

223224
if (package.PackagePath != null && !string.IsNullOrWhiteSpace(package.PackagePath))
224225
{
@@ -240,7 +241,7 @@ it is possible that incomplete package lists are returned from a command
240241
packageInfo = _packageInfoService.Get(packageLocalMetadata);
241242
deploymentlocation = packageInfo.DeploymentLocation;
242243
sourceInstalledFrom = packageInfo.SourceInstalledFrom;
243-
244+
lastUpdated = packageInfo.LastUpdated;
244245
if (config.ListCommand.IncludeVersionOverrides)
245246
{
246247
if (packageInfo.VersionOverride != null)
@@ -286,7 +287,7 @@ it is possible that incomplete package lists are returned from a command
286287
package.IsApproved ? " [Approved]" : string.Empty,
287288
package.IsDownloadCacheAvailable ? " Downloads cached for licensed users" : string.Empty,
288289
package.PackageTestResultStatus == "Failing" && package.IsDownloadCacheAvailable ? " - Possibly broken for FOSS users (due to original download location changes by vendor)" : package.PackageTestResultStatus == "Failing" ? " - Possibly broken" : string.Empty,
289-
config.ListCommand.ShowLastUpdatedDate ? package.Published?.ToString(" yyyy-MM-dd HH:mm:ss") ?? " Last updated not available" : string.Empty
290+
config.ListCommand.ShowLastUpdatedDate ? " {0}".FormatWith(packageInfo.LastUpdated) ?? " Last updated not available" : string.Empty
290291
))
291292
);
292293

@@ -300,7 +301,7 @@ Package url{6}
300301
Tags: {9}
301302
Software Site: {10}
302303
Software License: {11}{12}{13}{14}{15}{16}
303-
Description: {17}{18}{19}{20}{21}
304+
Description: {17}{18}{19}{20}{21}{22}
304305
".FormatWith(
305306
package.Title.EscapeCurlyBraces(),
306307
package.Published.GetValueOrDefault().UtcDateTime.ToShortDateString(),
@@ -337,6 +338,7 @@ Package url{6}
337338
!string.IsNullOrWhiteSpace(package.ReleaseNotes.ToStringSafe()) ? "{0} Release Notes: {1}".FormatWith(Environment.NewLine, package.ReleaseNotes.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n ")) : string.Empty,
338339
!string.IsNullOrWhiteSpace(deploymentlocation) ? "{0} Deployed to: '{1}'".FormatWith(Environment.NewLine, deploymentlocation) :string.Empty,
339340
!string.IsNullOrWhiteSpace(sourceInstalledFrom) ? "{0} Source package was installed from: '{1}'".FormatWith(Environment.NewLine, sourceInstalledFrom) : string.Empty,
341+
!string.IsNullOrWhiteSpace(lastUpdated) ? "{0} Last updated: {1}".FormatWith(Environment.NewLine, lastUpdated) : string.Empty,
340342
packageArgumentsUnencrypted != null ? packageArgumentsUnencrypted : string.Empty
341343
));
342344
}

0 commit comments

Comments
 (0)