Skip to content

Commit

Permalink
(GH-358) Capture Arguments During Install/Upgrade
Browse files Browse the repository at this point in the history
If an install/upgrade is successful, capture arguments to be used later
during upgrades, like when upgrading all packages.
  • Loading branch information
ferventcoder committed Jun 12, 2016
1 parent 7a3bb89 commit c0c2520
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public ChocolateyPackageInformation(IPackage package)
public IPackage Package { get; set; }
public Registry RegistrySnapshot { get; set; }
public PackageFiles FilesSnapshot { get; set; }
public string Arguments { get; set; }
public bool HasSilentUninstall { get; set; }
public bool IsSideBySide { get; set; }
public bool IsPinned { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal class ChocolateyPackageInformationService : IChocolateyPackageInformati
private const string SILENT_UNINSTALLER_FILE = ".silentUninstaller";
private const string SIDE_BY_SIDE_FILE = ".sxs";
private const string PIN_FILE = ".pin";
private const string ARGS_FILE = ".arguments";

public ChocolateyPackageInformationService(IFileSystem fileSystem, IRegistryService registryService, IFilesService filesService)
{
Expand Down Expand Up @@ -79,6 +80,8 @@ public ChocolateyPackageInformation get_package_information(IPackage package)
packageInformation.HasSilentUninstall = _fileSystem.file_exists(_fileSystem.combine_paths(pkgStorePath, SILENT_UNINSTALLER_FILE));
packageInformation.IsSideBySide = _fileSystem.file_exists(_fileSystem.combine_paths(pkgStorePath, SIDE_BY_SIDE_FILE));
packageInformation.IsPinned = _fileSystem.file_exists(_fileSystem.combine_paths(pkgStorePath, PIN_FILE));
var argsFile = _fileSystem.combine_paths(pkgStorePath, ARGS_FILE);
if (_fileSystem.file_exists(argsFile)) packageInformation.Arguments = _fileSystem.read_file(argsFile);

return packageInformation;
}
Expand Down Expand Up @@ -107,6 +110,13 @@ public void save_package_information(ChocolateyPackageInformation packageInforma
_filesService.save_to_file(packageInformation.FilesSnapshot, _fileSystem.combine_paths(pkgStorePath, FILES_SNAPSHOT_FILE));
}

if (!string.IsNullOrWhiteSpace(packageInformation.Arguments))
{
var argsFile = _fileSystem.combine_paths(pkgStorePath, ARGS_FILE);
if (_fileSystem.file_exists(argsFile)) _fileSystem.delete_file(argsFile);
_fileSystem.write_file(argsFile,packageInformation.Arguments);
}

if (packageInformation.HasSilentUninstall)
{
_fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, SILENT_UNINSTALLER_FILE), string.Empty, Encoding.ASCII);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace chocolatey.infrastructure.app.services
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using builders;
using commandline;
using configuration;
Expand All @@ -30,6 +31,7 @@ namespace chocolatey.infrastructure.app.services
using infrastructure.services;
using logging;
using NuGet;
using nuget;
using platforms;
using results;
using tolerance;
Expand Down Expand Up @@ -331,6 +333,7 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu
{
handle_extension_packages(config, packageResult);
handle_template_packages(config, packageResult);
pkgInfo.Arguments = capture_arguments(config, packageResult);
}

var toolsLocation = Environment.GetEnvironmentVariable(ApplicationParameters.ChocolateyToolsLocationEnvironmentVariableName);
Expand Down Expand Up @@ -384,6 +387,39 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu
}
}

private string capture_arguments(ChocolateyConfiguration config, PackageResult packageResult)
{
var arguments = new StringBuilder();

// use the config to reconstruct
arguments.Append(" --source=\"'{0}'\"".format_with(config.Sources));
if (config.Prerelease) arguments.Append(" --prerelease");
if (config.ForceX86) arguments.Append(" --forcex86");
if (!string.IsNullOrWhiteSpace(config.InstallArguments)) arguments.Append(" --install-arguments=\"'{0}'\"".format_with(config.InstallArguments));
if (config.OverrideArguments) arguments.Append(" --override-arguments");
if (!string.IsNullOrWhiteSpace(config.PackageParameters)) arguments.Append(" --package-parameters=\"'{0}'\"".format_with(config.PackageParameters));
if (config.AllowDowngrade) arguments.Append(" --allow-downgrade");
if (config.AllowMultipleVersions) arguments.Append(" --allow-multiple-versions");
if (config.IgnoreDependencies) arguments.Append(" --ignore-dependencies");
if (config.SkipPackageInstallProvider) arguments.Append(" --skip-automation-scripts");
if (config.UpgradeCommand.FailOnUnfound) arguments.Append(" --fail-on-unfound");
if (!string.IsNullOrWhiteSpace(config.SourceCommand.Username)) arguments.Append(" --user=\"'{0}'\"".format_with(config.SourceCommand.Username));
if (!string.IsNullOrWhiteSpace(config.SourceCommand.Password)) arguments.Append(" --password=\"'{0}'\"".format_with(NugetEncryptionUtility.EncryptString(config.SourceCommand.Password)));
if (!string.IsNullOrWhiteSpace(config.SourceCommand.Certificate)) arguments.Append(" --cert=\"'{0}'\"".format_with(config.SourceCommand.Certificate));
if (!string.IsNullOrWhiteSpace(config.SourceCommand.CertificatePassword)) arguments.Append(" --certpassword=\"'{0}'\"".format_with(NugetEncryptionUtility.EncryptString(config.SourceCommand.CertificatePassword)));
if (!config.Features.CheckSumFiles) arguments.Append(" --ignore-checksums");
arguments.Append(config.Features.UsePackageExitCodes ? " --use-package-exit-codes" : " --ignore-package-exit-codes");

//global options
arguments.Append(" --execution-timeout=\"'{0}'\"".format_with(config.CommandExecutionTimeoutSeconds));
if (!string.IsNullOrWhiteSpace(config.CacheLocation)) arguments.Append(" --cache-location=\"'{0}'\"".format_with(config.CacheLocation));
if (config.Features.FailOnStandardError) arguments.Append(" --fail-on-error-output");
if (!config.Features.UsePowerShellHost) arguments.Append(" --use-system-powershell");


return arguments.to_string();
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config)
{
this.Log().Info(@"Installing the following packages:");
Expand Down

0 comments on commit c0c2520

Please sign in to comment.