Skip to content

Commit 9b0fbd8

Browse files
sitiomniheaven
authored andcommitted
fix(shim): properly check wslpath/cygpath command first (ScoopInstaller#6114)
Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>
1 parent bff6e1f commit 9b0fbd8

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- **scoop-download|install|update:** Fallback to default downloader when aria2 fails ([#4292](https://github.com/ScoopInstaller/Scoop/issues/4292))
66
- **decompress**: `Expand-7zipArchive` only delete temp dir / `$extractDir` if it is empty ([#6092](https://github.com/ScoopInstaller/Scoop/issues/6092))
77
- **commands**: Handling broken aliases ([#6141](https://github.com/ScoopInstaller/Scoop/issues/6141))
8+
- **shim:** Do not suppress `stderr`, properly check `wslpath`/`cygpath` command first ([#6114](https://github.com/ScoopInstaller/Scoop/pull/6114))
89

910
### Code Refactoring
1011

lib/core.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,11 +1003,18 @@ function shim($path, $global, $name, $arg) {
10031003
) -join "`n" | Out-UTF8File $shim -NoNewLine
10041004
} else {
10051005
warn_on_overwrite "$shim.cmd" $path
1006+
$quoted_arg = if ($arg.Count -gt 0) { $arg | ForEach-Object { "`"$_`"" } }
10061007
@(
10071008
"@rem $resolved_path",
1008-
"@bash `"`$(wslpath -u '$resolved_path')`" $arg %* 2>nul",
1009-
'@if %errorlevel% neq 0 (',
1010-
" @bash `"`$(cygpath -u '$resolved_path')`" $arg %* 2>nul",
1009+
'@echo off',
1010+
'bash -c "command -v wslpath >/dev/null"',
1011+
'if %errorlevel% equ 0 (',
1012+
" bash `"`$(wslpath -u '$resolved_path')`" $quoted_arg %*",
1013+
') else (',
1014+
" set args=$quoted_arg %*",
1015+
' setlocal enabledelayedexpansion',
1016+
' if not "!args!"=="" set args=!args:"=""!',
1017+
" bash -c `"`$(cygpath -u '$resolved_path') !args!`"",
10111018
')'
10121019
) -join "`r`n" | Out-UTF8File "$shim.cmd"
10131020

0 commit comments

Comments
 (0)