opencode-repos 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/manifest.ts +21 -19
package/package.json
CHANGED
package/src/manifest.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { homedir } from "node:os"
|
|
2
2
|
import { join } from "node:path"
|
|
3
|
-
import { mkdir, rename, unlink, stat } from "node:fs/promises"
|
|
3
|
+
import { mkdir, rename, unlink, stat, open } from "node:fs/promises"
|
|
4
4
|
|
|
5
5
|
export interface RepoEntry {
|
|
6
6
|
type: "cached" | "local"
|
|
@@ -27,7 +27,7 @@ let cacheDir = join(homedir(), ".cache", "opencode-repos")
|
|
|
27
27
|
let manifestPath = join(cacheDir, "manifest.json")
|
|
28
28
|
let manifestTmpPath = join(cacheDir, "manifest.json.tmp")
|
|
29
29
|
let lockPath = join(cacheDir, "manifest.lock")
|
|
30
|
-
const LOCK_STALE_MS =
|
|
30
|
+
const LOCK_STALE_MS = 30_000
|
|
31
31
|
|
|
32
32
|
function createEmptyManifest(): Manifest {
|
|
33
33
|
return {
|
|
@@ -72,31 +72,33 @@ async function isLockStale(): Promise<boolean> {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
async function acquireLock(): Promise<void> {
|
|
75
|
-
const maxAttempts =
|
|
76
|
-
const retryDelayMs =
|
|
75
|
+
const maxAttempts = 150
|
|
76
|
+
const retryDelayMs = 200
|
|
77
|
+
|
|
78
|
+
await mkdir(cacheDir, { recursive: true })
|
|
77
79
|
|
|
78
80
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
try {
|
|
82
|
+
const fd = await open(lockPath, "wx")
|
|
83
|
+
await fd.write(String(process.pid))
|
|
84
|
+
await fd.close()
|
|
85
|
+
return
|
|
86
|
+
} catch (error) {
|
|
87
|
+
const code = (error as NodeJS.ErrnoException).code
|
|
88
|
+
if (code !== "EEXIST") {
|
|
89
|
+
throw error
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
await
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
} catch {
|
|
96
|
-
await Bun.sleep(retryDelayMs)
|
|
93
|
+
if (await isLockStale()) {
|
|
94
|
+
await unlink(lockPath).catch(() => {})
|
|
95
|
+
continue
|
|
97
96
|
}
|
|
97
|
+
|
|
98
|
+
await Bun.sleep(retryDelayMs)
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
await unlink(lockPath).catch(() => {})
|
|
100
102
|
throw new Error("Failed to acquire manifest lock after maximum attempts")
|
|
101
103
|
}
|
|
102
104
|
|