Files
oh-my-opencode/packages/omo-claude/plugin/components/telemetry/src/atomic-write.ts
T
YeonGyu-Kim 024788c823 feat(omo-claude): fork telemetry with distinct identity and derived literals
omo_claude_daily_active event + omo-claude: distinct-id salt; PostHog key/host/
LEGACY_PARENT_PACKAGE kept identical (shared project). platform + tmp-fallback
derived from constants (no literals). 4-flag opt-out incl inherited OMO_*.
cross-package-equivalence + cross-product distinctness tests (RED->GREEN).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-29 13:40:10 +09:00

23 lines
595 B
TypeScript

import { renameSync, unlinkSync, writeFileSync } from "node:fs"
export function writeFileAtomically(filePath: string, content: string): void {
const tempPath = `${filePath}.tmp`
writeFileSync(tempPath, content, "utf-8")
try {
renameSync(tempPath, filePath)
} catch (error) {
const isPermissionError =
error instanceof Error &&
(error.message.includes("EPERM") || error.message.includes("EACCES"))
if (process.platform === "win32" && isPermissionError) {
unlinkSync(filePath)
renameSync(tempPath, filePath)
return
}
throw error
}
}