@@ -120,18 +120,6 @@ async function install(args: string[], basePath: string) {
120120 // deno-lint-ignore no-explicit-any
121121 const pkg_prefixes = json . pkgs . map ( ( x : any ) => `${ x . project } /v${ x . version } ` ) ;
122122
123- const to_install = [ ] ;
124- for ( const prefix of pkg_prefixes ) {
125- if ( ! existsSync ( join ( `${ basePath } /pkgs` , prefix ) ) ) {
126- to_install . push ( prefix ) ;
127- }
128- }
129-
130- if ( to_install . length === 0 ) {
131- console . error ( "pkgs already installed" ) ;
132- Deno . exit ( 0 ) ;
133- }
134-
135123 const self = fromFileUrl ( import . meta. url ) ;
136124 const pkgx_dir = Deno . env . get ( "PKGX_DIR" ) || `${ Deno . env . get ( "HOME" ) } /.pkgx` ;
137125 const needs_sudo = Deno . uid ( ) != 0 && basePath === "/usr/local" ;
@@ -150,7 +138,7 @@ async function install(args: string[], basePath: string) {
150138 pkgx_dir ,
151139 runtime_env ,
152140 basePath ,
153- ...to_install ,
141+ ...pkg_prefixes ,
154142 ] ;
155143 let cmd = "" ;
156144 if ( needs_sudo ) {
@@ -237,12 +225,16 @@ async function mirror_directory(dst: string, src: string, prefix: string) {
237225 await processEntry ( entrySourcePath , entryTargetPath ) ;
238226 }
239227 } else if ( fileInfo . isFile ) {
228+ // Remove the target file if it exists
229+ if ( existsSync ( targetPath ) ) {
230+ await Deno . remove ( targetPath ) ;
231+ }
240232 // Create a hard link for files
241233 await Deno . link ( sourcePath , targetPath ) ;
242234 } else if ( fileInfo . isSymlink ) {
243235 // Recreate symlink in the target directory
244236 const linkTarget = await Deno . readLink ( sourcePath ) ;
245- await Deno . symlink ( linkTarget , targetPath ) ;
237+ symlink_with_overwrite ( linkTarget , targetPath ) ;
246238 } else {
247239 throw new Error ( `unsupported file type at: ${ sourcePath } ` ) ;
248240 }
@@ -275,7 +267,7 @@ async function symlink(src: string, dst: string) {
275267 if ( existsSync ( targetPath ) ) {
276268 await Deno . remove ( targetPath ) ;
277269 }
278- await Deno . symlink ( sourcePath , targetPath ) ;
270+ symlink_with_overwrite ( sourcePath , targetPath ) ;
279271 }
280272 }
281273}
@@ -310,7 +302,7 @@ async function create_v_symlinks(prefix: string) {
310302 }
311303
312304 for ( const [ key , value ] of Object . entries ( major_versions ) ) {
313- await Deno . symlink ( `v${ semver . format ( value ) } ` , join ( shelf , `v${ key } ` ) ) ;
305+ symlink_with_overwrite ( `v${ semver . format ( value ) } ` , join ( shelf , `v${ key } ` ) ) ;
314306 }
315307}
316308
@@ -329,3 +321,10 @@ function expand_runtime_env(
329321 }
330322 return JSON . stringify ( expanded ) ;
331323}
324+
325+ function symlink_with_overwrite ( src : string , dst : string ) {
326+ if ( existsSync ( dst ) ) {
327+ Deno . removeSync ( dst ) ;
328+ }
329+ Deno . symlinkSync ( src , dst ) ;
330+ }
0 commit comments