Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Fix bash arg quoting, remove bash/batch shortcuts on uninstall #258

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/functions/Chocolatey-Uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ param(
else {
Write-Debug "Looking for $($package).$($versions.found)"
$packageFolder = Join-Path $nugetLibPath "$($package).$($versions.found)"
Write-host "Uninstalling from folder $packageFolder"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line isn't strictly necessary, but I think I like it when a status message is shown when destructive changes are made.

Get-ChocolateyBins $packageFolder -uninstall
Run-ChocolateyPS1 $packageFolder $package "uninstall"
Remove-Item -Recurse -Force $packageFolder
}
Expand Down
5 changes: 3 additions & 2 deletions src/functions/Generate-BinFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ param(
$path = $path.ToLower().Replace($nugetPath.ToLower(), "%DIR%..\").Replace("\\","\")
$pathBash = $path.Replace("%DIR%..\","`$DIR/../").Replace("\","/")
Write-Host "Adding $packageBatchFileName and pointing to `'$path`'." -ForegroundColor $Note
Write-Host "Adding $packageBashFileName and pointing to `'$path`'." -ForegroundColor $Note
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this line, because the existing code seemed inconsistent (it displays a message about the batch file, but not about the bash file)

if ($useStart) {
Write-Host "Setting up $name as a non-command line application." -ForegroundColor $Note
"@echo off
Expand All @@ -19,7 +20,7 @@ start """" ""$path"" %*" | Out-File $packageBatchFileName -encoding ASCII

"#!/bin/sh
DIR=`${0%/*}
""$pathBash"" `$* &" | Out-File $packageBashFileName -encoding ASCII
""$pathBash"" ""`$*"" &" | Out-File $packageBashFileName -encoding ASCII

} else {
"@echo off
Expand All @@ -28,6 +29,6 @@ SET DIR=%~dp0%

"#!/bin/sh
DIR=`${0%/*}
""$pathBash"" `$*" | Out-File $packageBashFileName -encoding ASCII
""$pathBash"" ""`$*""" | Out-File $packageBashFileName -encoding ASCII
}
}
15 changes: 12 additions & 3 deletions src/functions/Get-ChocolateyBins.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function Get-ChocolateyBins {
param(
[string] $packageFolder
[string] $packageFolder,
[switch] $uninstall
)
Write-Debug "Running 'Get-ChocolateyBins' for $packageFolder";

Expand All @@ -17,9 +18,17 @@ Adding batch files for any executables found to a location on PATH. In other wor
foreach ($file in $files) {
if (!(test-path($file.FullName + '.ignore'))) {
if (test-path($file.FullName + '.gui')) {
Generate-BinFile $file.Name.Replace(".exe","").Replace(".EXE","") $file.FullName -useStart
if ($uninstall) {
Remove-BinFile $file.Name.Replace(".exe","").Replace(".EXE","") $file.FullName
} else {
Generate-BinFile $file.Name.Replace(".exe","").Replace(".EXE","") $file.FullName -useStart
}
} else {
Generate-BinFile $file.Name.Replace(".exe","").Replace(".EXE","") $file.FullName
if ($uninstall) {
Remove-BinFile $file.Name.Replace(".exe","").Replace(".EXE","") $file.FullName
} else {
Generate-BinFile $file.Name.Replace(".exe","").Replace(".EXE","") $file.FullName
}
}
$batchCreated = $true
}
Expand Down
27 changes: 27 additions & 0 deletions src/functions/Remove-BinFile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function Remove-BinFile {
param(
[string] $name,
[string] $path
)
Write-Debug "Running 'Remove-BinFile' for $name with path:`'$path`'";

$packageBatchFileName = Join-Path $nugetExePath "$name.bat"
$packageBashFileName = Join-Path $nugetExePath "$name"
$path = $path.ToLower().Replace($nugetPath.ToLower(), "%DIR%..\").Replace("\\","\")
$pathBash = $path.Replace("%DIR%..\","`$DIR/../").Replace("\","/")
Write-Debug "Attempting to remove the batch and bash shortcuts: $packageBatchFileName and $packageBashFileName"
if (Test-Path $packageBatchFileName) {
Write-Host "Removing batch file $packageBatchFileName which pointed to `'$path`'." -ForegroundColor $Note
Remove-Item $packageBatchFileName
}
else {
Write-Host "Tried to remove batch file $packageBatchFileName but it was already removed." -ForegroundColor $Note
}
if (Test-Path $packageBashFileName) {
Write-Host "Removing bash file $packageBashFileName which pointed to `'$path`'." -ForegroundColor $Note
Remove-Item $packageBashFileName
}
else {
Write-Host "Tried to remove bash file $packageBashFileName but it was already removed." -ForegroundColor $Note
}
}