Skip to content

[6.x] Truncate full measure static cache files before writing#14755

Merged
jasonvarga merged 3 commits into
6.xfrom
fix-full-measure-file-truncation
Jun 2, 2026
Merged

[6.x] Truncate full measure static cache files before writing#14755
jasonvarga merged 3 commits into
6.xfrom
fix-full-measure-file-truncation

Conversation

@joshuablum
Copy link
Copy Markdown
Member

Right now, full measure static cache operations open cache files with fopen($path, 'c') and then fwrites the content. Mode c positions the pointer at the start of the file but does not truncate it. When a page is recached with content shorter than the version already on disk, the leftover bytes past the new content are still there producing a valid document followed by leftovers after the </html>.

Having background_recache enabled, saving an entry overwrites the file in place rather than deleting it, so any edit that shrinks a page leaves bits behind.

This fixes it by calling ftruncate($handle, 0) after acquiring the lock and before writing. Mode c keeps the pointer at byte 0 after truncation.

Closes #14742.

@jasonvarga jasonvarga merged commit a9ca149 into 6.x Jun 2, 2026
18 checks passed
@jasonvarga jasonvarga deleted the fix-full-measure-file-truncation branch June 2, 2026 19:42
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.

Static Cache Writer producing invalid HTML

2 participants