* Write lock content to a file atomically
( lockFilePath: string, content: VersionLockContent, )
| 210 | * Write lock content to a file atomically |
| 211 | */ |
| 212 | function writeLockFile( |
| 213 | lockFilePath: string, |
| 214 | content: VersionLockContent, |
| 215 | ): void { |
| 216 | const fs = getFsImplementation() |
| 217 | const tempPath = `${lockFilePath}.tmp.${process.pid}.${Date.now()}` |
| 218 | |
| 219 | try { |
| 220 | writeFileSync_DEPRECATED(tempPath, jsonStringify(content, null, 2), { |
| 221 | encoding: 'utf8', |
| 222 | flush: true, |
| 223 | }) |
| 224 | fs.renameSync(tempPath, lockFilePath) |
| 225 | } catch (error) { |
| 226 | // Clean up temp file on failure (best-effort) |
| 227 | try { |
| 228 | fs.unlinkSync(tempPath) |
| 229 | } catch { |
| 230 | // Ignore cleanup errors (ENOENT expected if write failed before file creation) |
| 231 | } |
| 232 | throw error |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Try to acquire a lock on a version file |
no test coverage detected