Exports: atomic file writes, export folder locks, re-export unreadable model.json (SIX-203) #259

Manually merged
github merged 2 commits from gh-pr/259/head into gh-pr/259/base 2026-11-26 20:22:17 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-25 11:55 UTC · original
holdmysocks:six-203-atomic-writes → master · +447 −215 · 46 files · 2 commits · merged 2026-11-25 12:33 UTC

Fixes SIX-203: a large extract --force run over existing folders left some model.json files with a new JSON object followed by an older file's tail, and others zero-filled after runs were killed.

What changes

  • New sixng_core::atomic module. atomic::write replaces fs::write and atomic::AtomicFile replaces BufWriter<File> for every export write in sixng-core and the CLI: model.json, materials.json, GLBs, buffers, textures and PNGs, index.jsonl, manifests, map and placement jsonl and bins, gz indexes, vehicle and outfit GLBs, and movies. Each file goes to a hidden temp file in its folder and is renamed over the target. A killed run keeps the old file. Two writers leave one complete copy.
  • The hand-rolled temp + rename code now uses the helper. Some of it named temp files by thread id, so two processes could share one temp file.
  • Model and texture dictionary folders are locked while they are written. The lock is a .sixng.lock file held on an open handle, so the OS frees it if the process dies. A second run waits up to two minutes, then reports the folder as busy. The holder clears temp files that killed runs left behind.
  • Without --force, the skip-if-present check treats a model.json or dictionary.json that doesn't parse as missing. A plain re-run repairs the bad files.
  • No fsync on commit: it measured about 6 ms a file, and a killed process loses nothing once the rename is done.

Tests

  • New tests: 16 threads overwriting one file with long and short copies; a write killed before commit; zero-filled and stale-tail JSON reading as missing; a second lock waiting and then failing.
  • cargo check --workspace --all-targets is clean, and cargo test -p sixng-core -p sixng-gui --release passes.

Not covered

  • The viewer's own writes (map bake, settings, livery files) still use fs::write.
  • Temp files in shared texture folders, which aren't locked, are only removed by the run that made them.
**@⁠holdmysocks** on GitHub · 2026-11-25 11:55 UTC · [original](https://github.com/holdmysocks/SixNG/pull/259) `holdmysocks:six-203-atomic-writes` → `master` · +447 −215 · 46 files · 2 commits · merged 2026-11-25 12:33 UTC Fixes SIX-203: a large `extract --force` run over existing folders left some model.json files with a new JSON object followed by an older file's tail, and others zero-filled after runs were killed. **What changes** - New `sixng_core::atomic` module. `atomic::write` replaces `fs::write` and `atomic::AtomicFile` replaces `BufWriter<File>` for every export write in sixng-core and the CLI: model.json, materials.json, GLBs, buffers, textures and PNGs, index.jsonl, manifests, map and placement jsonl and bins, gz indexes, vehicle and outfit GLBs, and movies. Each file goes to a hidden temp file in its folder and is renamed over the target. A killed run keeps the old file. Two writers leave one complete copy. - The hand-rolled temp + rename code now uses the helper. Some of it named temp files by thread id, so two processes could share one temp file. - Model and texture dictionary folders are locked while they are written. The lock is a `.sixng.lock` file held on an open handle, so the OS frees it if the process dies. A second run waits up to two minutes, then reports the folder as busy. The holder clears temp files that killed runs left behind. - Without `--force`, the skip-if-present check treats a model.json or dictionary.json that doesn't parse as missing. A plain re-run repairs the bad files. - No fsync on commit: it measured about 6 ms a file, and a killed process loses nothing once the rename is done. **Tests** - New tests: 16 threads overwriting one file with long and short copies; a write killed before commit; zero-filled and stale-tail JSON reading as missing; a second lock waiting and then failing. - `cargo check --workspace --all-targets` is clean, and `cargo test -p sixng-core -p sixng-gui --release` passes. **Not covered** - The viewer's own writes (map bake, settings, livery files) still use `fs::write`. - Temp files in shared texture folders, which aren't locked, are only removed by the run that made them.
Every export write now goes through sixng_core::atomic: the data goes to a
hidden temp file in the target's folder and is renamed over the target, so a
killed run keeps the old file and two writers leave one whole copy instead of
a short file followed by an older file's tail (or a zero-filled file).

- atomic::write replaces fs::write; atomic::AtomicFile replaces the
  BufWriter<File> streams (jsonl, batch bins, gz indexes, movies, PNGs).
  Hand-rolled temp + rename code (some with per-thread temp names that two
  processes could share) now uses the helper.
- Model and texture dictionary folders are locked while they are written
  (a lock file held on an open handle, freed if the process dies); a second
  run waits up to two minutes, then reports the folder as busy. The lock
  holder clears temp files that killed runs left behind.
- The skip-if-present check treats a model.json or dictionary.json that
  does not parse as missing, so a re-run without --force repairs it.
- Tests: overlapping writers, a killed write, bad JSON, and the lock.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:22:15 +00:00
github manually merged commit 1bb9035bbe into gh-pr/259/base 2026-11-26 20:22:17 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.