diff --git a/pkgm.ts b/pkgm.ts index f128669..2e80d09 100755 --- a/pkgm.ts +++ b/pkgm.ts @@ -506,12 +506,23 @@ function expand_runtime_env( } function symlink_with_overwrite(src: string, dst: string) { - if (existsSync(dst) && Deno.lstatSync(dst).isSymlink) { + if (isSymlink(dst)) { Deno.removeSync(dst); } Deno.symlinkSync(src, dst); } +function isSymlink(path: string): boolean { + try { + return Deno.lstatSync(path).isSymlink; + } catch (err) { + if (err instanceof Deno.errors.NotFound) { + return false; + } + throw err; + } +} + function get_pkgx() { for (const path of Deno.env.get("PATH")!.split(":")) { const pkgx = join(path, "pkgx");