From 7a040178cca5bd5073dd3a5a80ccf092349bf2d1 Mon Sep 17 00:00:00 2001 From: swaran18999 Date: Fri, 22 Aug 2025 18:09:00 -0500 Subject: [PATCH 01/12] (#1276) Add option to show last updated date in `choco list` Add `--show-last-updated-date` option to the `list` command. When enabled, this displays the last date the package was installed or updated, alongside the usual metadata fields. Previously, users had no clear indication of when a local package was last changed. This new option provides better visibility and helps with package management, especially when filtering or sorting package lists by recency. Implementation details: - Introduced new switch `show-last-updated-date`. - Logs formatted date via `package.Published` (or fallback string if unavailable). - Integrated into existing `list` command output formatting. With this change, users can more easily audit their package states and track updates over time. --- .../infrastructure.app/commands/ChocolateyListCommand.cs | 5 ++++- .../configuration/ChocolateyConfiguration.cs | 1 + src/chocolatey/infrastructure.app/services/NugetService.cs | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index e380aca4cf..22a7c6d6e3 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -138,7 +138,10 @@ public virtual void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfi option => configuration.Verbose = option != null) .Add("ignore-pinned", "Ignore Pinned - Ignore pinned packages. Defaults to false.", - option => configuration.ListCommand.IgnorePinned = option != null); + option => configuration.ListCommand.IgnorePinned = option != null) + .Add("show-last-updated-date", + "Show Date - Shows the last date the package was installed/updated.", + option => configuration.ListCommand.ShowLastUpdatedDate = option != null); } public virtual int Count(ChocolateyConfiguration config) diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index c0bfe9f9c0..ad0ddf7040 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -626,6 +626,7 @@ public ListCommandConfiguration() public bool ByTagOnly { get; set; } public bool IdStartsWith { get; set; } public bool IgnorePinned { get; set; } + public bool ShowLastUpdatedDate { get; set; } public PackageOrder OrderBy { get; set; } [Obsolete("This property is deprecated and will be removed in version 3.0. Use the 'OrderBy' property instead.")] diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 5f56905196..a2ebbc13c2 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -276,11 +276,12 @@ it is possible that incomplete package lists are returned from a command { if (!(packageInfo != null && packageInfo.IsPinned && config.ListCommand.IgnorePinned)) { - this.Log().Info(logger, () => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3}".FormatWith( + this.Log().Info(logger, () => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3} {4}".FormatWith( packageLocalMetadata != null ? packageLocalMetadata.Version.ToFullStringChecked() : package.Identity.Version.ToFullStringChecked(), package.IsApproved ? " [Approved]" : string.Empty, package.IsDownloadCacheAvailable ? " Downloads cached for licensed users" : string.Empty, - 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 + 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, + config.ListCommand.ShowLastUpdatedDate ? package.Published?.ToString("yyyy-MM-dd HH:mm:ss") ?? "Last updated not available" : string.Empty )) ); From 424b9f7a35463962092dc2e6c82c2d095edf9128 Mon Sep 17 00:00:00 2001 From: swaran18999 Date: Mon, 22 Sep 2025 20:03:11 -0500 Subject: [PATCH 02/12] (chocolatey#1276) Add tab completion support for new list options Update `ChocolateyTabExpansion.ps1` to include the new `--show-last-updated-date` and `--order-by-last-updated-date` switches in the `list` command's tab completion options. --- src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 index cbd9fd908f..d3b33b08d3 100644 --- a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 +++ b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 @@ -49,7 +49,7 @@ $commandOptions = @{ info = "--cert='' --certpassword='' --disable-repository-optimizations --include-configured-sources --local-only --password='' --prerelease --source='' --user='' --version=''" install = "--allow-downgrade --allow-empty-checksums --allow-empty-checksums-secure --apply-args-to-dependencies --apply-package-parameters-to-dependencies --cert='' --certpassword='' --disable-repository-optimizations --download-checksum='' --download-checksum-x64='' --download-checksum-type='' --download-checksum-type-x64='' --exit-when-reboot-detected --force-dependencies --forcex86 --ignore-checksum --ignore-dependencies --ignore-detected-reboot --ignore-package-exit-codes --include-configured-sources --install-arguments='' --not-silent --override-arguments --package-parameters='' --password='' --pin --prerelease --require-checksums --skip-hooks --skip-scripts --source='' --stop-on-first-failure --use-package-exit-codes --user='' --version=''" license = "" - list = "--by-id-only --by-tag-only --detail --exact --id-only --id-starts-with --ignore-pinned --include-programs --page='' --page-size='' --prerelease --source='' --version=''" + list = "--by-id-only --by-tag-only --detail --exact --id-only --id-starts-with --ignore-pinned --include-programs --order-by-last-updated-date --page='' --page-size='' --prerelease --show-last-updated-date --source='' --version=''" new = "--automaticpackage --download-checksum='' --download-checksum-x64='' --download-checksum-type='' --maintainer='' --name='' --output-directory='' --template='' --use-built-in-template --version=''" outdated = "--cert='' --certpassword='' --disable-repository-optimizations --ignore-pinned --ignore-unfound --include-configured-sources --password='' --prerelease --source='' --user=''" pack = "--output-directory='' --version=''" From 60dcb8a279ad33215ddc426de8d8de6ab0161a44 Mon Sep 17 00:00:00 2001 From: swaran18999 Date: Mon, 22 Sep 2025 20:06:01 -0500 Subject: [PATCH 03/12] (chocolatey#1276) Refactor space changes and added last update dated --- src/chocolatey/infrastructure.app/services/NugetService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index a2ebbc13c2..c0c4d28b56 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -276,12 +276,12 @@ it is possible that incomplete package lists are returned from a command { if (!(packageInfo != null && packageInfo.IsPinned && config.ListCommand.IgnorePinned)) { - this.Log().Info(logger, () => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3} {4}".FormatWith( + this.Log().Info(logger, () => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3}{4}".FormatWith( packageLocalMetadata != null ? packageLocalMetadata.Version.ToFullStringChecked() : package.Identity.Version.ToFullStringChecked(), package.IsApproved ? " [Approved]" : string.Empty, package.IsDownloadCacheAvailable ? " Downloads cached for licensed users" : string.Empty, 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, - config.ListCommand.ShowLastUpdatedDate ? package.Published?.ToString("yyyy-MM-dd HH:mm:ss") ?? "Last updated not available" : string.Empty + config.ListCommand.ShowLastUpdatedDate ? package.Published?.ToString(" yyyy-MM-dd HH:mm:ss") ?? " Last updated not available" : string.Empty )) ); From 644bf84f36e339068a0ad05c3310594e19855bd9 Mon Sep 17 00:00:00 2001 From: swaran18999 Date: Fri, 22 Aug 2025 18:09:00 -0500 Subject: [PATCH 04/12] (#1276) Add option to show last updated date in `choco list` Add `--show-last-updated-date` option to the `list` command. When enabled, this displays the last date the package was installed or updated, alongside the usual metadata fields. Previously, users had no clear indication of when a local package was last changed. This new option provides better visibility and helps with package management, especially when filtering or sorting package lists by recency. Implementation details: - Introduced new switch `show-last-updated-date`. - Logs formatted date via `package.Published` (or fallback string if unavailable). - Integrated into existing `list` command output formatting. With this change, users can more easily audit their package states and track updates over time. --- .../infrastructure.app/commands/ChocolateyListCommand.cs | 5 ++++- .../configuration/ChocolateyConfiguration.cs | 1 + src/chocolatey/infrastructure.app/services/NugetService.cs | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index e380aca4cf..22a7c6d6e3 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -138,7 +138,10 @@ public virtual void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfi option => configuration.Verbose = option != null) .Add("ignore-pinned", "Ignore Pinned - Ignore pinned packages. Defaults to false.", - option => configuration.ListCommand.IgnorePinned = option != null); + option => configuration.ListCommand.IgnorePinned = option != null) + .Add("show-last-updated-date", + "Show Date - Shows the last date the package was installed/updated.", + option => configuration.ListCommand.ShowLastUpdatedDate = option != null); } public virtual int Count(ChocolateyConfiguration config) diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index c0bfe9f9c0..ad0ddf7040 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -626,6 +626,7 @@ public ListCommandConfiguration() public bool ByTagOnly { get; set; } public bool IdStartsWith { get; set; } public bool IgnorePinned { get; set; } + public bool ShowLastUpdatedDate { get; set; } public PackageOrder OrderBy { get; set; } [Obsolete("This property is deprecated and will be removed in version 3.0. Use the 'OrderBy' property instead.")] diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 5f56905196..a2ebbc13c2 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -276,11 +276,12 @@ it is possible that incomplete package lists are returned from a command { if (!(packageInfo != null && packageInfo.IsPinned && config.ListCommand.IgnorePinned)) { - this.Log().Info(logger, () => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3}".FormatWith( + this.Log().Info(logger, () => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3} {4}".FormatWith( packageLocalMetadata != null ? packageLocalMetadata.Version.ToFullStringChecked() : package.Identity.Version.ToFullStringChecked(), package.IsApproved ? " [Approved]" : string.Empty, package.IsDownloadCacheAvailable ? " Downloads cached for licensed users" : string.Empty, - 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 + 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, + config.ListCommand.ShowLastUpdatedDate ? package.Published?.ToString("yyyy-MM-dd HH:mm:ss") ?? "Last updated not available" : string.Empty )) ); From 0d400dc31bf8bfa619f69e0360e0588850e7ef00 Mon Sep 17 00:00:00 2001 From: swaran18999 Date: Mon, 22 Sep 2025 20:03:11 -0500 Subject: [PATCH 05/12] (chocolatey#1276) Add tab completion support for new list options Update `ChocolateyTabExpansion.ps1` to include the new `--show-last-updated-date` and `--order-by-last-updated-date` switches in the `list` command's tab completion options. --- src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 index cbd9fd908f..d3b33b08d3 100644 --- a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 +++ b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 @@ -49,7 +49,7 @@ $commandOptions = @{ info = "--cert='' --certpassword='' --disable-repository-optimizations --include-configured-sources --local-only --password='' --prerelease --source='' --user='' --version=''" install = "--allow-downgrade --allow-empty-checksums --allow-empty-checksums-secure --apply-args-to-dependencies --apply-package-parameters-to-dependencies --cert='' --certpassword='' --disable-repository-optimizations --download-checksum='' --download-checksum-x64='' --download-checksum-type='' --download-checksum-type-x64='' --exit-when-reboot-detected --force-dependencies --forcex86 --ignore-checksum --ignore-dependencies --ignore-detected-reboot --ignore-package-exit-codes --include-configured-sources --install-arguments='' --not-silent --override-arguments --package-parameters='' --password='' --pin --prerelease --require-checksums --skip-hooks --skip-scripts --source='' --stop-on-first-failure --use-package-exit-codes --user='' --version=''" license = "" - list = "--by-id-only --by-tag-only --detail --exact --id-only --id-starts-with --ignore-pinned --include-programs --page='' --page-size='' --prerelease --source='' --version=''" + list = "--by-id-only --by-tag-only --detail --exact --id-only --id-starts-with --ignore-pinned --include-programs --order-by-last-updated-date --page='' --page-size='' --prerelease --show-last-updated-date --source='' --version=''" new = "--automaticpackage --download-checksum='' --download-checksum-x64='' --download-checksum-type='' --maintainer='' --name='' --output-directory='' --template='' --use-built-in-template --version=''" outdated = "--cert='' --certpassword='' --disable-repository-optimizations --ignore-pinned --ignore-unfound --include-configured-sources --password='' --prerelease --source='' --user=''" pack = "--output-directory='' --version=''" From 953770796a7015e4f3d706e9d410ed5dee6e8ccd Mon Sep 17 00:00:00 2001 From: swaran18999 Date: Mon, 22 Sep 2025 20:06:01 -0500 Subject: [PATCH 06/12] (chocolatey#1276) Refactor space changes and added last update dated --- src/chocolatey/infrastructure.app/services/NugetService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index a2ebbc13c2..c0c4d28b56 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -276,12 +276,12 @@ it is possible that incomplete package lists are returned from a command { if (!(packageInfo != null && packageInfo.IsPinned && config.ListCommand.IgnorePinned)) { - this.Log().Info(logger, () => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3} {4}".FormatWith( + this.Log().Info(logger, () => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3}{4}".FormatWith( packageLocalMetadata != null ? packageLocalMetadata.Version.ToFullStringChecked() : package.Identity.Version.ToFullStringChecked(), package.IsApproved ? " [Approved]" : string.Empty, package.IsDownloadCacheAvailable ? " Downloads cached for licensed users" : string.Empty, 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, - config.ListCommand.ShowLastUpdatedDate ? package.Published?.ToString("yyyy-MM-dd HH:mm:ss") ?? "Last updated not available" : string.Empty + config.ListCommand.ShowLastUpdatedDate ? package.Published?.ToString(" yyyy-MM-dd HH:mm:ss") ?? " Last updated not available" : string.Empty )) ); From 24f74cd78ad8d4dfab66bf1f46dec2af661c3244 Mon Sep 17 00:00:00 2001 From: swaran18999 Date: Fri, 22 Aug 2025 18:12:33 -0500 Subject: [PATCH 07/12] (#1276) Add option to order packages by last updated date Add `--order-by-last-updated-date` option to the `list` command. When used, the command output is ordered by the date each package was last installed or updated. Previously, package listings were only ordered by name or version. This limited users who wanted to quickly identify the most recently changed packages. With this new option, users gain more control over list output and can better manage their environments based on package activity. Implementation details: - Introduced new switch `order-by-last-updated-date`. - Maps user input to `PackageOrder.LastPublished`. - Integrates naturally into existing sort logic of `list`. --- .../infrastructure.app/commands/ChocolateyListCommand.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index 22a7c6d6e3..062e9275ea 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -141,7 +141,10 @@ public virtual void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfi option => configuration.ListCommand.IgnorePinned = option != null) .Add("show-last-updated-date", "Show Date - Shows the last date the package was installed/updated.", - option => configuration.ListCommand.ShowLastUpdatedDate = option != null); + option => configuration.ListCommand.ShowLastUpdatedDate = option != null) + .Add("order-by-last-updated-date", + "Order by Last Updated Date - Orders packages by date the package was installed/updated.", + option => configuration.ListCommand.OrderBy = PackageOrder.LastPublished); } public virtual int Count(ChocolateyConfiguration config) From 0d1a41436c0ce25592ebc532456a42550838e99e Mon Sep 17 00:00:00 2001 From: swaran18999 Date: Mon, 3 Nov 2025 20:46:15 -0800 Subject: [PATCH 08/12] (#1276) Persist .lastUpdated in package info Add support for reading and writing the .lastUpdated file for package information to track when packages were last modified. Add LastUpdated property to ChocolateyPackageInformation domain to store the timestamp. Update ChocolateyPackageInformationService.Get to read .lastUpdated files. Modify ChocolateyPackageInformationService.Save to persist or remove .lastUpdated files, fetching the current timestamp from NugetService via DateTime.Now. --- .../domain/ChocolateyPackageInformation.cs | 1 + .../ChocolateyPackageInformationService.cs | 32 +++++++++++++++++++ .../services/ChocolateyPackageService.cs | 1 + .../services/NugetService.cs | 8 +++-- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs index 697675b5aa..d5d90ac3d0 100644 --- a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs +++ b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs @@ -38,5 +38,6 @@ public ChocolateyPackageInformation(IPackageMetadata package) public string ExtraInformation { get; set; } public string DeploymentLocation { get; set; } public string SourceInstalledFrom { get; set; } + public string LastUpdated { get; set; } } } diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs index 3682325228..cc5f9e6bfb 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs @@ -46,6 +46,7 @@ public class ChocolateyPackageInformationService : IChocolateyPackageInformation private const string VersionOverrideFile = ".version"; private const string DeploymentLocationFile = ".deploymentLocation"; private const string SourceInstalledFromFile = ".sourceInstalledFrom"; + private const string LastUpdated = ".lastUpdated"; // We need to store the package identifiers we have warned about // to prevent duplicated outputs. @@ -208,6 +209,20 @@ has errored attempting to read it. This file will be renamed to logWarningInsteadOfError: true ); } + + var lastUpdated = _fileSystem.CombinePaths(pkgStorePath, LastUpdated); + if (_fileSystem.FileExists(lastUpdated)) + { + FaultTolerance.TryCatchWithLoggingException( + () => + { + packageInformation.LastUpdated = _fileSystem.ReadFile(lastUpdated); + }, + "Unable to read last updated from file", + throwError: false, + logWarningInsteadOfError: true + ); + } return packageInformation; } @@ -340,6 +355,23 @@ public void Save(ChocolateyPackageInformation packageInformation) { _fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, SourceInstalledFromFile)); } + + if (!string.IsNullOrWhiteSpace(packageInformation.LastUpdated)) + { + var lastUpdatedDate = _fileSystem.CombinePaths(pkgStorePath, LastUpdated); + if (_fileSystem.FileExists(lastUpdatedDate)) + { + _fileSystem.DeleteFile(lastUpdatedDate); + } + + _fileSystem.WriteFile(lastUpdatedDate, packageInformation.LastUpdated); + } + else + { + _fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, LastUpdated)); + } + + } public void Remove(IPackageMetadata package) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 14742a25a2..e10fdee351 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -566,6 +566,7 @@ public virtual void HandlePackageResult(PackageResult packageResult, ChocolateyC pkgInfo.DeploymentLocation = Environment.GetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation); pkgInfo.SourceInstalledFrom = packageResult.SourceInstalledFrom; + pkgInfo.LastUpdated = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); UpdatePackageInformation(pkgInfo); EnsureBadPackagesPathIsClean(packageResult); diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 57e1d9b39e..07c6577841 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -219,6 +219,7 @@ it is possible that incomplete package lists are returned from a command string packageInstallLocation = null; string deploymentlocation = null; string sourceInstalledFrom = null; + string lastUpdated = null; if (package.PackagePath != null && !string.IsNullOrWhiteSpace(package.PackagePath)) { @@ -240,7 +241,7 @@ it is possible that incomplete package lists are returned from a command packageInfo = _packageInfoService.Get(packageLocalMetadata); deploymentlocation = packageInfo.DeploymentLocation; sourceInstalledFrom = packageInfo.SourceInstalledFrom; - + lastUpdated = packageInfo.LastUpdated; if (config.ListCommand.IncludeVersionOverrides) { if (packageInfo.VersionOverride != null) @@ -286,7 +287,7 @@ it is possible that incomplete package lists are returned from a command package.IsApproved ? " [Approved]" : string.Empty, package.IsDownloadCacheAvailable ? " Downloads cached for licensed users" : string.Empty, 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, - config.ListCommand.ShowLastUpdatedDate ? package.Published?.ToString(" yyyy-MM-dd HH:mm:ss") ?? " Last updated not available" : string.Empty + config.ListCommand.ShowLastUpdatedDate ? " {0}".FormatWith(packageInfo.LastUpdated) ?? " Last updated not available" : string.Empty )) ); @@ -300,7 +301,7 @@ Package url{6} Tags: {9} Software Site: {10} Software License: {11}{12}{13}{14}{15}{16} - Description: {17}{18}{19}{20}{21} + Description: {17}{18}{19}{20}{21}{22} ".FormatWith( package.Title.EscapeCurlyBraces(), package.Published.GetValueOrDefault().UtcDateTime.ToShortDateString(), @@ -337,6 +338,7 @@ Package url{6} !string.IsNullOrWhiteSpace(package.ReleaseNotes.ToStringSafe()) ? "{0} Release Notes: {1}".FormatWith(Environment.NewLine, package.ReleaseNotes.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n ")) : string.Empty, !string.IsNullOrWhiteSpace(deploymentlocation) ? "{0} Deployed to: '{1}'".FormatWith(Environment.NewLine, deploymentlocation) :string.Empty, !string.IsNullOrWhiteSpace(sourceInstalledFrom) ? "{0} Source package was installed from: '{1}'".FormatWith(Environment.NewLine, sourceInstalledFrom) : string.Empty, + !string.IsNullOrWhiteSpace(lastUpdated) ? "{0} Last updated: {1}".FormatWith(Environment.NewLine, lastUpdated) : string.Empty, packageArgumentsUnencrypted != null ? packageArgumentsUnencrypted : string.Empty )); } From 0c9bfb53927f06bd3a4d3b1b4d0d9722977a22fa Mon Sep 17 00:00:00 2001 From: swaran18999 Date: Tue, 4 Nov 2025 20:38:10 -0800 Subject: [PATCH 09/12] (#1276]) Add LastUpdated ordering option for list command Add support for ordering packages by last updated date in the list command, providing users with a new sorting option to view packages by their most recent updates. --- .../helpers/ChocolateyTabExpansion.ps1 | 4 ++-- .../infrastructure.app/nuget/NugetListSpecs.cs | 1 + .../commands/ChocolateyListCommand.cs | 2 +- .../infrastructure.app/domain/PackageOrder.cs | 5 +++++ .../infrastructure.app/nuget/NugetList.cs | 7 +++++++ .../infrastructure.app/services/NugetService.cs | 8 ++++---- .../infrastructure/results/PackageResult.cs | 15 +++++++++++---- 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 index d3b33b08d3..e63070ae1f 100644 --- a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 +++ b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 @@ -242,9 +242,9 @@ function Get-ChocoOrderByOptions { manually when the enum changes. .OUTPUTS - A string in the format "Id|LastPublished|Popularity|Title|Unsorted" + A string in the format "Id|LastPublished|Popularity|Title|Unsorted|LastUpdated" #> - return @("Id", "LastPublished", "Popularity", "Title", "Unsorted") + return @("Id", "LastPublished", "Popularity", "Title", "Unsorted", "LastUpdated") } function ChocolateyTabExpansion($lastBlock) { diff --git a/src/chocolatey.tests.integration/infrastructure.app/nuget/NugetListSpecs.cs b/src/chocolatey.tests.integration/infrastructure.app/nuget/NugetListSpecs.cs index e470e08a01..7bcb842a6b 100644 --- a/src/chocolatey.tests.integration/infrastructure.app/nuget/NugetListSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure.app/nuget/NugetListSpecs.cs @@ -347,6 +347,7 @@ protected void AddV2MetadataResponse(string path) + diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index 062e9275ea..d6134952e7 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -144,7 +144,7 @@ public virtual void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfi option => configuration.ListCommand.ShowLastUpdatedDate = option != null) .Add("order-by-last-updated-date", "Order by Last Updated Date - Orders packages by date the package was installed/updated.", - option => configuration.ListCommand.OrderBy = PackageOrder.LastPublished); + option => configuration.ListCommand.OrderBy = PackageOrder.LastUpdated); } public virtual int Count(ChocolateyConfiguration config) diff --git a/src/chocolatey/infrastructure.app/domain/PackageOrder.cs b/src/chocolatey/infrastructure.app/domain/PackageOrder.cs index 0db14a85b9..2b93c3d30a 100644 --- a/src/chocolatey/infrastructure.app/domain/PackageOrder.cs +++ b/src/chocolatey/infrastructure.app/domain/PackageOrder.cs @@ -38,6 +38,11 @@ public enum PackageOrder /// LastPublished, + /// + /// Sort by last updated date, from newest to oldest. + /// + LastUpdated, + /// /// Do not sort; return packages in the order received from the source. /// diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index f91762c2e2..ede493a8b0 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -481,6 +481,13 @@ private static IOrderedEnumerable ApplyPackageSort(IEnum .ThenBy(q => q.Identity.Id) .ThenByDescending(q => q.Identity.Version); + case domain.PackageOrder.LastUpdated: + return query + .OrderByDescending(q => q.Published) + .ThenBy(q => q.Identity.Id) + .ThenByDescending(q => q.Identity.Version); + + default: // Since we return an IOrderedEnumerable, some form of ordering must be applied, // even when the user has not explicitly requested a sort order. diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 07c6577841..5dc21a0715 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -364,7 +364,7 @@ Package url{6} } else { - yield return new PackageResult(packageLocalMetadata, package, config.ListCommand.LocalOnly ? packageInstallLocation : null, config.Sources, null); + yield return new PackageResult(packageLocalMetadata, package, config.ListCommand.LocalOnly ? packageInstallLocation : null, config.Sources, null, lastUpdated); } } @@ -1004,7 +1004,7 @@ Version was specified as '{0}'. It is possible that version packageRemoteMetadata.PackageTestResultStatus == "Failing" && packageRemoteMetadata.IsDownloadCacheAvailable ? " - Likely broken for FOSS users (due to download location changes)" : packageRemoteMetadata.PackageTestResultStatus == "Failing" ? " - Possibly broken" : string.Empty )); - var packageResult = packageResultsToReturn.GetOrAdd(packageDependencyInfo.Id.ToLowerSafe(), new PackageResult(packageMetadata, packageRemoteMetadata, installedPath, null, packageDependencyInfo.Source.ToStringSafe())); + var packageResult = packageResultsToReturn.GetOrAdd(packageDependencyInfo.Id.ToLowerSafe(), new PackageResult(packageMetadata, packageRemoteMetadata, installedPath, null, packageDependencyInfo.Source.ToStringSafe(), null)); if (shouldAddForcedResultMessage) { packageResult.Messages.Add(new ResultMessage(ResultType.Note, "Backing up and removing old version")); @@ -1829,7 +1829,7 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon packageRemoteMetadata.PackageTestResultStatus == "Failing" && packageRemoteMetadata.IsDownloadCacheAvailable ? " - Likely broken for FOSS users (due to download location changes)" : packageRemoteMetadata.PackageTestResultStatus == "Failing" ? " - Possibly broken" : string.Empty )); - var upgradePackageResult = packageResultsToReturn.GetOrAdd(packageDependencyInfo.Id.ToLowerSafe(), new PackageResult(packageMetadata, packageRemoteMetadata, installedPath, null, packageDependencyInfo.Source.ToStringSafe())); + var upgradePackageResult = packageResultsToReturn.GetOrAdd(packageDependencyInfo.Id.ToLowerSafe(), new PackageResult(packageMetadata, packageRemoteMetadata, installedPath, null, packageDependencyInfo.Source.ToStringSafe(), null)); upgradePackageResult.ResetMetadata(packageMetadata, packageRemoteMetadata); upgradePackageResult.InstallLocation = installedPath; @@ -2905,7 +2905,7 @@ protected virtual void BackupAndRunBeforeModify( { "chocolatey".Log().Debug("Running beforeModify step for '{0}'", packageResult.PackageMetadata.Id); - var packageResultCopy = new PackageResult(packageResult.PackageMetadata, packageResult.SearchMetadata, packageResult.InstallLocation, packageResult.Source, null); + var packageResultCopy = new PackageResult(packageResult.PackageMetadata, packageResult.SearchMetadata, packageResult.InstallLocation, packageResult.Source, null, null); beforeModifyAction(packageResultCopy, config); diff --git a/src/chocolatey/infrastructure/results/PackageResult.cs b/src/chocolatey/infrastructure/results/PackageResult.cs index a64d5f8d7a..76295d5c31 100644 --- a/src/chocolatey/infrastructure/results/PackageResult.cs +++ b/src/chocolatey/infrastructure/results/PackageResult.cs @@ -71,6 +71,11 @@ public bool Warning /// The package source used to install the package. /// public string SourceInstalledFrom { get; set; } + + /// + /// When the packaage was last updated. + /// + public string LastUpdated { get; set; } public int ExitCode { get; set; } public void ResetMetadata(IPackageMetadata metadata, IPackageSearchMetadata search) @@ -141,8 +146,8 @@ public PackageResult(IPackageSearchMetadata packageSearch, string installLocatio } [Obsolete("This overload is deprecated and will be removed in v3.")] - public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source = null) - : this(packageMetadata, packageSearch, installLocation, source, null) { } + public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source = null, string lastUpdated = null) + : this(packageMetadata, packageSearch, installLocation, source, null, lastUpdated) { } /// /// Initializes a new instance of the class. @@ -152,12 +157,14 @@ public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata pa /// Assigned to /// Sources available during package installation. Assigned to /// The package source used to install the package. Assigned to - public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source, string sourceInstalledFrom) - : this(packageMetadata.Id, packageMetadata.Version.ToNormalizedStringChecked(), installLocation) + /// The last updated date of the package. Assigned to + public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source, string sourceInstalledFrom, string lastUpdated) + : this(packageMetadata.Id, packageMetadata.Version.ToNormalizedStringChecked(), installLocation, lastUpdated) { SearchMetadata = packageSearch; PackageMetadata = packageMetadata; SourceInstalledFrom = sourceInstalledFrom; + LastUpdated = lastUpdated; var sources = new List(); if (!string.IsNullOrEmpty(source)) { From a8437eaa81a34b941e13c8fb90df19b4b2acbc88 Mon Sep 17 00:00:00 2001 From: swaran18999 Date: Thu, 6 Nov 2025 18:28:57 -0800 Subject: [PATCH 10/12] (#1276]) Add LastUpdatedDate ordering with .lastUpdated file-based sorting Add LastUpdatedDate ordering option that reads from .lastUpdated files to sort packages by their actual update timestamps rather than remote publication dates. Add LastUpdatedDate enum value to PackageOrder with documentation explaining it uses .lastUpdated file data. Update ChocolateyListCommand to map --order-by-last-updated-date flag to PackageOrder.LastUpdatedDate instead of LastUpdated. Implement sorting logic in NugetList.ApplyPackageSort to read timestamp from .lastUpdated files using the FaultTolerance pattern for error handling. Sort packages by these timestamps in descending order with secondary sorting by ID and version. Make ChocolateyPackageInformationService.GetStorePath public to enable NugetList to access package storage paths for reading .lastUpdated files. --- .../commands/ChocolateyListCommand.cs | 2 +- .../infrastructure.app/domain/PackageOrder.cs | 5 +++ .../infrastructure.app/nuget/NugetList.cs | 31 +++++++++++++++++-- .../ChocolateyPackageInformationService.cs | 2 +- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index d6134952e7..c8e935a3c6 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -144,7 +144,7 @@ public virtual void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfi option => configuration.ListCommand.ShowLastUpdatedDate = option != null) .Add("order-by-last-updated-date", "Order by Last Updated Date - Orders packages by date the package was installed/updated.", - option => configuration.ListCommand.OrderBy = PackageOrder.LastUpdated); + option => configuration.ListCommand.OrderBy = PackageOrder.LastUpdatedDate); } public virtual int Count(ChocolateyConfiguration config) diff --git a/src/chocolatey/infrastructure.app/domain/PackageOrder.cs b/src/chocolatey/infrastructure.app/domain/PackageOrder.cs index 2b93c3d30a..112df7ac5c 100644 --- a/src/chocolatey/infrastructure.app/domain/PackageOrder.cs +++ b/src/chocolatey/infrastructure.app/domain/PackageOrder.cs @@ -43,6 +43,11 @@ public enum PackageOrder /// LastUpdated, + /// + /// Sort by last updated date, from newest to oldest, fetched from the .lastUpdated file if available. + /// + LastUpdatedDate, + /// /// Do not sort; return packages in the order received from the source. /// diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index ede493a8b0..ca4498a451 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -22,6 +22,7 @@ using chocolatey.infrastructure.tolerance; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.filesystem; +using chocolatey.infrastructure.app.services; using NuGet.Common; using NuGet.Packaging; using NuGet.Packaging.Core; @@ -36,6 +37,8 @@ public static class NugetList public static bool ThresholdHit { get; private set; } public static bool LowerThresholdHit { get; private set; } + private const string LastUpdated = ".lastUpdated"; + public static IEnumerable GetPackages(ChocolateyConfiguration configuration, ILogger nugetLogger, IFileSystem filesystem) { return SearchPackagesAsync(configuration, nugetLogger, filesystem).GetAwaiter().GetResult(); @@ -320,7 +323,7 @@ private async static Task> SearchPackagesAsyn results = results.Where(p => (p.IsDownloadCacheAvailable && configuration.Information.IsLicensedVersion) || p.PackageTestResultStatus != "Failing").ToHashSet(); } - results = ApplyPackageSort(results, configuration.ListCommand.OrderBy).ToHashSet(); + results = ApplyPackageSort(results, configuration.ListCommand.OrderBy, filesystem).ToHashSet(); return results.AsQueryable(); } @@ -453,7 +456,7 @@ public static IPackageSearchMetadata FindPackage( return packagesList.OrderByDescending(p => p.Identity.Version).FirstOrDefault(); } - private static IOrderedEnumerable ApplyPackageSort(IEnumerable query, domain.PackageOrder orderBy) + private static IOrderedEnumerable ApplyPackageSort(IEnumerable query, domain.PackageOrder orderBy, IFileSystem filesystem) { switch (orderBy) { @@ -487,6 +490,30 @@ private static IOrderedEnumerable ApplyPackageSort(IEnum .ThenBy(q => q.Identity.Id) .ThenByDescending(q => q.Identity.Version); + case domain.PackageOrder.LastUpdatedDate: + return query + .OrderByDescending(q => + { + string lastUpdatedContent = null; + var pkgStorePath = ChocolateyPackageInformationService.GetStorePath(filesystem, q.Identity.Id, q.Identity.Version); + var lastUpdated = filesystem.CombinePaths(pkgStorePath, LastUpdated); + if (filesystem.FileExists(lastUpdated)) + { + FaultTolerance.TryCatchWithLoggingException( + () => + { + lastUpdatedContent = filesystem.ReadFile(lastUpdated); + }, + "Unable to read last updated from file", + throwError: false, + logWarningInsteadOfError: true + ); + } + return lastUpdatedContent; + }) + .ThenBy(q => q.Identity.Id) + .ThenByDescending(q => q.Identity.Version); + default: // Since we return an IOrderedEnumerable, some form of ordering must be applied, diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs index cc5f9e6bfb..4e1016ffb2 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs @@ -385,7 +385,7 @@ public void Remove(IPackageMetadata package) _fileSystem.DeleteDirectoryChecked(pkgStorePath, recursive: true); } - private static string GetStorePath(IFileSystem fileSystem, string id, NuGetVersion version) + public static string GetStorePath(IFileSystem fileSystem, string id, NuGetVersion version) { var preferredStorePath = fileSystem.CombinePaths(ApplicationParameters.ChocolateyPackageInfoStoreLocation, "{0}.{1}".FormatWith(id, version.ToNormalizedStringChecked())); From 17bd5e6dbdaad5b79749ea81ffdabcc25b97245a Mon Sep 17 00:00:00 2001 From: swaran18999 Date: Thu, 6 Nov 2025 18:34:10 -0800 Subject: [PATCH 11/12] (#1276]) Consolidate LastUpdated ordering implementation Remove duplicate LastUpdatedDate enum value and consolidate into the existing LastUpdated ordering option. Update ChocolateyListCommand to use PackageOrder.LastUpdated for the --order-by-last-updated-date flag. Remove LastUpdatedDate case from NugetList.ApplyPackageSort switch statement, leaving only the LastUpdated implementation that reads from .lastUpdated files. Remove LastUpdated property from integration test OData schema expectations as it is not needed. --- .../infrastructure.app/nuget/NugetListSpecs.cs | 1 - .../infrastructure.app/commands/ChocolateyListCommand.cs | 2 +- src/chocolatey/infrastructure.app/domain/PackageOrder.cs | 5 ----- src/chocolatey/infrastructure.app/nuget/NugetList.cs | 6 ------ 4 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/chocolatey.tests.integration/infrastructure.app/nuget/NugetListSpecs.cs b/src/chocolatey.tests.integration/infrastructure.app/nuget/NugetListSpecs.cs index 7bcb842a6b..e470e08a01 100644 --- a/src/chocolatey.tests.integration/infrastructure.app/nuget/NugetListSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure.app/nuget/NugetListSpecs.cs @@ -347,7 +347,6 @@ protected void AddV2MetadataResponse(string path) - diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index c8e935a3c6..d6134952e7 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -144,7 +144,7 @@ public virtual void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfi option => configuration.ListCommand.ShowLastUpdatedDate = option != null) .Add("order-by-last-updated-date", "Order by Last Updated Date - Orders packages by date the package was installed/updated.", - option => configuration.ListCommand.OrderBy = PackageOrder.LastUpdatedDate); + option => configuration.ListCommand.OrderBy = PackageOrder.LastUpdated); } public virtual int Count(ChocolateyConfiguration config) diff --git a/src/chocolatey/infrastructure.app/domain/PackageOrder.cs b/src/chocolatey/infrastructure.app/domain/PackageOrder.cs index 112df7ac5c..2b93c3d30a 100644 --- a/src/chocolatey/infrastructure.app/domain/PackageOrder.cs +++ b/src/chocolatey/infrastructure.app/domain/PackageOrder.cs @@ -43,11 +43,6 @@ public enum PackageOrder /// LastUpdated, - /// - /// Sort by last updated date, from newest to oldest, fetched from the .lastUpdated file if available. - /// - LastUpdatedDate, - /// /// Do not sort; return packages in the order received from the source. /// diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index ca4498a451..ee03a640df 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -485,12 +485,6 @@ private static IOrderedEnumerable ApplyPackageSort(IEnum .ThenByDescending(q => q.Identity.Version); case domain.PackageOrder.LastUpdated: - return query - .OrderByDescending(q => q.Published) - .ThenBy(q => q.Identity.Id) - .ThenByDescending(q => q.Identity.Version); - - case domain.PackageOrder.LastUpdatedDate: return query .OrderByDescending(q => { From d06205b1e2595c5b6473db4d9c2825e0fb84a4d7 Mon Sep 17 00:00:00 2001 From: swaran18999 Date: Thu, 6 Nov 2025 18:34:10 -0800 Subject: [PATCH 12/12] (#1276]) Consolidate LastUpdated ordering implementation Remove duplicate LastUpdatedDate enum value and consolidate into the existing LastUpdated ordering option. Update ChocolateyListCommand to use PackageOrder.LastUpdated for the --order-by-last-updated-date flag. Remove LastUpdatedDate case from NugetList.ApplyPackageSort switch statement, leaving only the LastUpdated implementation that reads from .lastUpdated files. Remove LastUpdated property from integration test OData schema expectations as it is not needed. --- .../infrastructure.app/nuget/NugetListSpecs.cs | 1 - .../infrastructure.app/commands/ChocolateyListCommand.cs | 2 +- src/chocolatey/infrastructure.app/domain/PackageOrder.cs | 5 ----- src/chocolatey/infrastructure.app/nuget/NugetList.cs | 6 ------ .../services/ChocolateyPackageInformationService.cs | 2 +- src/chocolatey/infrastructure.app/services/NugetService.cs | 1 + 6 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/chocolatey.tests.integration/infrastructure.app/nuget/NugetListSpecs.cs b/src/chocolatey.tests.integration/infrastructure.app/nuget/NugetListSpecs.cs index 7bcb842a6b..e470e08a01 100644 --- a/src/chocolatey.tests.integration/infrastructure.app/nuget/NugetListSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure.app/nuget/NugetListSpecs.cs @@ -347,7 +347,6 @@ protected void AddV2MetadataResponse(string path) - diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index c8e935a3c6..d6134952e7 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -144,7 +144,7 @@ public virtual void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfi option => configuration.ListCommand.ShowLastUpdatedDate = option != null) .Add("order-by-last-updated-date", "Order by Last Updated Date - Orders packages by date the package was installed/updated.", - option => configuration.ListCommand.OrderBy = PackageOrder.LastUpdatedDate); + option => configuration.ListCommand.OrderBy = PackageOrder.LastUpdated); } public virtual int Count(ChocolateyConfiguration config) diff --git a/src/chocolatey/infrastructure.app/domain/PackageOrder.cs b/src/chocolatey/infrastructure.app/domain/PackageOrder.cs index 112df7ac5c..2b93c3d30a 100644 --- a/src/chocolatey/infrastructure.app/domain/PackageOrder.cs +++ b/src/chocolatey/infrastructure.app/domain/PackageOrder.cs @@ -43,11 +43,6 @@ public enum PackageOrder /// LastUpdated, - /// - /// Sort by last updated date, from newest to oldest, fetched from the .lastUpdated file if available. - /// - LastUpdatedDate, - /// /// Do not sort; return packages in the order received from the source. /// diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index ca4498a451..ee03a640df 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -485,12 +485,6 @@ private static IOrderedEnumerable ApplyPackageSort(IEnum .ThenByDescending(q => q.Identity.Version); case domain.PackageOrder.LastUpdated: - return query - .OrderByDescending(q => q.Published) - .ThenBy(q => q.Identity.Id) - .ThenByDescending(q => q.Identity.Version); - - case domain.PackageOrder.LastUpdatedDate: return query .OrderByDescending(q => { diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs index 4e1016ffb2..6be2845602 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs @@ -385,7 +385,7 @@ public void Remove(IPackageMetadata package) _fileSystem.DeleteDirectoryChecked(pkgStorePath, recursive: true); } - public static string GetStorePath(IFileSystem fileSystem, string id, NuGetVersion version) + internal static string GetStorePath(IFileSystem fileSystem, string id, NuGetVersion version) { var preferredStorePath = fileSystem.CombinePaths(ApplicationParameters.ChocolateyPackageInfoStoreLocation, "{0}.{1}".FormatWith(id, version.ToNormalizedStringChecked())); diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 5dc21a0715..06cb6ea38f 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -242,6 +242,7 @@ it is possible that incomplete package lists are returned from a command deploymentlocation = packageInfo.DeploymentLocation; sourceInstalledFrom = packageInfo.SourceInstalledFrom; lastUpdated = packageInfo.LastUpdated; + if (config.ListCommand.IncludeVersionOverrides) { if (packageInfo.VersionOverride != null)