Resync linked media sidecars when a post is deleted #77
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.8.
Spec:
specs/engine_side_effects.alliumDeletePostSideEffects: "for media_link in post.linked_media: ensures MediaSidecarUpdated(media_link.media_id) — removes post from media sidecar's linkedPostIds". Media sidecars carrylinkedPostIds(specs/frontmatter.alliumMediaSidecar).bDS2:
../bDS2/lib/bds/posts.exdelete_postcollects linked media ids first and callssync_deleted_post_media_sidecar/1(→Media.sync_media_sidecar) for each after deletion.Current behaviour (RuDS):
crates/bds-core/src/engine/post.rsdelete_post(~line 474) deletes the post_media rows but never rewrites the affected media sidecars, so theirlinkedPostIdskeep referencing the deleted post — a divergence metadata diff will surface, and rebuild-from-filesystem would resurrect dead links.Task: In
delete_post, capturemedia_ids from post_media (ordered per bDS2: sort_order, media_id) before deleting the rows, then after deletion rewrite each media's sidecar (engine/media.rs already has the sidecar writer — reuse whateverupdate_mediauses). Checkcrates/bds-core/src/engine/post_media.rslink/unlink paths also keep sidecars in sync (spec: metadata must flush to filesystem).Acceptance: Test: link media to post, publish (sidecar contains post id), delete post → sidecar no longer lists the post id.
Implemented in
1cdc86b. Post deletion now captures linked media in deterministic sort-order/media-id order before removing associations, deletes the post, and rewrites every surviving media sidecar through a shared canonical media-sidecar writer. Link, unlink, media metadata updates, and media-file replacement now use that same writer, while a concurrently missing media record is ignored in parity with bDS2. Added a regression test covering a published post linked to multiple media items and preservation of another post's linkedPostIds, and updated the README. Verified with Allium check/analyse, cargo fmt --check, cargo check --workspace, cargo machete --with-metadata, cargo build --workspace, focused link/unlink/deletion tests, and cargo test --workspace (all passed; one intentional model-download test ignored).