feat: implement pkg-helper fallback execution

Add CLI argument support to pkg-helper and fallback execution via $PATH in dep_installer when the Unix socket is unavailable.

💘 Generated with Crush

Assisted-by: Crush:gemini-3.1-pro-preview-customtools
This commit is contained in:
Keith Patrick committed 2026-06-11 13:34:49 +01:00
1 parent d85bf17171
commit 37e2d37cf4
2 files changed
+41

No files matched your search

+14
View File
@@ -60,6 +60,20 @@ type response struct {
}
func main() {
if len(os.Args) > 1 {
req := request{Action: os.Args[1]}
if len(os.Args) > 2 {
req.Package = os.Args[2]
}
resp := handleRequest(req)
out, _ := json.Marshal(resp)
fmt.Println(string(out))
if !resp.OK {
os.Exit(1)
}
return
}
slog.Info("pkg-helper: starting", "socket", socketPath, "protocol", "v2")
// Remove stale socket.
+27
View File
@@ -305,6 +305,33 @@ func UninstallPackage(ctx context.Context, dep string) (bool, string) {
func apkHelperCall(ctx context.Context, action, pkg string) (ok bool, code, data, errMsg string) {
conn, err := net.DialTimeout("unix", pkgHelperSocket, 5*time.Second)
if err != nil {
// Fallback: try executing pkg-helper directly if available
if path, lookErr := exec.LookPath("pkg-helper"); lookErr == nil {
cmd := exec.CommandContext(ctx, path, action)
if pkg != "" {
cmd.Args = append(cmd.Args, pkg)
}
out, execErr := cmd.CombinedOutput()
var resp struct {
OK bool `json:"ok"`
Error string `json:"error"`
Code string `json:"code"`
Data string `json:"data"`
}
if unmarshalErr := json.Unmarshal(out, &resp); unmarshalErr == nil {
if resp.Code == "" && !resp.OK {
resp.Code = "system_error"
}
return resp.OK, resp.Code, resp.Data, resp.Error
}
if execErr != nil {
return false, "system_error", "", fmt.Sprintf("pkg-helper fallback failed: %v: %s", execErr, strings.TrimSpace(string(out)))
}
return true, "", string(out), ""
}
return false, "helper_unavailable", "", fmt.Sprintf("pkg-helper unavailable: %v", err)
}
defer conn.Close()