Skip to content

Make default Markdown publication atomic and root-contained #261

Description

@chubes4

Problem

The default post-type-hierarchy layout is the canonical production layout, but WP_Markdown_Storage::write_post() publishes with an in-place file_put_contents(..., LOCK_EX). A terminated or failed write can leave the authoritative Markdown file truncated or partial.

This legacy path also creates and traverses directories without applying the symlink-segment and root-containment checks used by custom layout profiles. A linked segment inside the canonical tree can redirect publication outside MARKDOWN_DB_CONTENT_DIR.

Relevant implementation: inc/class-wp-markdown-storage.php, default-layout write path around lines 276-308. The default profile is marked legacy in inc/class-wp-markdown-content-layout-profiles.php.

This is a concrete storage-integrity prerequisite for the pure-PHP canonical engine tracked in #232 and may also close one class of durability failure represented by #99.

Required outcome

  • Publish default-layout Markdown through a same-directory staged file and atomic replacement.
  • Preserve the previous complete canonical file whenever staging or publication fails.
  • Validate every destination path segment beneath the canonical root and reject symlinks or directory replacement.
  • Retain current hierarchy promotion, stale-path cleanup, indexing, and mutation receipts.
  • Add deterministic coverage for failed publication, interrupted-write safety, and linked path segments.

Acceptance criteria

  • Readers observe either the previous complete file or the next complete file, never a partial write.
  • A failed replacement leaves the prior canonical post readable and unchanged.
  • No default-layout write can escape the configured content root through a symlinked segment.
  • Existing default-layout and parent-promotion tests continue to pass.

AI assistance

GPT-5.6 Sol via OpenCode reviewed the storage implementation, identified the publication and containment gaps, and helped structure this issue and its acceptance criteria. Chris Huber directed the review and issue creation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions