(filePath: string, content: string | Buffer)
| 40 | } |
| 41 | |
| 42 | async function writeFileAtomically(filePath: string, content: string | Buffer): Promise<void> { |
| 43 | const dir = path.dirname(filePath) |
| 44 | await mkdir(dir, { recursive: true }) |
| 45 | |
| 46 | const tmpPath = path.join( |
| 47 | dir, |
| 48 | `.${path.basename(filePath)}.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp` |
| 49 | ) |
| 50 | |
| 51 | try { |
| 52 | await writeFile(tmpPath, content) |
| 53 | await rename(tmpPath, filePath) |
| 54 | } catch (error) { |
| 55 | try { |
| 56 | await unlink(tmpPath) |
| 57 | } catch { |
| 58 | // Ignore temp cleanup errors |
| 59 | } |
| 60 | throw error |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | export function setupFileSystemHandlers(): void { |
| 65 | // 获取应用数据目录 |
no outgoing calls
no test coverage detected