Skip to content

Commit dab7263

Browse files
author
James Reynolds
committed
Add isSymlink function and use it in symlink_with_overwrite
1 parent 4a1f44d commit dab7263

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

pkgm.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,23 @@ function expand_runtime_env(
506506
}
507507

508508
function symlink_with_overwrite(src: string, dst: string) {
509-
if (existsSync(dst) && Deno.lstatSync(dst).isSymlink) {
509+
if (isSymlink(dst)) {
510510
Deno.removeSync(dst);
511511
}
512512
Deno.symlinkSync(src, dst);
513513
}
514514

515+
function isSymlink(path: string): boolean {
516+
try {
517+
return Deno.lstatSync(path).isSymlink;
518+
} catch (err) {
519+
if (err instanceof Deno.errors.NotFound) {
520+
return false;
521+
}
522+
throw err;
523+
}
524+
}
525+
515526
function get_pkgx() {
516527
for (const path of Deno.env.get("PATH")!.split(":")) {
517528
const pkgx = join(path, "pkgx");

0 commit comments

Comments
 (0)