Skip to content

Commit 768c81c

Browse files
committed
core: prevent concurrent bun package installs that could cause corruption or conflicts
1 parent bcea8ed commit 768c81c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

packages/opencode/src/bun/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Log } from "../util/log"
44
import path from "path"
55
import { NamedError } from "../util/error"
66
import { readableStreamToText } from "bun"
7+
import { Lock } from "../util/lock"
78

89
export namespace BunProc {
910
const log = Log.create({ service: "bun" })
@@ -58,6 +59,9 @@ export namespace BunProc {
5859
)
5960

6061
export async function install(pkg: string, version = "latest") {
62+
// Use lock to ensure only one install at a time
63+
using _ = await Lock.write("bun-install")
64+
6165
const mod = path.join(Global.Path.cache, "node_modules", pkg)
6266
const pkgjson = Bun.file(path.join(Global.Path.cache, "package.json"))
6367
const parsed = await pkgjson.json().catch(async () => {

0 commit comments

Comments
 (0)