Skip to content

[Bug] lib/install.ps1 function rm_shim fails if manifest bin includes <filename> and <filename>.exeΒ #6529

@o-l-a-v

Description

@o-l-a-v

Bug Report

Current Behavior

Some apps have CLI bins for both Windows and WSL that we want shimmed. Like Zed prior to PR ScoopInstaller/Extras#16438.

PS > scoop uninstall zed
Uninstalling 'zed' (0.209.5).
Removing shim 'zed'.
Removing shim 'zed.shim'.
Removing shim 'zed.exe'.
Remove-Item: C:\Users\<redacted>\scoop\apps\scoop\current\lib\install.ps1:213
Line |
 213 |                      Remove-Item -Path "$shimdir\$name.exe"
     |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find path 'C:\Users\<redacted>\scoop\shims\zed.exe' because it does not exist.
Removing shim 'zed.cmd'.
Removing shim 'zed'.
Removing shortcut ~\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Scoop Apps\Zed.lnk
Unlinking ~\scoop\apps\zed\current
'zed' was uninstalled.
PS >

Relevant function as of now:

Scoop/lib/install.ps1

Lines 199 to 220 in b588a06

function rm_shim($name, $shimdir, $app) {
'', '.shim', '.cmd', '.ps1' | ForEach-Object {
$shimPath = "$shimdir\$name$_"
$altShimPath = "$shimPath.$app"
if ($app -and (Test-Path -Path $altShimPath -PathType Leaf)) {
Write-Output "Removing shim '$name$_.$app'."
Remove-Item $altShimPath
} elseif (Test-Path -Path $shimPath -PathType Leaf) {
Write-Output "Removing shim '$name$_'."
Remove-Item $shimPath
$oldShims = Get-Item -Path "$shimPath.*" -Exclude '*.shim', '*.cmd', '*.ps1'
if ($null -eq $oldShims) {
if ($_ -eq '.shim') {
Write-Output "Removing shim '$name.exe'."
Remove-Item -Path "$shimdir\$name.exe"
}
} else {
(@($oldShims) | Sort-Object -Property LastWriteTimeUtc)[-1] | Rename-Item -NewName { $_.Name -replace '\.[^.]*$', '' }
}
}
}
}

Issue ScoopInstaller/Extras#16441 was created for this.

The manifest looked like this: https://github.com/ScoopInstaller/Extras/blob/0b90c52eae5c8bfbdf12089e02bccec97e6ec049/bucket/zed.json

Expected Behavior

  • Handle manifests where bin includes both <filename> and <filename>.exe
  • Don't throw if a shim is already removed.

Additional context/output

Possible Solution

  • if (Test-Path -Path $FilePath) {Remove-Item}
  • Remove-Item -ErrorAction 'Ignore'

System details

Not relevant.

Scoop Configuration

Not relevant

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions