From a572a3f10df6667d1330e52634291404ecb52f07 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Thu, 26 Feb 2015 07:50:28 -0600 Subject: [PATCH 1/8] (GH-120) ChocolateyPackageFolder env var wrong In Powershell Choco, the chocolateyPackageFolder environment variable would point to the directory the package was extracted to, e.g. C:\ProgramData\chocolatey\lib\package.1.2.3 (relevant source lines: https://github.com/chocolatey/chocolatey/blob/2d61a3b0958170ade13d8ad5a09a88af9e46bb65/src/functions/Run-ChocolateyPS1.ps1#L28 and https://github.com/chocolatey/chocolatey/blob/2d61a3b0958170ade13d8ad5a09a88af9e46bb65/src/functions/Chocolatey-NuGet.ps1#L64). In C# Choco, this variable is set to the path of the lib directory. Set the variables to the proper directory for the package. --- .../helpers/functions/Get-ChocolateyUnzip.ps1 | 2 +- .../functions/UnInstall-ChocolateyZipPackage.ps1 | 10 ++++++---- .../infrastructure.app/services/PowershellService.cs | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/chocolatey.resources/helpers/functions/Get-ChocolateyUnzip.ps1 b/src/chocolatey.resources/helpers/functions/Get-ChocolateyUnzip.ps1 index b02291bf47..a6acd609c5 100644 --- a/src/chocolatey.resources/helpers/functions/Get-ChocolateyUnzip.ps1 +++ b/src/chocolatey.resources/helpers/functions/Get-ChocolateyUnzip.ps1 @@ -60,7 +60,7 @@ param( Write-Debug "Running 'Get-ChocolateyUnzip' with fileFullPath:`'$fileFullPath`'', destination: `'$destination`', specificFolder: `'$specificFolder``, packageName: `'$packageName`'"; if ($packageName) { - $packagelibPath = Join-Path $env:ChocolateyPackageFolder $packageName + $packagelibPath = $env:ChocolateyPackageFolder if (!(Test-Path -path $packagelibPath)) { New-Item $packagelibPath -type directory } diff --git a/src/chocolatey.resources/helpers/functions/UnInstall-ChocolateyZipPackage.ps1 b/src/chocolatey.resources/helpers/functions/UnInstall-ChocolateyZipPackage.ps1 index cf8cb116e7..7dc5f61f78 100644 --- a/src/chocolatey.resources/helpers/functions/UnInstall-ChocolateyZipPackage.ps1 +++ b/src/chocolatey.resources/helpers/functions/UnInstall-ChocolateyZipPackage.ps1 @@ -46,9 +46,11 @@ param( $packagelibPath=$env:chocolateyPackageFolder $zipContentFile=(join-path $packagelibPath $zipFileName) + ".txt" - $zipContentFile - $zipContents=get-content $zipContentFile - foreach ($fileInZip in $zipContents) { - remove-item "$fileInZip" -ErrorAction SilentlyContinue + if ((Test-Path -path $zipContentFile)) { + $zipContentFile + $zipContents=get-content $zipContentFile + foreach ($fileInZip in $zipContents) { + remove-item "$fileInZip" -ErrorAction SilentlyContinue + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/services/PowershellService.cs b/src/chocolatey/infrastructure.app/services/PowershellService.cs index 80f9736f80..3ba74fb63a 100644 --- a/src/chocolatey/infrastructure.app/services/PowershellService.cs +++ b/src/chocolatey/infrastructure.app/services/PowershellService.cs @@ -158,8 +158,8 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack Environment.SetEnvironmentVariable("packageName", package.Id); Environment.SetEnvironmentVariable("chocolateyPackageVersion", package.Version.to_string()); Environment.SetEnvironmentVariable("packageVersion", package.Version.to_string()); - Environment.SetEnvironmentVariable("chocolateyPackageFolder", ApplicationParameters.PackagesLocation); - Environment.SetEnvironmentVariable("packageFolder", ApplicationParameters.PackagesLocation); + Environment.SetEnvironmentVariable("chocolateyPackageFolder", packageDirectory); + Environment.SetEnvironmentVariable("packageFolder", packageDirectory); Environment.SetEnvironmentVariable("installerArguments", configuration.InstallArguments); Environment.SetEnvironmentVariable("chocolateyPackageParameters", configuration.PackageParameters); if (configuration.ForceX86) From eef497d9ed750e8456c1d929c8405aadce937884 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Fri, 27 Feb 2015 07:59:31 -0600 Subject: [PATCH 2/8] (GH-122) Remove usage of Write-ChocolateyFailure This moves to throwing or rethrowing exceptions instead of using Write-ChocolateyFailure. Write-ChocolateyFailure is deprecated and due to be removed, so remove it from Chocolatey methods. --- .../functions/Install-ChocolateyDesktopLink.ps1 | 6 +++--- .../functions/Install-ChocolateyShortcut.ps1 | 17 ++++++----------- .../functions/Install-ChocolateyVsixPackage.ps1 | 11 ++++------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/chocolatey.resources/helpers/functions/Install-ChocolateyDesktopLink.ps1 b/src/chocolatey.resources/helpers/functions/Install-ChocolateyDesktopLink.ps1 index 6e21516e6c..6c7fdb8028 100644 --- a/src/chocolatey.resources/helpers/functions/Install-ChocolateyDesktopLink.ps1 +++ b/src/chocolatey.resources/helpers/functions/Install-ChocolateyDesktopLink.ps1 @@ -32,12 +32,12 @@ param( Write-Debug "Running 'Install-ChocolateyDesktopLink' with targetFilePath:`'$targetFilePath`'"; if(!$targetFilePath) { - Write-ChocolateyFailure "Install-ChocolateyDesktopLink" "Missing TargetFilePath input parameter." + throw "Install-ChocolateyDesktopLink" "Missing TargetFilePath input parameter." return } if(!(Test-Path($targetFilePath))) { - Write-ChocolateyFailure "Install-ChocolateyDesktopLink" "TargetPath does not exist, so can't create shortcut." + throw "Install-ChocolateyDesktopLink" "TargetPath does not exist, so can't create shortcut." return } @@ -58,6 +58,6 @@ param( } catch { - Write-ChocolateyFailure "Install-ChocolateyDesktopLink" "There were errors attempting to create shortcut. The error message was '$_'." + throw $_.Exception } } \ No newline at end of file diff --git a/src/chocolatey.resources/helpers/functions/Install-ChocolateyShortcut.ps1 b/src/chocolatey.resources/helpers/functions/Install-ChocolateyShortcut.ps1 index 1d94d6a63f..b84773cc10 100644 --- a/src/chocolatey.resources/helpers/functions/Install-ChocolateyShortcut.ps1 +++ b/src/chocolatey.resources/helpers/functions/Install-ChocolateyShortcut.ps1 @@ -66,31 +66,26 @@ directoy, an icon to be used for the shortcut, along with a description and argu Write-Debug "Running 'Install-ChocolateyShortcut' with parameters ShortcutFilePath: `'$shortcutFilePath`', TargetPath: `'$targetPath`', WorkingDirectory: `'$workingDirectory`', Arguments: `'$arguments`', IconLocation: `'$iconLocation`', Description: `'$description`'"; if(!$shortcutFilePath) { - Write-ChocolateyFailure "Install-ChocolateyShortcut" "Missing ShortCutFilePath input parameter." - return + throw "Install-ChocolateyShortcut" "Missing ShortCutFilePath input parameter." } if(!$targetPath) { - Write-ChocolateyFailure "Install-ChocolateyShortcut" "Missing TargetPath input parameter." - return + throw "Install-ChocolateyShortcut" "Missing TargetPath input parameter." } if(!(Test-Path($targetPath))) { - Write-ChocolateyFailure "Install-ChocolateyShortcut" "TargetPath does not exist, so can't create shortcut." - return + throw "Install-ChocolateyShortcut" "TargetPath does not exist, so can't create shortcut." } if($iconLocation) { if(!(Test-Path($iconLocation))) { - Write-ChocolateyFailure "Install-ChocolateyShortcut" "IconLocation does not exist, so can't create shortcut." - return + throw "Install-ChocolateyShortcut" "IconLocation does not exist, so can't create shortcut." } } if($workingDirectory) { if(!(Test-Path($workingDirectory))) { - Write-ChocolateyFailure "Install-ChocolateyShortcut" "WorkingDirectory does not exist, so can't create shortcut." - return + throw "Install-ChocolateyShortcut" "WorkingDirectory does not exist, so can't create shortcut." } } @@ -112,6 +107,6 @@ directoy, an icon to be used for the shortcut, along with a description and argu } catch { - Write-ChocolateyFailure "Install-ChocolateyShortcut" "There were errors attempting to create shortcut. The error message was '$_'." + throw $_.Exception } } \ No newline at end of file diff --git a/src/chocolatey.resources/helpers/functions/Install-ChocolateyVsixPackage.ps1 b/src/chocolatey.resources/helpers/functions/Install-ChocolateyVsixPackage.ps1 index 18484a4c4f..049496ee93 100644 --- a/src/chocolatey.resources/helpers/functions/Install-ChocolateyVsixPackage.ps1 +++ b/src/chocolatey.resources/helpers/functions/Install-ChocolateyVsixPackage.ps1 @@ -96,8 +96,7 @@ param( if($version){ $vnum=$version.PSPath.Substring($version.PSPath.LastIndexOf('\')+1) if($vnum -as [int] -lt 10) { - Write-ChocolateyFailure $packageName "This installed VS version, $vnum, does not support installing VSIX packages. Version 10 is the minimum acceptable version." - return + throw "This installed VS version, $vnum, does not support installing VSIX packages. Version 10 is the minimum acceptable version." } $dir=(get-itemProperty $version.PSPath "InstallDir").InstallDir $installer = Join-Path $dir "VsixInstaller.exe" @@ -108,18 +107,16 @@ param( Get-ChocolateyWebFile $packageName $download $vsixUrl -checksum $checksum -checksumType $checksumType } catch { - Write-ChocolateyFailure $packageName "There were errors attempting to retrieve the vsix from $vsixUrl. The error message was '$_'." - return + throw "There were errors attempting to retrieve the vsix from $vsixUrl. The error message was '$_'." } Write-Debug "Installing VSIX using $installer" $exitCode = Install-Vsix "$installer" "$download" if($exitCode -gt 0 -and $exitCode -ne 1001) { #1001: Already installed - Write-ChocolateyFailure $packageName "There was an error installing '$packageName'. The exit code returned was $exitCode." - return + throw "There was an error installing '$packageName'. The exit code returned was $exitCode." } } else { - Write-ChocolateyFailure $packageName "Visual Studio is not installed or the specified version is not present." + throw "Visual Studio is not installed or the specified version is not present." } } From 60f0b6874941179bcc80fad58070e1815645fd53 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Fri, 27 Feb 2015 08:00:27 -0600 Subject: [PATCH 3/8] (GH-122) Write-ChocolateyFailure throw Even if deprecated, Write-ChocolateyFailure should still throw the error message so that packages can error. --- .../helpers/functions/Write-ChocolateyFailure.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/chocolatey.resources/helpers/functions/Write-ChocolateyFailure.ps1 b/src/chocolatey.resources/helpers/functions/Write-ChocolateyFailure.ps1 index 0f476d2f8c..5d4dbf19fc 100644 --- a/src/chocolatey.resources/helpers/functions/Write-ChocolateyFailure.ps1 +++ b/src/chocolatey.resources/helpers/functions/Write-ChocolateyFailure.ps1 @@ -20,4 +20,6 @@ param( Write-Warning "Write-ChocolateyFailure is deprecated. If you are the package maintainer, please use 'throw `$_.Exception' instead." $error | %{ $_.Exception | fl * | Out-String } + + throw "$failureMessage" } From cd9c0486de4bf0c77334da39e707b114303bc688 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Fri, 27 Feb 2015 08:01:53 -0600 Subject: [PATCH 4/8] (maint)(posh) Ensure Module loading preference Ensure that `$PSModuleAutoLoadingPreference` is set to `All`. This was done in the POSH version of Chocolatey and should also be done in choco. --- src/chocolatey.resources/helpers/chocolateyInstaller.psm1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 b/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 index dce848afc4..39c0a8acd2 100644 --- a/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 +++ b/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 @@ -19,6 +19,9 @@ if ($env:ChocolateyEnvironmentDebug -eq 'true') { $DebugPreference = "Continue"; $VerbosePreference = "SilentlyContinue" if ($env:ChocolateyEnvironmentVerbose -eq 'true') { $VerbosePreference = "Continue"; $verbosity = $true } +# ensure module loading preference is on +$PSModuleAutoLoadingPreference = "All"; + Write-Debug "Posh version is $($psversiontable.PsVersion.ToString())" # grab functions from files From 1ca64c429a1cfcbe714e02a36580137b1e7dc8cc Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Fri, 27 Feb 2015 08:03:18 -0600 Subject: [PATCH 5/8] (maint)(log) Get-BinRoot friendly deprecation Log a message (not a warning yet) that Get-BinRoot will be deprecated by v1. --- src/chocolatey.resources/helpers/functions/Get-BinRoot.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/chocolatey.resources/helpers/functions/Get-BinRoot.ps1 b/src/chocolatey.resources/helpers/functions/Get-BinRoot.ps1 index e80d499a56..a512f6a4a5 100644 --- a/src/chocolatey.resources/helpers/functions/Get-BinRoot.ps1 +++ b/src/chocolatey.resources/helpers/functions/Get-BinRoot.ps1 @@ -15,6 +15,7 @@ function Get-BinRoot { Write-Debug "Running 'Get-BinRoot'"; + Write-Output "Get-BinRoot is going to be deprecated by v1. Many packages no longer require it since the folders no longer have versions on them." # Since CamelCase was decided upon when $env:ChocolateyInstall was first invented, whe should stick to this convention and use $env:ChocolateyBinRoot. # I propose: From ea5d5f936108f07529be85d713836bdfd96a8e52 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Fri, 27 Feb 2015 09:34:43 -0600 Subject: [PATCH 6/8] (GH-122)(GH-125) Throw fixes / Shortcut enhancements GH-122 - Fix mistakes on throw (doesn't accept two parameters). GH-125 - `Install-ChocolateyDesktopLink` will warn instead of throw if targetPath doesn't exist - `Install-ChocolateyDesktopLink` will create the desktop directory if it doesn't exist - `Install-ChocolateyShortcut` wil create the shortcutDirectory if it doesn't exist - `Install-ChocolateyShortcut` will warn instead of throw if targetPath doesn't exist - `Install-ChocolateyShortcut` will warn instead of throw if iconlocation doesn't exist - `Install-ChocolateyShortcut` will create the workingDirectory instead of throwing an error if it doesn't exist - `Install-ChocolateyShortcut` will not try to set description if it is null --- .../Install-ChocolateyDesktopLink.ps1 | 9 +++--- .../functions/Install-ChocolateyShortcut.ps1 | 31 ++++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/chocolatey.resources/helpers/functions/Install-ChocolateyDesktopLink.ps1 b/src/chocolatey.resources/helpers/functions/Install-ChocolateyDesktopLink.ps1 index 6c7fdb8028..12f81ffc1c 100644 --- a/src/chocolatey.resources/helpers/functions/Install-ChocolateyDesktopLink.ps1 +++ b/src/chocolatey.resources/helpers/functions/Install-ChocolateyDesktopLink.ps1 @@ -32,19 +32,20 @@ param( Write-Debug "Running 'Install-ChocolateyDesktopLink' with targetFilePath:`'$targetFilePath`'"; if(!$targetFilePath) { - throw "Install-ChocolateyDesktopLink" "Missing TargetFilePath input parameter." - return + throw "Install-ChocolateyDesktopLink - `$targetFilePath can not be null." } if(!(Test-Path($targetFilePath))) { - throw "Install-ChocolateyDesktopLink" "TargetPath does not exist, so can't create shortcut." - return + Write-Warning "'$targetFilePath' does not exist. If it is not created the shortcut will not be valid." } Write-Debug "Creating Shortcut..." try { $desktop = $([System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::DesktopDirectory)) + if(!(Test-Path($desktop))) { + [System.IO.Directory]::CreateDirectory($desktop) | Out-Null + } $link = Join-Path $desktop "$([System.IO.Path]::GetFileName($targetFilePath)).lnk" $workingDirectory = $([System.IO.Path]::GetDirectoryName($targetFilePath)) diff --git a/src/chocolatey.resources/helpers/functions/Install-ChocolateyShortcut.ps1 b/src/chocolatey.resources/helpers/functions/Install-ChocolateyShortcut.ps1 index b84773cc10..038a688a62 100644 --- a/src/chocolatey.resources/helpers/functions/Install-ChocolateyShortcut.ps1 +++ b/src/chocolatey.resources/helpers/functions/Install-ChocolateyShortcut.ps1 @@ -66,27 +66,32 @@ directoy, an icon to be used for the shortcut, along with a description and argu Write-Debug "Running 'Install-ChocolateyShortcut' with parameters ShortcutFilePath: `'$shortcutFilePath`', TargetPath: `'$targetPath`', WorkingDirectory: `'$workingDirectory`', Arguments: `'$arguments`', IconLocation: `'$iconLocation`', Description: `'$description`'"; if(!$shortcutFilePath) { - throw "Install-ChocolateyShortcut" "Missing ShortCutFilePath input parameter." + throw "Install-ChocolateyShortcut - `$shortcutFilePath can not be null." } + $shortcutDirectory = $([System.IO.Path]::GetDirectoryName($shortcutFilePath)) + if (!(Test-Path($shortcutDirectory))) { + [System.IO.Directory]::CreateDirectory($shortcutDirectory) | Out-Null + } + if(!$targetPath) { - throw "Install-ChocolateyShortcut" "Missing TargetPath input parameter." + throw "Install-ChocolateyShortcut - `$targetFilePath can not be null." } - + if(!(Test-Path($targetPath))) { - throw "Install-ChocolateyShortcut" "TargetPath does not exist, so can't create shortcut." + Write-Warning "'$targetFilePath' does not exist. If it is not created the shortcut will not be valid." } if($iconLocation) { if(!(Test-Path($iconLocation))) { - throw "Install-ChocolateyShortcut" "IconLocation does not exist, so can't create shortcut." + Write-Warning "'$iconLocation' does not exist. A default icon will be used." } } - if($workingDirectory) { - if(!(Test-Path($workingDirectory))) { - throw "Install-ChocolateyShortcut" "WorkingDirectory does not exist, so can't create shortcut." - } + if ($workingDirectory) { + if (!(Test-Path($workingDirectory))) { + [System.IO.Directory]::CreateDirectory($workingDirectory) | Out-Null + } } Write-Debug "Creating Shortcut..." @@ -98,13 +103,15 @@ directoy, an icon to be used for the shortcut, along with a description and argu $lnk.WorkingDirectory = $workingDirectory $lnk.Arguments = $arguments if($iconLocation) { - $lnk.IconLocation = $iconLocation + $lnk.IconLocation = $iconLocation } - $lnk.Description = $description + if ($description) { + $lnk.Description = $description + } + $lnk.Save() Write-Debug "Shortcut created." - } catch { throw $_.Exception From 54ad8524edb5f0a80a6bd94754e978f7a7ab0cbb Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Fri, 27 Feb 2015 09:46:06 -0600 Subject: [PATCH 7/8] (GH-124) Load PowerShell extensions if present --- .../helpers/chocolateyInstaller.psm1 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 b/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 index 39c0a8acd2..4281f15384 100644 --- a/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 +++ b/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 @@ -30,4 +30,12 @@ Get-Item $helpersPath\functions\*.ps1 | % { . $_.FullName; Export-ModuleMember -Function $_.BaseName - } \ No newline at end of file + } + +# load extensions if they exist +$extensionsPath = Join-Path "$helpersPath" '..\extensions' +if(Test-Path($extensionsPath)) { + Write-Debug 'Loading community extensions' + #Resolve-Path $extensionsPath\**\*\*.psm1 | % { Write-Debug "Importing `'$_`'"; Import-Module $_.ProviderPath } + Get-ChildItem $extensionsPath -recurse -filter "*.psm1" | Select -ExpandProperty FullName | % { Write-Debug "Importing `'$_`'"; Import-Module $_; } +} \ No newline at end of file From babae807e97c02c949307de8a1f1bd1c7a888eb6 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Fri, 27 Feb 2015 10:10:39 -0600 Subject: [PATCH 8/8] (GH-124) Install extensions If a package name ends with .extension, install it to the extensions directory. Handle upgrade and uninstall scenarios for extensions as well. --- src/chocolatey.tests.integration/Scenario.cs | 2 ++ .../scenarios/InstallScenarios.cs | 8 +++++ .../ApplicationParameters.cs | 1 + .../services/ChocolateyPackageService.cs | 36 ++++++++++++++++++- 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index 22b7d6691c..d97fde1337 100644 --- a/src/chocolatey.tests.integration/Scenario.cs +++ b/src/chocolatey.tests.integration/Scenario.cs @@ -53,6 +53,7 @@ public static void reset(ChocolateyConfiguration config) _fileSystem.delete_directory_if_exists(badPackagesPath, recursive: true); _fileSystem.delete_directory_if_exists(backupPackagesPath, recursive: true); _fileSystem.delete_directory_if_exists(_fileSystem.combine_paths(get_top_level(), ".chocolatey"), recursive: true); + _fileSystem.delete_directory_if_exists(_fileSystem.combine_paths(get_top_level(), "extensions"), recursive: true); _fileSystem.create_directory(config.CacheLocation); _fileSystem.create_directory(config.Sources); @@ -61,6 +62,7 @@ public static void reset(ChocolateyConfiguration config) _fileSystem.create_directory(badPackagesPath); _fileSystem.create_directory(backupPackagesPath); _fileSystem.create_directory(_fileSystem.combine_paths(get_top_level(), ".chocolatey")); + _fileSystem.create_directory(_fileSystem.combine_paths(get_top_level(), "extensions")); } public static void add_packages_to_source_location(ChocolateyConfiguration config, string pattern) diff --git a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs index 0154a79536..e7b09d3c26 100644 --- a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs @@ -210,6 +210,14 @@ public void should_not_create_a_shim_for_mismatched_case_ignored_executable_in_t var shimfile = Path.Combine(Scenario.get_top_level(), "bin", "casemismatch.exe"); File.Exists(shimfile).ShouldBeFalse(); + } + + [Fact] + public void should_not_create_an_extensions_folder_for_the_pacakge() + { + var extensionsDirectory = Path.Combine(Scenario.get_top_level(), "extensions", Configuration.PackageNames); + + Directory.Exists(extensionsDirectory).ShouldBeFalse(); } [Fact] diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index 082aa2de9f..a55cf8bbf7 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -52,6 +52,7 @@ public static class ApplicationParameters public static readonly string PackageBackupLocation = _fileSystem.combine_paths(InstallLocation, "lib-bkp"); public static readonly string ShimsLocation = _fileSystem.combine_paths(InstallLocation, "bin"); public static readonly string ChocolateyPackageInfoStoreLocation = _fileSystem.combine_paths(InstallLocation, ".chocolatey"); + public static readonly string ExtensionsLocation = _fileSystem.combine_paths(InstallLocation, "extensions"); public static readonly string ChocolateyCommunityFeedPushSource = "https://chocolatey.org/"; public static readonly string UserAgent = "Chocolatey Command Line"; public static readonly string RegistryValueInstallLocation = "InstallLocation"; diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 8ee04262a9..a9abc0c987 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -196,6 +196,11 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu if (config.Information.PlatformType != PlatformType.Windows) this.Log().Info(ChocolateyLoggers.Important, () => " Skipping Powershell and shimgen portions of the install due to non-Windows."); } + if (packageResult.Success) + { + handle_extension_packages(config, packageResult); + } + _packageInfoService.save_package_information(pkgInfo); ensure_bad_package_path_is_clean(config, packageResult); @@ -477,6 +482,8 @@ private void uninstall_cleanup(ChocolateyConfiguration config, PackageResult pac _packageInfoService.remove_package_information(packageResult.Package); ensure_bad_package_path_is_clean(config, packageResult); remove_rollback_if_exists(packageResult); + handle_extension_packages(config, packageResult); + if (config.Force) { var packageDirectory = _fileSystem.combine_paths(packageResult.InstallLocation); @@ -496,11 +503,38 @@ private void uninstall_cleanup(ChocolateyConfiguration config, PackageResult pac FaultTolerance.try_catch_with_logging_exception( () => _fileSystem.delete_directory_if_exists(packageDirectory, recursive: true), - "Attempted to remove '{0}' but had an error:".format_with(packageDirectory), + "Attempted to remove '{0}' but had an error".format_with(packageDirectory), logWarningInsteadOfError: true); } } + private void handle_extension_packages(ChocolateyConfiguration config, PackageResult packageResult) + { + if (packageResult == null) return; + _fileSystem.create_directory_if_not_exists(ApplicationParameters.ExtensionsLocation); + + if (!packageResult.Name.to_lower().EndsWith(".extension")) return; + + var pkgExtensions = _fileSystem.combine_paths(ApplicationParameters.ExtensionsLocation, packageResult.Name); + FaultTolerance.try_catch_with_logging_exception( + () => _fileSystem.delete_directory_if_exists(pkgExtensions, recursive: true), + "Attempted to remove '{0}' but had an error".format_with(pkgExtensions)); + + if (!config.CommandName.is_equal_to(CommandNameType.uninstall.to_string())) + { + if (packageResult.InstallLocation == null) return; + + _fileSystem.create_directory_if_not_exists(pkgExtensions); + FaultTolerance.try_catch_with_logging_exception( + () => _fileSystem.copy_directory(packageResult.InstallLocation, pkgExtensions, overwriteExisting: true), + "Attempted to copy{0} '{1}'{0} to '{2}'{0} but had an error".format_with(Environment.NewLine, packageResult.InstallLocation, pkgExtensions)); + + string logMessage = "Installed/updated extension for {0}. You will be able to use it on next run.".format_with(packageResult.Name); + this.Log().Warn(logMessage); + packageResult.Messages.Add(new ResultMessage(ResultType.Note, logMessage)); + } + } + private void ensure_bad_package_path_is_clean(ChocolateyConfiguration config, PackageResult packageResult) { FaultTolerance.try_catch_with_logging_exception(