fix(firehose): seed firehose-apps.json with empty data; atomic write …#709
Conversation
…for images.json
- Replace 1.5MB populated firehose-apps.json with a minimal empty seed
{"apps":[],"metadata":{"schemaVersion":"1.0.0","generatedAt":null}}
so a clean git clone builds successfully without running fetch-firehose.js
Closes #48
- Write images.json atomically via a .tmp file + fs.renameSync to prevent
build-time reads from seeing a partially-written file on concurrent runs
Closes #49
Assisted-by: Claude Sonnet 4.6 via GitHub Copilot
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request modifies scripts/fetch-github-images.js to implement atomic file writes by using a temporary file before renaming it to the final destination. A review comment identified a potential race condition where concurrent executions of the script would collide on the same static temporary filename and suggested incorporating the process ID into the filename to ensure uniqueness.
| const TMP_FILE = OUTPUT_FILE + ".tmp"; | ||
| fs.writeFileSync(TMP_FILE, JSON.stringify(output, null, 2), "utf-8"); | ||
| fs.renameSync(TMP_FILE, OUTPUT_FILE); |
There was a problem hiding this comment.
Using a static filename for the temporary file (OUTPUT_FILE + ".tmp") introduces a race condition if multiple instances of this script run concurrently. While the atomic rename protects readers, concurrent writers will collide on the same temporary file, potentially leading to data corruption or process crashes (e.g., when one instance renames the file while another is still writing to it). To safely handle concurrent runs as intended, use a unique temporary filename by incorporating the process ID.
| const TMP_FILE = OUTPUT_FILE + ".tmp"; | |
| fs.writeFileSync(TMP_FILE, JSON.stringify(output, null, 2), "utf-8"); | |
| fs.renameSync(TMP_FILE, OUTPUT_FILE); | |
| const TMP_FILE = OUTPUT_FILE + "." + process.pid + ".tmp"; | |
| fs.writeFileSync(TMP_FILE, JSON.stringify(output, null, 2), "utf-8"); | |
| fs.renameSync(TMP_FILE, OUTPUT_FILE); |
…for images.json
Assisted-by: Claude Sonnet 4.6 via GitHub Copilot