File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ async function install(args: string[], basePath: string) {
122122
123123 const self = fromFileUrl ( import . meta. url ) ;
124124 const pkgx_dir = Deno . env . get ( "PKGX_DIR" ) || `${ Deno . env . get ( "HOME" ) } /.pkgx` ;
125- const needs_sudo = Deno . uid ( ) != 0 && basePath === "/usr/local" ;
125+ const needs_sudo = basePath === "/usr/local" && ! writable ( "/usr/local" ) ;
126126
127127 const runtime_env = expand_runtime_env ( json , basePath ) ;
128128
@@ -493,7 +493,8 @@ async function uninstall(arg: string) {
493493 Deno . exit ( 1 ) ;
494494 }
495495
496- const needs_sudo = files . some ( ( p ) => p . string . startsWith ( "/usr/local" ) ) ;
496+ const needs_sudo = files . some ( ( p ) => p . string . startsWith ( "/usr/local" ) ) &&
497+ ! writable ( "/usr/local" ) ;
497498 if ( needs_sudo ) {
498499 {
499500 const { success, code } = await new Deno . Command ( "/usr/bin/sudo" , {
@@ -546,3 +547,14 @@ async function uninstall(arg: string) {
546547 }
547548 }
548549}
550+
551+ function writable ( path : string ) {
552+ try {
553+ //FIXME this is pretty gross
554+ Deno . mkdirSync ( join ( path , ".writable_test" ) , { recursive : true } ) ;
555+ Deno . remove ( join ( path , ".writable_test" ) ) ;
556+ return true ;
557+ } catch {
558+ return false ;
559+ }
560+ }
You can’t perform that action at this time.
0 commit comments