Skip to content

Commit

Permalink
fix(shim): properly check wslpath/cygpath command first (#6114)
Browse files Browse the repository at this point in the history
Co-authored-by: Hsiao-nan Cheung <[email protected]>
  • Loading branch information
sitiom and niheaven authored Oct 9, 2024
1 parent 3577f91 commit 7a309a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- **scoop-download|install|update:** Fallback to default downloader when aria2 fails ([#4292](https://github.com/ScoopInstaller/Scoop/issues/4292))
- **decompress**: `Expand-7zipArchive` only delete temp dir / `$extractDir` if it is empty ([#6092](https://github.com/ScoopInstaller/Scoop/issues/6092))
- **commands**: Handling broken aliases ([#6141](https://github.com/ScoopInstaller/Scoop/issues/6141))
- **shim:** Do not suppress `stderr`, properly check `wslpath`/`cygpath` command first ([#6114](https://github.com/ScoopInstaller/Scoop/pull/6114))

### Code Refactoring

Expand Down
13 changes: 10 additions & 3 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1003,11 +1003,18 @@ function shim($path, $global, $name, $arg) {
) -join "`n" | Out-UTF8File $shim -NoNewLine
} else {
warn_on_overwrite "$shim.cmd" $path
$quoted_arg = if ($arg.Count -gt 0) { $arg | ForEach-Object { "`"$_`"" } }
@(
"@rem $resolved_path",
"@bash `"`$(wslpath -u '$resolved_path')`" $arg %* 2>nul",
'@if %errorlevel% neq 0 (',
" @bash `"`$(cygpath -u '$resolved_path')`" $arg %* 2>nul",
'@echo off',
'bash -c "command -v wslpath >/dev/null"',
'if %errorlevel% equ 0 (',
" bash `"`$(wslpath -u '$resolved_path')`" $quoted_arg %*",
') else (',
" set args=$quoted_arg %*",
' setlocal enabledelayedexpansion',
' if not "!args!"=="" set args=!args:"=""!',
" bash -c `"`$(cygpath -u '$resolved_path') !args!`"",
')'
) -join "`r`n" | Out-UTF8File "$shim.cmd"

Expand Down

0 comments on commit 7a309a1

Please sign in to comment.