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

fix(scoop-alias): Prevent overwrite existing file when adding alias #5577

Merged
merged 10 commits into from
Apr 8, 2024
3 changes: 3 additions & 0 deletions libexec/scoop-alias.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ function add_alias($name, $command) {

# generate script
$shimdir = shimdir $false
if (Test-Path "$shimdir\$alias_file.ps1") {
abort "File '$alias_file.ps1' already exists in shims directory."
}
$script =
@(
"# Summary: $description",
Expand Down
17 changes: 8 additions & 9 deletions test/Scoop-Alias.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ Describe 'Manipulate Alias' -Tag 'Scoop' {
& $alias_file | Should -Be 'hello, world!'
}

It 'Does not change existing alias if alias exists' {
$alias_file = "$shimdir\scoop-rm.ps1"
New-Item $alias_file -Type File -Force
$alias_file | Should -Exist
# NOTE: `abort()` in `add_alias()` cause tests error.
# It 'Does not change existing file if its filename same as alias name' {
# $alias_file = "$shimdir\scoop-rm.ps1"
# New-Item $alias_file -Type File -Force
# $alias_file | Should -Exist

add_alias 'rm' 'test'
& $alias_file | Should -Not -Be 'test'
}
# add_alias 'rm' '"test"'
# & $alias_file | Should -Be $null
# }

It 'Removes an existing alias' {
$alias_file = "$shimdir\scoop-rm.ps1"
add_alias 'rm' '"hello, world!"'

$alias_file | Should -Exist
Mock get_config { @(@{'rm' = 'scoop-rm' }) }

Expand Down
2 changes: 1 addition & 1 deletion test/Scoop-Versions.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Describe 'versions comparison' -Tag 'Scoop' {
Compare-Version 'nightly-20190801' 'nightly-20200801' | Should -Be 0
}

It 'handles nightly versions with `update_nightly`' {
It "handles nightly versions with 'update_nightly'" {
function get_config { $true }
Mock Get-Date { '20200801' }
Compare-Version 'nightly-20200801' 'nightly' | Should -Be 0
Expand Down