Skip to content

Commit

Permalink
Merge branch 'ticket/stable/GH-942-version_overrides' into stable
Browse files Browse the repository at this point in the history
* ticket/stable/GH-942-version_overrides:
  (GH-942) Override local version
  • Loading branch information
ferventcoder committed Mar 21, 2017
2 parents d8f4273 + 8a918f0 commit 17c9866
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
Expand Up @@ -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]
Expand Down
Expand Up @@ -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; }
Expand Down
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Expand Up @@ -115,6 +115,7 @@ public IEnumerable<PackageResult> 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));
Expand All @@ -128,6 +129,18 @@ public IEnumerable<PackageResult> 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)
Expand Down Expand Up @@ -1324,9 +1337,12 @@ private IEnumerable<PackageResult> 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;
Expand Down

0 comments on commit 17c9866

Please sign in to comment.