Skip to content
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

UnInstall-ChocolateyZipPackage is failing #871

Closed
tonyrsmith opened this issue Jul 22, 2016 · 3 comments
Closed

UnInstall-ChocolateyZipPackage is failing #871

tonyrsmith opened this issue Jul 22, 2016 · 3 comments
Assignees
Milestone

Comments

@tonyrsmith
Copy link

What You Are Seeing?

chocolatey version: 0.9.10.3

I am creating my own chocolatey packages to install zip files. Since upgrading to chocolatey 0.9.10.3 the installation of my package works, but uninstalling my package fails. This used to work on 0.9.9.8.

What is Expected?

chocolatey to uninstall my package without any errors

How Did You Get This To Happen? (Steps to Reproduce)

Simplified example using MyTest as a package...

tools\chocolateyinstall.ps1

# WARNING: This file needs to be saved as UTF-8 with BOM
# Do not remove this test for UTF-8: if “Ω” doesn’t appear as greek uppercase omega letter enclosed in quotation marks, you should use an editor that supports UTF-8, not this one.

$ErrorActionPreference = 'Stop'; # stop on all errors
$packageName = 'MyTest'

$destFolder = "C:\Temp\$packageName"

if ((Test-Path $destFolder) -eq $false) {
    New-Item $destFolder -itemtype directory
}

# Unzip package
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$source = "$toolsDir\$packageName.zip"
Get-ChocolateyUnzip "$source" "$destFolder" "" "$packageName"

tools\chocolateyuninstall.ps1

# WARNING: This file needs to be saved as UTF-8 with BOM
# Do not remove this test for UTF-8: if “Ω” doesn’t appear as greek uppercase omega letter enclosed in quotation marks, you should use an editor that supports UTF-8, not this one.

$ErrorActionPreference = 'Stop'; # stop on all errors
$packageName = 'MyTest'

# UnInstall files
UnInstall-ChocolateyZipPackage "$packageName" "$packageName.zip"

tools\MyTest.zip just contains one file called MyTest.txt which is just a small text file

MyTest.nuspec

<?xml version="1.0" encoding="utf-8"?>
<!-- WARNING: This file needs to be saved as UTF-8 without BOM -->
<!-- Do not remove this test for UTF-8: if “Ω” doesn’t appear as greek uppercase omega letter enclosed in quotation marks, you should use an editor that supports UTF-8, not this one. -->
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>MyTest</id>
    <title>MyTest</title>
    <version>$version$</version>
    <authors>MyTest</authors>
    <owners>MyTest</owners>
    <summary>$version$ MyTest</summary>
    <description>$version$ MyTest</description>
    <projectUrl>ssh://mytest.net</projectUrl>
    <tags>MyTest</tags>
    <copyright>2016</copyright>
    <licenseUrl>http://mytest.net</licenseUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <releaseNotes></releaseNotes>
  </metadata>
  <files>
    <file src="tools\**" target="tools" />
  </files>
</package>

Chocolatey package is created using:

choco pack --version=1.0.0

Chocolatey package installed using:

choco install MyTest --source . -y

Chocolatey package uninstalled using:

choco uninstall MyTest -y

Output Log

Uninstalling the following packages:
MyTest

MyTest v1.0.0
C:\ProgramData\chocolatey\lib\MyTest\MyTest.zip.txt
ERROR: Cannot bind argument to parameter 'Path' because it is an empty string.
mytest uninstall not successful.
Error while running 'C:\ProgramData\chocolatey\lib\MyTest\tools\chocolateyuninstall.ps1'.
 See log for details.
MyTest not uninstalled. An error occurred during uninstall:
 mytest uninstall not successful.

Chocolatey uninstalled 0/1 packages. 1 packages failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Failures
 - mytest (exited -1) - Error while running 'C:\ProgramData\chocolatey\lib\MyTest\tools\chocolateyuninstall.ps1'.
 See log for details.

C:\ProgramData\chocolatey\lib\MyTest\MyTest.zip.txt contains a trailing empty line:

C:\Temp\MyTest\MyTest.txt<CR><LF>
<CR><LF>

When I remove the trailing empty line (see below), and re-run choco uninstall, the uninstall works.

C:\ProgramData\chocolatey\lib\MyTest\MyTest.zip.txt (modified):

C:\Temp\MyTest\MyTest.txt<CR><LF>

So I think there's either a problem with UnInstall-ChocolateyZipPackage not handling empty lines, or Get-ChocolateyUnzip erroneously logging an extra empty line. Or am I doing something wrong?

@ferventcoder
Copy link
Member

Looks like a bug

@ferventcoder
Copy link
Member

This is fixed for 0.9.10.4

ferventcoder added a commit that referenced this issue Jul 24, 2016
When calling Uninstall-ChocolateyZipPackage, the text file may have an
empty string at the end of the file. This line should be skipped and
not tried to remove. Even though the ErrorAction is to
SilentlyContinue, it will fail if the arguments are not correct.
ferventcoder added a commit that referenced this issue Jul 24, 2016
* stable:
  (maint) Skip log PowerShell resource assembly failures
  (GH-871) Fix - Uninstall zip: Path is empty string
  (maint) remove unused import
  (GH-854) Reset Exit Code between package runs
  (GH-852) Bump up the default log sizes
  (GH-867) NuGet.Core Errors Exit Code 1
  (GH-853) Handle null values better
  (GH-836) Fix - Use 32 bit 7zip
  (GH-847) Tab Completion Enhancements
  (GH-857) Fix - Sometimes paths contain null chars
@tonyrsmith
Copy link
Author

@ferventcoder Great job! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants