From 43df00cb7433100ac9774f1bc16a3b8d79dc52f5 Mon Sep 17 00:00:00 2001 From: tannevaled Date: Mon, 4 May 2026 14:14:59 +0200 Subject: [PATCH 1/3] Refactor sudo handling for package installation proposal to fix sudo handling --- pkgm.ts | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/pkgm.ts b/pkgm.ts index f3f08c3..406d1bd 100755 --- a/pkgm.ts +++ b/pkgm.ts @@ -297,23 +297,28 @@ async function query_pkgx( set("PKGX_DIST_URL"); set("XDG_DATA_HOME"); - const needs_sudo_backwards = install_prefix().string == "/usr/local"; - let cmd = needs_sudo_backwards ? "/usr/bin/sudo" : pkgx; - if (needs_sudo_backwards) { - if (!Deno.env.get("SUDO_USER")) { - if (Deno.uid() == 0) { - console.error( - "%cwarning", - "color:yellow", - "installing as root; installing via `sudo` is preferred", - ); - } - cmd = pkgx; - } else { - args.unshift("-u", Deno.env.get("SUDO_USER")!, pkgx); - } + const isRoot = Deno.uid() == 0; + const sudoUser = Deno.env.get("SUDO_USER"); + + if (install_prefix().string == "/usr/local" && isRoot && !sudoUser) { + console.error( + "%cwarning", + "color:yellow", + "installing as root; installing via `sudo` is preferred", + ); } + + const needs_sudo_backwards = + install_prefix().string == "/usr/local" && !isRoot && !sudoUser; + + let cmd = pkgx; + if (needs_sudo_backwards) { + cmd = "/usr/bin/sudo"; + const user = Deno.env.get("USER")!; + args.unshift("-u", user, pkgx); + } + const proc = new Deno.Command(cmd, { args: [...args, "--json=v1"], stdout: "piped", From 2f5723023396da75a85abb9d0870f86add7f6a96 Mon Sep 17 00:00:00 2001 From: Jacob Heider Date: Mon, 4 May 2026 12:44:39 -0400 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- pkgm.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkgm.ts b/pkgm.ts index 406d1bd..00ef27c 100755 --- a/pkgm.ts +++ b/pkgm.ts @@ -299,17 +299,18 @@ async function query_pkgx( const isRoot = Deno.uid() == 0; const sudoUser = Deno.env.get("SUDO_USER"); + const prefix = install_prefix().string; - if (install_prefix().string == "/usr/local" && isRoot && !sudoUser) { + if (prefix == "/usr/local" && isRoot && !sudoUser) { console.error( "%cwarning", "color:yellow", "installing as root; installing via `sudo` is preferred", ); } - - const needs_sudo_backwards = - install_prefix().string == "/usr/local" && !isRoot && !sudoUser; + + const needs_sudo_backwards = + prefix == "/usr/local" && !isRoot && !sudoUser; let cmd = pkgx; From ef25b1c0bb1e562eef4fc4ac7f2004d36b1a75b1 Mon Sep 17 00:00:00 2001 From: tannevaled Date: Tue, 5 May 2026 08:48:57 +0200 Subject: [PATCH 3/3] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- pkgm.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgm.ts b/pkgm.ts index 00ef27c..e7af31f 100755 --- a/pkgm.ts +++ b/pkgm.ts @@ -319,7 +319,7 @@ async function query_pkgx( const user = Deno.env.get("USER")!; args.unshift("-u", user, pkgx); } - + const proc = new Deno.Command(cmd, { args: [...args, "--json=v1"], stdout: "piped",