-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from gep13/Issue-195
Added Remove-BinFile Helper
- Loading branch information
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/chocolatey.resources/helpers/functions/Remove-BinFile.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2011 - Present RealDimensions Software, LLC & original authors/contributors from https://github.com/chocolatey/chocolatey | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
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" | ||
$packageShimFileName = Join-Path $nugetExePath "$name.exe" | ||
$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-Debug "Tried to remove batch file $packageBatchFileName but it was already removed." | ||
} | ||
|
||
if (Test-Path $packageBashFileName) { | ||
Write-Host "Removing bash file $packageBashFileName which pointed to `'$path`'." -ForegroundColor $Note | ||
Remove-Item $packageBashFileName | ||
} | ||
else { | ||
Write-Debug "Tried to remove bash file $packageBashFileName but it was already removed." | ||
} | ||
|
||
Write-Debug "Attempting to remove the shim: $packageShimFileName" | ||
if (Test-Path $packageShimFileName) { | ||
Write-Host "Removing shim $packageShimFileName which pointed to `'$path`'." -ForegroundColor $Note | ||
Remove-Item $packageShimFileName | ||
} | ||
else { | ||
Write-Debug "Tried to remove shim $packageShimFileName but it was already removed." | ||
} | ||
} |