Skip to content

fix(ssg): copy the live output folder under the directory lock for --incremental - #156

Merged
smiggleworth merged 1 commit into
developfrom
fix/ssg-incremental-lock
Oct 2, 2026
Merged

smiggleworth merged 1 commit into
developfrom
fix/ssg-incremental-lock

Conversation

@smiggleworth

Copy link
Copy Markdown
Contributor

Summary

askr ssg --incremental copied the live output folder into its staging folder before taking the directory lock; only the final swap ran under it. Two concurrent incremental builds could race: on Windows a rename fails with EPERM while the other build is copying, and on any OS a build could stage from a half-swapped folder.

The copy now runs under the same lock as the swap through a new copyTargetIntoStage helper. The existence check happens inside the lock too, so a target that is momentarily absent mid-swap is never mistaken for a missing output folder. The lock is held only for the copy, not for site generation, so builds are not serialised for their whole duration. Each build still publishes a complete tree, so two concurrent runs both succeed and the last swap wins, and neither publishes a partial tree.

Tests

  • A deterministic race test holds the lock with the target half-swapped (removed, new content pending) and asserts the staged copy waits, then contains the complete swapped tree. It failed before the change (the helper did not exist, and the old code copied immediately).
  • A test covers the no-target case returning false with an empty stage.

npm run lint, typecheck, test:coverage (288 tests), test:changelog, build and test:publint pass.

Closes #155

…incremental

Concurrent incremental builds copied the live output folder into staging
before taking the lock, so a build could stage from a half-swapped tree or
race the other build's rename. The copy now runs under the same lock as the
swap, held only for the copy and not for site generation.
@smiggleworth
smiggleworth merged commit 7b61765 into develop Oct 2, 2026
10 checks passed
@smiggleworth
smiggleworth deleted the fix/ssg-incremental-lock branch October 2, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ssg --incremental copies the output directory outside its lock

1 participant