Delete the stale old post file when publish writes to a new path #76

Closed
opened 2026-07-20 19:43:59 +00:00 by hugo · 1 comment
Owner

Source: Audit section 2.7.

Spec: specs/engine_side_effects.allium PublishPostSideEffects: "if old_file_path != new_file_path: ensures OldPostFileDeleted(old_file_path)".

bDS2: ../bDS2/lib/bds/posts.ex publish_post (~line 188): if post.file_path != "" and post.file_path != relative_path, do: delete_post_file(post).

Current behaviour (RuDS): crates/bds-core/src/engine/post.rs publish_post_in_savepoint computes rel_path from created_at+slug and writes there, but never removes a previous file at a different post.file_path. Reachable when a rebuilt/imported post has a file_path that differs from the computed layout (e.g. slug changed while draft after an orphan import, or a legacy layout). Leaves orphan .md files that metadata diff then reports.

Task: Before/after writing the new file in publish_post_in_savepoint, if post.file_path (pre-publish value) is non-empty and differs from the new relative path, delete the old file (ignore missing). Mirror the same logic in publish_translation (bDS2: Translations module — verify whether it also cleans old paths, and match).

Acceptance: Test: post with divergent stored file_path publishes → old file gone, new file present, DB file_path updated.

**Source:** Audit section 2.7. **Spec:** `specs/engine_side_effects.allium` PublishPostSideEffects: "if old_file_path != new_file_path: ensures OldPostFileDeleted(old_file_path)". **bDS2:** `../bDS2/lib/bds/posts.ex` `publish_post` (~line 188): `if post.file_path != "" and post.file_path != relative_path, do: delete_post_file(post)`. **Current behaviour (RuDS):** `crates/bds-core/src/engine/post.rs` `publish_post_in_savepoint` computes `rel_path` from created_at+slug and writes there, but never removes a previous file at a different `post.file_path`. Reachable when a rebuilt/imported post has a file_path that differs from the computed layout (e.g. slug changed while draft after an orphan import, or a legacy layout). Leaves orphan .md files that metadata diff then reports. **Task:** Before/after writing the new file in `publish_post_in_savepoint`, if `post.file_path` (pre-publish value) is non-empty and differs from the new relative path, delete the old file (ignore missing). Mirror the same logic in `publish_translation` (bDS2: `Translations` module — verify whether it also cleans old paths, and match). **Acceptance:** Test: post with divergent stored file_path publishes → old file gone, new file present, DB file_path updated.
hugo added the bug label 2026-07-20 19:43:59 +00:00
Author
Owner

Implemented and pushed in 53ada2c. Canonical post publishing now captures the stored pre-publish path, atomically writes the computed canonical file, then removes a distinct non-empty old file before persisting the new path. Missing old files are explicitly ignored; other removal failures propagate. Dedicated tests cover existing and already-missing legacy paths, new-file and DB-path results, and the real desktop Publish flow. bDS2 translation publishing was verified separately: it does not delete a divergent prior translation file, so RuDS intentionally remains unchanged there and a regression test records that baseline distinction. README updated. Neutral review compared issue #76, bDS2 posts/file_sync/translations, and PublishPostSideEffects. Verification: Allium check/analyse, cargo fmt/check/build, cargo machete, all post tests, focused UI integration, and cargo test --workspace (green; one intentional model-download ignore).

Implemented and pushed in 53ada2c. Canonical post publishing now captures the stored pre-publish path, atomically writes the computed canonical file, then removes a distinct non-empty old file before persisting the new path. Missing old files are explicitly ignored; other removal failures propagate. Dedicated tests cover existing and already-missing legacy paths, new-file and DB-path results, and the real desktop Publish flow. bDS2 translation publishing was verified separately: it does not delete a divergent prior translation file, so RuDS intentionally remains unchanged there and a regression test records that baseline distinction. README updated. Neutral review compared issue #76, bDS2 posts/file_sync/translations, and PublishPostSideEffects. Verification: Allium check/analyse, cargo fmt/check/build, cargo machete, all post tests, focused UI integration, and cargo test --workspace (green; one intentional model-download ignore).
hugo closed this issue 2026-07-21 20:31:26 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: hugo/RuDS#76