fix(fs): tolerate EACCES on existing mkdir targets (#319)

Add mkdirSafe/mkdirSyncSafe helpers that swallow EACCES/EPERM when the
target directory already exists with execute permission, and route all
recursive mkdir call sites through them so pre-existing directories
owned by another user do not break backend startup, file ops, or repo
mirroring.
This commit is contained in:
Chris Scott authored and GitHub committed 2026-07-23 22:51:17 -04:00
1 parent 8a8bdc18b0
commit 87f3d7f230
22 files changed
+210 -46

No files matched your search

@@ -26,6 +26,7 @@ import { writeFileContent } from './file-operations'
import { getOrCreateInternalToken } from './internal-token'
import { installGhEnvPlugin } from './opencode-gh-env-plugin'
import { CredentialProvider } from './credential-provider'
import { mkdirSafe } from '../utils/fs-safe'
const MIN_OPENCODE_VERSION = '1.0.137'
@@ -495,7 +496,7 @@ class OpenCodeServerManager {
const packageJsonPath = path.join(binDir, 'package.json')
try {
await fs.mkdir(binDir, { recursive: true })
await mkdirSafe(binDir)
const packageJsonExists = await fs.access(packageJsonPath)
.then(() => true)
@@ -600,7 +601,7 @@ class OpenCodeServerManager {
}
}
await fs.mkdir(installDir, { recursive: true })
await mkdirSafe(installDir)
if (!await fs.access(path.join(installDir, 'package.json')).then(() => true).catch(() => false)) {
const init = spawnSync('bun', ['init', '-y'], { cwd: installDir, encoding: 'utf8', timeout: 30000 })
if (init.status !== 0) {