fix(team-mode): tolerate EPERM during fsync in atomicWrite and acquireLock
Replaces direct fileHandle.sync() calls in acquireLock and atomicWrite with tolerantFsync. Users on iCloud Drive / OneDrive / Desktop sync folders were hitting 'EPERM: operation not permitted, fsync' during team_create, which propagated up and aborted the entire team_create flow even though the actual write+rename had succeeded. Reported on Discord (omo 4.0.0, opencode desktop 1.14.41, project on synced Desktop). atomicity is preserved by the temp-file rename; only the durability hint is now best-effort on filesystems that disallow fsync.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { randomUUID } from "node:crypto"
|
import { randomUUID } from "node:crypto"
|
||||||
import { open, readFile, rename, rm, unlink, writeFile } from "node:fs/promises"
|
import { open, readFile, rename, rm, unlink, writeFile } from "node:fs/promises"
|
||||||
|
|
||||||
|
import { tolerantFsync } from "../../../shared/tolerant-fsync"
|
||||||
|
|
||||||
type LockOptions = {
|
type LockOptions = {
|
||||||
staleAfterMs?: number
|
staleAfterMs?: number
|
||||||
ownerTag?: string
|
ownerTag?: string
|
||||||
@@ -51,7 +53,7 @@ async function acquireLock(lockPath: string, ownerTag: string, staleAfterMs: num
|
|||||||
const fileHandle = await open(lockPath, "wx")
|
const fileHandle = await open(lockPath, "wx")
|
||||||
try {
|
try {
|
||||||
await fileHandle.writeFile(buildOwnerContent(ownerTag))
|
await fileHandle.writeFile(buildOwnerContent(ownerTag))
|
||||||
await fileHandle.sync()
|
await tolerantFsync(fileHandle, `acquireLock:${lockPath}`)
|
||||||
} finally {
|
} finally {
|
||||||
await fileHandle.close()
|
await fileHandle.close()
|
||||||
}
|
}
|
||||||
@@ -116,7 +118,7 @@ export async function atomicWrite(
|
|||||||
await writeFile(tmpPath, content)
|
await writeFile(tmpPath, content)
|
||||||
const fileHandle = await open(tmpPath, "r")
|
const fileHandle = await open(tmpPath, "r")
|
||||||
try {
|
try {
|
||||||
await fileHandle.sync()
|
await tolerantFsync(fileHandle, `atomicWrite:${filePath}`)
|
||||||
} finally {
|
} finally {
|
||||||
await fileHandle.close()
|
await fileHandle.close()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user