Skip to content

Commit 8a1cf0a

Browse files
committed
Truncate static cache files before writing
1 parent bc3afd0 commit 8a1cf0a

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/StaticCaching/Cachers/Writer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function write($path, $content, $lockFor = 0)
4343
return false;
4444
}
4545

46+
// Truncate the file before writing. Since the "c" mode doesn't truncate and leaves
47+
// the pointer at the start, writing content shorter than what's already on disk
48+
// would otherwise leave stale bytes behind, producing an invalid document.
49+
ftruncate($handle, 0);
50+
4651
fwrite($handle, $content);
4752
chmod($path, $this->permissions['file']);
4853

0 commit comments

Comments
 (0)