win_chocolatey: fix regression around using all as a package name (#43483)

This commit is contained in:
Jordan Borean 2018-08-06 07:33:55 +10:00 committed by GitHub
commit 8f8e3db067
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 9 deletions

View file

@ -294,12 +294,6 @@ Function Get-ChocolateyPackageVersion {
[Parameter(Mandatory=$true)][String]$choco_path,
[Parameter(Mandatory=$true)][String]$name
)
# returns the package version or null if it isn't installed
# all is a special case where we want to say it isn't installed, in choco
# it means runs on all the packages installed
if ($name -eq "all") {
return $null
}
$command = Argv-ToString -arguments @($choco_path, "list", "--local-only", "--exact", "--limit-output", $name)
$res = Run-Command -command $command
@ -501,7 +495,16 @@ $choco_path = Install-Chocolatey -proxy_url $proxy_url -proxy_username $proxy_us
# get the version of all specified packages
$package_info = @{}
foreach ($package in $name) {
$package_version = Get-ChocolateyPackageVersion -choco_path $choco_path -name $package
# all is a special package name that means all installed packages, we set
# a dummy version so absent, latest, and downgrade will run with all
if ($package -eq "all") {
if ($state -in @("present", "reinstalled")) {
Fail-Json -obj $result -message "Cannot specify the package name as 'all' when state=$state"
}
$package_version = "0.0.0"
} else {
$package_version = Get-ChocolateyPackageVersion -choco_path $choco_path -name $package
}
$package_info.$package = $package_version
}
@ -535,7 +538,7 @@ if ($state -in @("downgrade", "latest", "present", "reinstalled")) {
foreach ($package in $name) {
$package_version = ($package_info.GetEnumerator() | Where-Object { $name -eq $_.Key -and $null -ne $_.Value }).Value
if ($null -ne $package_version -and $package_version -ne $version) {
Fail-Json -obj $result -message "Chocolatey package '$package' is already installed at version '$package_version' but was expecting '$version'. Either change the expected version, set state=latest, set allow_multiple_versions=yes, or set force=yes to continue"
Fail-Json -obj $result -message "Chocolatey package '$package' is already installed at version '$package_version' but was expecting '$version'. Either change the expected version, set state=latest, or set force=yes to continue"
}
}
}