Delete the stale old post file when publish writes to a new path #76
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Source: Audit section 2.7.
Spec:
specs/engine_side_effects.alliumPublishPostSideEffects: "if old_file_path != new_file_path: ensures OldPostFileDeleted(old_file_path)".bDS2:
../bDS2/lib/bds/posts.expublish_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.rspublish_post_in_savepointcomputesrel_pathfrom created_at+slug and writes there, but never removes a previous file at a differentpost.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, ifpost.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 inpublish_translation(bDS2:Translationsmodule — 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.
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).