diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 0cbf5c0ff7..f708be906b 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -388,6 +388,7 @@ public ListCommandConfiguration() public bool ApprovedOnly { get; set; } public bool DownloadCacheAvailable { get; set; } public bool NotBroken { get; set; } + public bool IncludeVersionOverrides { get; set; } } [Serializable] diff --git a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs index 5bed532c57..19fcbe6113 100644 --- a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs +++ b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs @@ -28,6 +28,7 @@ public ChocolateyPackageInformation(IPackage package) public Registry RegistrySnapshot { get; set; } public PackageFiles FilesSnapshot { get; set; } public string Arguments { get; set; } + public SemanticVersion VersionOverride { get; set; } public bool HasSilentUninstall { get; set; } public bool IsSideBySide { get; set; } public bool IsPinned { get; set; } diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs index fa1c3825c3..49063bf3e9 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs @@ -34,6 +34,7 @@ internal class ChocolateyPackageInformationService : IChocolateyPackageInformati private const string SIDE_BY_SIDE_FILE = ".sxs"; private const string PIN_FILE = ".pin"; private const string ARGS_FILE = ".arguments"; + private const string VERSION_OVERRIDE_FILE = ".version"; public ChocolateyPackageInformationService(IFileSystem fileSystem, IRegistryService registryService, IFilesService filesService) { @@ -83,6 +84,21 @@ public ChocolateyPackageInformation get_package_information(IPackage package) var argsFile = _fileSystem.combine_paths(pkgStorePath, ARGS_FILE); if (_fileSystem.file_exists(argsFile)) packageInformation.Arguments = _fileSystem.read_file(argsFile); + var versionOverrideFile = _fileSystem.combine_paths(pkgStorePath, VERSION_OVERRIDE_FILE); + if (_fileSystem.file_exists(versionOverrideFile)) + { + + FaultTolerance.try_catch_with_logging_exception( + () => + { + packageInformation.VersionOverride = new SemanticVersion(_fileSystem.read_file(versionOverrideFile).trim_safe()); + }, + "Unable to read version override file", + throwError: false, + logWarningInsteadOfError: true + ); + } + return packageInformation; } @@ -114,7 +130,22 @@ public void save_package_information(ChocolateyPackageInformation packageInforma { var argsFile = _fileSystem.combine_paths(pkgStorePath, ARGS_FILE); if (_fileSystem.file_exists(argsFile)) _fileSystem.delete_file(argsFile); - _fileSystem.write_file(argsFile,packageInformation.Arguments); + _fileSystem.write_file(argsFile, packageInformation.Arguments); + } + else + { + _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, ARGS_FILE)); + } + + if (packageInformation.VersionOverride != null) + { + var versionOverrideFile = _fileSystem.combine_paths(pkgStorePath, VERSION_OVERRIDE_FILE); + if (_fileSystem.file_exists(versionOverrideFile)) _fileSystem.delete_file(versionOverrideFile); + _fileSystem.write_file(versionOverrideFile, packageInformation.VersionOverride.to_string()); + } + else + { + _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, VERSION_OVERRIDE_FILE)); } if (packageInformation.HasSilentUninstall) @@ -137,7 +168,7 @@ public void save_package_information(ChocolateyPackageInformation packageInforma else { _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, PIN_FILE)); - } + } } public void remove_package_information(IPackage package) diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 0afa51eec4..baca0c15e8 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -115,6 +115,7 @@ public IEnumerable list_run(ChocolateyConfiguration config) { config.Sources = ApplicationParameters.PackagesLocation; config.Prerelease = true; + config.ListCommand.IncludeVersionOverrides = true; } if (config.RegularOutput) this.Log().Debug(() => "Running list with the following filter = '{0}'".format_with(config.Input)); @@ -128,6 +129,18 @@ public IEnumerable list_run(ChocolateyConfiguration config) if (!pkg.Version.to_string().is_equal_to(config.Version)) continue; } + if (config.ListCommand.LocalOnly) + { + var packageInfo = _packageInfoService.get_package_information(package); + if (config.ListCommand.IncludeVersionOverrides) + { + if (packageInfo.VersionOverride != null) + { + package.OverrideOriginalVersion(packageInfo.VersionOverride); + } + } + } + if (!config.QuietOutput) { if (config.RegularOutput) @@ -1324,9 +1337,12 @@ private IEnumerable get_all_intalled_packages(ChocolateyConfigura config.Input = string.Empty; var quiet = config.QuietOutput; config.QuietOutput = true; + //changed by the command automatically when LocalOnly = true + var includeVersionOverrides = config.ListCommand.IncludeVersionOverrides; var installedPackages = list_run(config).ToList(); + config.ListCommand.IncludeVersionOverrides = includeVersionOverrides; config.QuietOutput = quiet; config.Input = input; config.PackageNames = packageNames;