issues/completed/8-017-preserve-generated-files-during-sync.md
Issue 8-017: Preserve Generated Files During Input Sync
Current Behavior
The scripts/update-words script calls /home/ritz/backups/words/sync-to-projects, which does:
rm -rf "${NEOCITIES_DIR}/input"
mkdir -p "${NEOCITIES_DIR}/input"
rsync -av ${MSG_ZIP} ${FEDI_ZIP} ${NOTES_DIR} "${NEOCITIES_DIR}/input"
This deletes the entire input directory including generated files:
input/fediverse/files/poems.jsoninput/messages/files/poems.jsoninput/notes/files/poems.json
When scripts/update then runs its freshness check, the output files don't exist, causing
full re-extraction every time run.sh executes (~2-3 minutes of unnecessary work).
The Deletion Loop
run.shcallsupdate-wordsupdate-wordscallssync-to-projectssync-to-projectsdoesrm -rf input/(deletes poems.json files)scripts/updatechecks: "Do poems.json files exist?" → No!- Full extraction runs, recreates poems.json (~2-3 min)
- Next run, step 3 deletes them again...
Intended Behavior
Generated files should be preserved across sync operations. The freshness check inscripts/update should work correctly, skipping extraction when source ZIPs haven't changed.
Suggested Implementation Steps
Option A: Preserve in update-words (Recommended)
Modify scripts/update-words to back up and restore generated files:
#!/bin/bash
set -euo pipefail
DIR="${1:-/mnt/mtwo/programming/ai-stuff/neocities-modernization}"
BACKUP_DIR="${DIR}/temp/preserved-files"
# Preserve generated files before sync
preserve_generated_files() {
mkdir -p "${BACKUP_DIR}"
for subdir in fediverse messages notes; do
if [ -d "${DIR}/input/${subdir}/files" ]; then
mkdir -p "${BACKUP_DIR}/${subdir}"
cp -a "${DIR}/input/${subdir}/files" "${BACKUP_DIR}/${subdir}/"
fi
done
}
# Restore generated files after sync
restore_generated_files() {
for subdir in fediverse messages notes; do
if [ -d "${BACKUP_DIR}/${subdir}/files" ]; then
mkdir -p "${DIR}/input/${subdir}"
cp -a "${BACKUP_DIR}/${subdir}/files" "${DIR}/input/${subdir}/"
fi
done
rm -rf "${BACKUP_DIR}"
}
# Run with preservation
preserve_generated_files
/home/ritz/backups/words/sync-to-projects > /dev/null 2>&1
restore_generated_files
# Remove unwanted ZIP files
rm -f "${DIR}/input/images/poem-pictures/neocities-ritz-menardi.zip"
Option B: Use Content Checksums
Store SHA256 checksums of ZIP files in a manifest. Only extract if checksums change:
MANIFEST="${DIR}/assets/extraction-manifest.json"
# Contains: {"most-recent-29.zip": "abc123...", "similar-different.zip": "def456..."}
Option C: Modify External Script (Requires coordination)
Modify sync-to-projects to use rsync without deleting the entire directory:
# Instead of: rm -rf input && mkdir -p input && rsync ...
# Use: rsync -av --delete --exclude='*/files/' ...
Impact
- Before fix: Full extraction every run (~2-3 minutes)
- After fix: Extraction only when ZIPs actually change (~5 seconds skip check)
Related Files
scripts/update-words- Entry point for sync (in project)/home/ritz/backups/words/sync-to-projects- External sync scriptscripts/update- Has freshness check that fails due to deleted filesinput/*/files/poems.json- Generated files being deleted
Implementation (2025-12-23)
Implemented Option A: Modified scripts/update-words to preserve and restore generated files.
Test results:
=== Running update-words ===
💾 Preserved 3 generated file directories
♻️ Restored 3 generated file directories
=== Running scripts/update (should skip) ===
✅ Extraction data is up to date, skipping ZIP extraction
File timestamps are preserved across sync, freshness check works correctly.
Document History
- Created: 2025-12-23
- Implemented: 2025-12-23
- Status: Completed
- Phase: 8
- Priority: High (affects every run.sh execution)