-
Notifications
You must be signed in to change notification settings - Fork 109
(GH-95) Allow for upgrading of packages #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
8aa297c
d19da2c
320ba4e
391091d
b81c7c4
dd0c3ff
e6e48f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,10 +117,28 @@ function Set-TargetResource | |
| $whatIfShouldProcess = $pscmdlet.ShouldProcess("$Name", 'Installing / upgrading package from Chocolatey') | ||
| if ($whatIfShouldProcess) { | ||
| if ($Version) { | ||
| Write-Verbose -Message "Uninstalling $Name due to version mis-match" | ||
| UninstallPackage -pName $Name -pParams $Params | ||
| Write-Verbose -Message "Re-Installing $Name with correct version $versionToInstall" | ||
| InstallPackage -pName $Name -pParams $Params -pVersion $versionToInstall -pSource $Source -cParams $chocoParams | ||
| # Version check on the existing package to ensure we don't attempt to upgrade in a downgrade situation | ||
| $installedPackages = @(Get-ChocoInstalledPackage | Where-object { $_.Name -eq $Name }) | ||
| $packageCount = $installedPackages.Count | ||
| Write-Verbose "Found $packageCount matching package(s) for upgrade" | ||
| $canUpgrade = $packageCount -eq 1 | ||
| if ($canUpgrade) { | ||
| [Version] $installedVersion = Get-VersionCore -Version $installedPackages[0].Version | ||
| [Version] $targetVersion = Get-VersionCore -Version $Version | ||
|
|
||
| $canUpgrade = $installedVersion.CompareTo($targetVersion) -le 0 | ||
| } | ||
|
|
||
| if ($canUpgrade) { | ||
| Write-Verbose -Message "Upgrading $Name to version $Version" | ||
| Upgrade-Package -pName $Name -pParams $Params -pVersion $Version | ||
| } | ||
| else { | ||
| Write-Verbose -Message "Uninstalling $Name due to version mis-match" | ||
| UninstallPackage -pName $Name -pParams $Params | ||
| Write-Verbose -Message "Re-Installing $Name with correct version $version" | ||
| InstallPackage -pName $Name -pParams $Params -pVersion $Version -pSource $Source -cParams $chocoParams | ||
| } | ||
| } | ||
| elseif ($MinimumVersion) { | ||
| Write-Verbose -Message "Upgrading $Name because installed version is lower that the specified minimum" | ||
|
|
@@ -443,7 +461,7 @@ function global:Write-Host | |
| Write-Verbose -Message $Object | ||
| } | ||
|
|
||
| Function Upgrade-Package { | ||
| function Upgrade-Package { | ||
| [Diagnostics.CodeAnalysis.SuppressMessage('PSUseApprovedVerbs','')] | ||
| [Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidUsingInvokeExpression','')] | ||
| param( | ||
|
|
@@ -454,7 +472,9 @@ Function Upgrade-Package { | |
| [Parameter(Position=2)] | ||
| [string]$pSource, | ||
| [Parameter(Position=3)] | ||
| [string]$cParams | ||
| [string]$cParams, | ||
| [Parameter(Position=4)] | ||
| [string]$pVersion | ||
|
Comment on lines
+476
to
+477
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you look at line 146 above you've got: The version parameter is added in the calling code by adding it to |
||
| ) | ||
|
|
||
| $env:Path = [Environment]::GetEnvironmentVariable('Path','Machine') | ||
|
|
@@ -464,6 +484,9 @@ Function Upgrade-Package { | |
| if ($pParams) { | ||
| $chocoParams += " --params=`"$pParams`"" | ||
| } | ||
| if ($pVersion) { | ||
| $chocoParams += " --version=`"$pVersion`"" | ||
| } | ||
|
Comment on lines
+487
to
+489
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the code I was talking about above. |
||
| if ($pSource) { | ||
| $chocoParams += " --source=`"$pSource`"" | ||
| } | ||
|
|
@@ -550,4 +573,18 @@ function Get-ChocoVersion { | |
| Return $res | ||
| } | ||
|
|
||
| function Get-VersionCore { | ||
| [CmdletBinding()] | ||
| param ( | ||
| [string]$Version | ||
| ) | ||
|
|
||
| [Version] $versionCore = $null | ||
| if ($Version -match '(?<Major>[1-9]\d*)(\.(?<Minor>[0-9]*))?(\.(?<Patch>[0-9]*))?(\.(?<Segment>[0-9]*))?([-+].*)?') { | ||
| $versionCore = New-Object System.Version($Matches.Major, $Matches.Minor, $Matches.Patch, $Matches.Segment) | ||
| } | ||
|
|
||
| $versionCore | ||
| } | ||
|
Comment on lines
+576
to
+588
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't compare prerelease versions so 3.0.0-beta1 and 3.0.0-beta2 are the same. So in this instance the code calling it would actually uninstall 3.0.0-beta1 and install 3.0.0-beta2 rather than upgrade. |
||
|
|
||
| Export-ModuleMember -Function *-TargetResource | ||
Uh oh!
There was an error while loading. Please reload this page.