Skip to content

Commit 4e28898

Browse files
committed
workaround link bug only seen with dnt
possibly this is our bug due to race condition, or possibly a deno shim issue.
1 parent 5495971 commit 4e28898

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/prefab/link.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Package } from "../types.ts"
55
import install from "./install.ts"
66
import link from "./link.ts";
77

8-
Deno.test("link()", async runner => {
8+
Deno.test("prefab.link", async runner => {
99
const pkg: Package = {
1010
project: "tea.xyz/brewkit",
1111
version: new SemVer("0.30.0")
@@ -16,7 +16,7 @@ Deno.test("link()", async runner => {
1616

1717
const installation = await install(pkg)
1818
await link(installation)
19-
await link(installation) // calling twice works
19+
await link(installation) // test that calling twice serially works
2020

2121
/// test symlinks work
2222
assert(installation.path.parent().join("v*").isDirectory())

src/prefab/link.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import SemVer, * as semver from "../utils/semver.ts"
22
import { Package, Installation } from "../types.ts"
33
import useCellar from "../hooks/useCellar.ts"
44
import { panic } from "../utils/error.ts"
5+
import fs from "node:fs/promises"
56
import Path from "../utils/Path.ts"
67

78
export default async function link(pkg: Package | Installation) {
@@ -44,6 +45,19 @@ export default async function link(pkg: Package | Installation) {
4445

4546
async function makeSymlink(symname: string) {
4647
try {
48+
const what_we_make = shelf.join(symname)
49+
if (what_we_make.isSymlink()) {
50+
try {
51+
// using this rather than rm due to bug in deno shims that
52+
// tries to call rmdir on the symlink because the symlink points to a dir
53+
await fs.unlink(what_we_make.string)
54+
} catch (err) {
55+
// we were deleted by another thing linking simultaneously
56+
//FIXME our flock should surround the link step too
57+
if (err.code != 'ENOENT') throw err
58+
}
59+
}
60+
4761
await Deno.symlink(
4862
installation.path.basename(), // makes it relative
4963
shelf.join(symname).rm().string,

0 commit comments

Comments
 (0)