@@ -104,18 +104,6 @@ async function install(args: string[]) {
104104 // deno-lint-ignore no-explicit-any
105105 const pkg_prefixes = json . pkgs . map ( ( x : any ) => `${ x . project } /v${ x . version } ` ) ;
106106
107- const to_install = [ ] ;
108- for ( const prefix of pkg_prefixes ) {
109- if ( ! existsSync ( join ( "/usr/local/pkgs" , prefix ) ) ) {
110- to_install . push ( prefix ) ;
111- }
112- }
113-
114- if ( to_install . length === 0 ) {
115- console . error ( "pkgs already installed" ) ;
116- Deno . exit ( 0 ) ;
117- }
118-
119107 const self = fromFileUrl ( import . meta. url ) ;
120108 const pkgx_dir = Deno . env . get ( "PKGX_DIR" ) || `${ Deno . env . get ( "HOME" ) } /.pkgx` ;
121109 const needs_sudo = Deno . uid ( ) != 0 ;
@@ -133,7 +121,7 @@ async function install(args: string[]) {
133121 "sudo-install" ,
134122 pkgx_dir ,
135123 runtime_env ,
136- ...to_install ,
124+ ...pkg_prefixes ,
137125 ] ;
138126 const cmd = needs_sudo ? "/usr/bin/sudo" : args . shift ( ) ! ;
139127 status = await new Deno . Command ( cmd , { args, env, clearEnv : true } )
@@ -209,12 +197,16 @@ async function mirror_directory(dst: string, src: string, prefix: string) {
209197 await processEntry ( entrySourcePath , entryTargetPath ) ;
210198 }
211199 } else if ( fileInfo . isFile ) {
200+ // Remove the target file if it exists
201+ if ( existsSync ( targetPath ) ) {
202+ await Deno . remove ( targetPath ) ;
203+ }
212204 // Create a hard link for files
213205 await Deno . link ( sourcePath , targetPath ) ;
214206 } else if ( fileInfo . isSymlink ) {
215207 // Recreate symlink in the target directory
216208 const linkTarget = await Deno . readLink ( sourcePath ) ;
217- await Deno . symlink ( linkTarget , targetPath ) ;
209+ symlink_with_overwrite ( linkTarget , targetPath ) ;
218210 } else {
219211 throw new Error ( `unsupported file type at: ${ sourcePath } ` ) ;
220212 }
@@ -247,7 +239,7 @@ async function symlink(src: string, dst: string) {
247239 if ( existsSync ( targetPath ) ) {
248240 await Deno . remove ( targetPath ) ;
249241 }
250- await Deno . symlink ( sourcePath , targetPath ) ;
242+ symlink_with_overwrite ( sourcePath , targetPath ) ;
251243 }
252244 }
253245}
@@ -282,7 +274,7 @@ async function create_v_symlinks(prefix: string) {
282274 }
283275
284276 for ( const [ key , value ] of Object . entries ( major_versions ) ) {
285- await Deno . symlink ( `v${ semver . format ( value ) } ` , join ( shelf , `v${ key } ` ) ) ;
277+ symlink_with_overwrite ( `v${ semver . format ( value ) } ` , join ( shelf , `v${ key } ` ) ) ;
286278 }
287279}
288280
@@ -300,3 +292,10 @@ function expand_runtime_env(
300292 }
301293 return JSON . stringify ( expanded ) ;
302294}
295+
296+ function symlink_with_overwrite ( src : string , dst : string ) {
297+ if ( existsSync ( dst ) ) {
298+ Deno . removeSync ( dst ) ;
299+ }
300+ Deno . symlinkSync ( src , dst ) ;
301+ }
0 commit comments