fix(cmd): use exec.LookPath in Which() so detection works without external 'which'#12651
fix(cmd): use exec.LookPath in Which() so detection works without external 'which'#12651Sanjays2402 wants to merge 1 commit into1Panel-dev:dev-v2from
Conversation
…ernal 'which' cmd.Which() previously shelled out to `which <name>` to determine whether a binary was on PATH. On distributions that do not ship a `which` package by default — Arch Linux is the canonical example, but the same applies to several minimal container images — `which` itself is missing, so every call to Which() returned false and 1Panel reported core dependencies (notably Docker) as 'not installed' even when they were running normally. Switch the primary path to Go's exec.LookPath, which uses the process PATH directly and has no external dependency. The original shell-out is preserved as a fallback so any environment where the agent's PATH differs from the user's interactive shell PATH (the original reason the shell-out existed) keeps working unchanged. Both copies are updated (agent/utils/cmd/cmd.go and core/utils/cmd/cmd.go) and a small unit test is added to each package to guard the regression. Fixes 1Panel-dev#12605 Signed-off-by: Sanjay Santhanam <51058514+Sanjays2402@users.noreply.github.com>
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
What this PR does / why we need it?
Fixes #12605.
cmd.Which()previously shelled out towhich <name>to determine whether a binary was on PATH. On distributions that do not ship awhichpackage by default — Arch Linux is the canonical example, but the same applies to several minimal container images —whichitself is missing from PATH, so every call toWhich()returnedfalse. As a result, 1Panel reported core dependencies (notably Docker) as not installed even when they were running normally:…on a host where
docker.servicewas active,docker versionworked, and/var/run/docker.sockwas reachable. The reporter confirmed that simply dropping a stub/usr/local/bin/whichscript restored detection.Summary of your change
Switch the primary path to Go's
exec.LookPath, which uses the process PATH directly and has no external binary dependency. The original shell-out is preserved as a fallback so any environment where the agent's PATH differs from the user's interactive shell PATH (the reason the shell-out existed in the first place) keeps working unchanged.Both copies of the helper are updated:
agent/utils/cmd/cmd.gocore/utils/cmd/cmd.goA small unit test is added to each package guarding the regression:
Which("sh")istrue(sh is on every Unix-like host the CI runs on, regardless of whetherwhichitself is installed).Which("definitely-not-a-real-binary-xyzzy-1panel")isfalse.Verification
go vetandgofmtare both clean on the touched files.Please indicate you've done the following:
Which()is internal.)