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