From d38d40a27ada42bd15e49edbd618990d947ceece Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Tue, 12 Mar 2019 20:22:12 -0500 Subject: [PATCH 1/8] (GH-1614) Quote source name if includes pipe Also quote the source name if it includes a pipe character. --- .../services/ChocolateyConfigSettingsService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs index 14fb95ee4b..9e1cd0e733 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs @@ -75,7 +75,7 @@ public virtual IEnumerable source_list(ChocolateyConfiguration else { this.Log().Info(() => "{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}".format_with( - source.Id, + source.Id.quote_if_pipe_found(), source.Value, source.Disabled.to_string(), source.UserName.quote_if_pipe_found(), From c18afec18bb982bc35c285caec4e3481328c301e Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Tue, 12 Mar 2019 20:24:13 -0500 Subject: [PATCH 2/8] (doc) add step for rebasing prior to merging If following the steps there is a need to get the latest from upstream and rebase, and a merge has already occurred, the merge commit is lost. Add a step to ensure that the rebase from upstream has happened just before merging the PR branch into the main branch. --- COMMITTERS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/COMMITTERS.md b/COMMITTERS.md index 5ac6df4047..2c5d186d5c 100644 --- a/COMMITTERS.md +++ b/COMMITTERS.md @@ -75,6 +75,7 @@ Because we ask contributors to target master, sometimes a fix/enhancement may ne * `build.bat` - build and test * Any additional changes or testing here. * `git checkout stable` + * `git fetch upstream` - if this pulls anything, make sure to also run `git rebase upstream/stable` prior to merging or you will lose the merge commit. * `git merge pr --log --no-ff` * `git branch -d pr` * `git checkout master` From 05912e1660aca5d8b25a1d02b88e0abf1a96afa0 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 13 Mar 2019 10:20:49 -0500 Subject: [PATCH 3/8] (GH-1602) exit 2 on items outdated When items are outdated, the exit should indicate that it is not all good to go as there is possible work to do. A zero exit code should only be used if choco outdated does not return any results. - Exit of 0 indicates all up to date - Exit of 2 indicates out of date packages - Exit of 1 or -1 would indicate an error --- .../infrastructure.app/services/ChocolateyPackageService.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 3ef31c147a..753370d622 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -656,6 +656,11 @@ Output is package name | current version | available version | pinned? } } + if (oudatedPackages.Count != 0 && Environment.ExitCode == 0) + { + Environment.ExitCode = 2; + } + randomly_notify_about_pro_business(config); } From 88bd5a872c1616215b600a08d7a34eca681a4f22 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 13 Mar 2019 10:21:02 -0500 Subject: [PATCH 4/8] (maint) fix typo --- .../services/ChocolateyPackageService.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 753370d622..3ba579f767 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -633,30 +633,30 @@ Output is package name | current version | available version | pinned? var output = config.RegularOutput; config.RegularOutput = false; - var oudatedPackages = _nugetService.get_outdated(config); + var outdatedPackages = _nugetService.get_outdated(config); config.RegularOutput = output; if (config.RegularOutput) { - var upgradeWarnings = oudatedPackages.Count(p => p.Value.Warning); + var upgradeWarnings = outdatedPackages.Count(p => p.Value.Warning); this.Log().Warn(() => @"{0}{1} has determined {2} package(s) are outdated. {3}".format_with( Environment.NewLine, ApplicationParameters.Name, - oudatedPackages.Count(p => p.Value.Success && !p.Value.Inconclusive), + outdatedPackages.Count(p => p.Value.Success && !p.Value.Inconclusive), upgradeWarnings == 0 ? string.Empty : "{0} {1} package(s) had warnings.".format_with(Environment.NewLine, upgradeWarnings) )); if (upgradeWarnings != 0) { this.Log().Warn(ChocolateyLoggers.Important, "Warnings:"); - foreach (var warning in oudatedPackages.Where(p => p.Value.Warning).or_empty_list_if_null()) + foreach (var warning in outdatedPackages.Where(p => p.Value.Warning).or_empty_list_if_null()) { this.Log().Warn(ChocolateyLoggers.Important, " - {0}".format_with(warning.Value.Name)); } } } - if (oudatedPackages.Count != 0 && Environment.ExitCode == 0) + if (outdatedPackages.Count != 0 && Environment.ExitCode == 0) { Environment.ExitCode = 2; } From 71cacb1840e69f8b8f16f8ef88de691fe4df6b1e Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 13 Mar 2019 10:28:00 -0500 Subject: [PATCH 5/8] (doc) add don't use nupkg to scripting guidelines Ensure folks understand that using 'nupkg' or pointing directly to the nupkg file is an antipattern. --- .../infrastructure.app/builders/ConfigurationBuilder.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index 59a9e3ec3b..aef581cc11 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -512,7 +512,12 @@ shortcut commands like `cinst` or `cup`. `choco source list`, where `source` is the command and `list` is the subcommand. * Typically the subject comes next. If installing packages, the - subject would be the package names. e.g. `choco install pkg1 pkg2`. + subject would be the package names, e.g. `choco install pkg1 pkg2`. + * Never use 'nupkg' or point directly to a nupkg file UNLESS using + 'choco push'. Use the source folder instead, e.g. `choco install + --source=""'c:\folder\with\package'""` instead of + `choco install DoNotDoThis.1.0.nupkg` or `choco install DoNotDoThis + --source=""'c:\folder\with\package\DoNotDoThis.1.0.nupkg'""`. * Switches and parameters are called simply options. Options come after the subject. e.g. `choco install pkg1 --debug --verbose`. * Never use the force option (`--force`/`-f`) in scripts (or really From 9d4c4ce2f329af570ab8b92dd0ec1f3ff58d9b59 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 13 Mar 2019 10:28:50 -0500 Subject: [PATCH 6/8] (doc) fix grammar in scripting guidelines Ensure that e.g. is started with a preceding comma instead of a period as it is illustrating the previous comments. --- .../infrastructure.app/builders/ConfigurationBuilder.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index aef581cc11..daff600795 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -534,15 +534,15 @@ online or through `choco -?` /`choco [Command Name] -?`. temporarily stop for input - the key here is temporarily. They will continue without requiring any action after the temporary timeout (typically 30 seconds). - * Full option names are prepended with two dashes. e.g. `--` or + * Full option names are prepended with two dashes, e.g. `--` or `--debug --verbose --ignore-proxy`. * When setting a value to an option, always put an equals (`=`) between the name and the setting, e.g. `--source=""'local'""`. * When setting a value to an option, always surround the value - properly with double quotes bookending apostrophes. e.g. + properly with double quotes bookending apostrophes, e.g. `--source=""'internal_server'""`. * If you are building PowerShell scripts, you can most likely just - simply use apostrophes surrounding option values e.g. + simply use apostrophes surrounding option values, e.g. `--source='internal_server'`. * Prefer upgrade to install in scripts. You can't `install` to a newer version of something, but you can `choco upgrade` which will do both From 3516bd4154b09592074e8195408a16cc5a601120 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Tue, 12 Mar 2019 12:00:59 +0000 Subject: [PATCH 7/8] (GH-1689) Delete packaging scripts before upgrade It is possible, due to the way that Package Reducer works, that there are extra files left in the package directory when doing an upgrade of a package. This can cause a package upgrade to fail. Prior to performing the upgrade, delete all packaging scripts (chocolateyInstall, chocolateyUninstall, and chocolateyBeforeModify) from the package folder, these will then be replaced during the upgrade, if they are still required.. --- .../services/NugetService.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 63159fd59d..b38ea3fc59 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -1146,6 +1146,8 @@ public virtual void backup_existing_version(ChocolateyConfiguration config, IPac try { _fileSystem.copy_directory(backupLocation, pkgInstallPath, overwriteExisting: true); + + remove_packaging_files_prior_to_upgrade(pkgInstallPath, config.CommandName); } catch (Exception ex) { @@ -1167,6 +1169,29 @@ process locking the folder or files. Please make sure nothing is } } + public virtual void remove_packaging_files_prior_to_upgrade(string directoryPath, string commandName) + { + if (commandName.to_lower() == "upgrade") + { + // Due to the way that Package Reducer works, there is a potential that a Chocolatey Packaging + // script could be incorrectly left in place during an upgrade operation. To guard against this, + // remove any Chocolatey Packaging scripts, which will then be restored by the new package, if + // they are still required + var filesToDelete = new List {"chocolateyinstall", "chocolateyuninstall", "chocolateybeforemodify"}; + var packagingScripts = _fileSystem.get_files(directoryPath, "*.ps1", SearchOption.AllDirectories) + .Where(p => filesToDelete.Contains(_fileSystem.get_file_name_without_extension(p).to_lower())); + + foreach (var packagingScript in packagingScripts) + { + if (_fileSystem.file_exists(packagingScript)) + { + this.Log().Debug("Deleting file {0}".format_with(packagingScript)); + _fileSystem.delete_file(packagingScript); + } + } + } + } + public virtual void backup_changed_files(string packageInstallPath, ChocolateyConfiguration config, ChocolateyPackageInformation packageInfo) { if (packageInfo == null || packageInfo.Package == null) return; From 57f966ff5b51cf43a56e9aa56f844384326ae0a1 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Wed, 13 Mar 2019 09:30:06 +0000 Subject: [PATCH 8/8] (maint) Corrected whitespace --- src/chocolatey/infrastructure.app/services/NugetService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index b38ea3fc59..ae4d49a47e 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -899,7 +899,7 @@ public virtual ConcurrentDictionary get_outdated(Chocolat var pkgInfo = _packageInfoService.get_package_information(installedPackage); bool isPinned = pkgInfo.IsPinned; - // if the package is pinned and we are skipping pinned, + // if the package is pinned and we are skipping pinned, // move on quickly if (isPinned && config.OutdatedCommand.IgnorePinned) { @@ -918,7 +918,7 @@ public virtual ConcurrentDictionary get_outdated(Chocolat } var latestPackage = find_package(packageName, null, config, repository); - + if (latestPackage == null) { if (config.Features.IgnoreUnfoundPackagesOnUpgradeOutdated) continue; @@ -933,7 +933,7 @@ public virtual ConcurrentDictionary get_outdated(Chocolat } if (latestPackage.Version <= installedPackage.Version) continue; - + var packageResult = outdatedPackages.GetOrAdd(packageName, new PackageResult(latestPackage, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, latestPackage.Id))); string logMessage = "You have {0} v{1} installed. Version {2} is available based on your source(s).{3} Source(s): \"{4}\"".format_with(installedPackage.Id, installedPackage.Version, latestPackage.Version, Environment.NewLine, config.Sources);