Skip to content

Commit

Permalink
FileStorage: removed <?php from cache file structure (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 18, 2017
1 parent 13afec7 commit 31225fa
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Caching/Storages/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class FileStorage implements Nette\Caching\IStorage
* delete* = try unlink, if fails (on NTFS) { lock(EX), truncate, close, unlink } else close (on ext3)
*/

/** @internal cache file structure */
/** @internal cache file structure: meta-struct size + serialized meta-struct + data */
private const
META_HEADER_LEN = 28, // 22b signature + 6b meta-struct size + serialized meta-struct + data
META_HEADER_LEN = 6,
// meta structure: array of
META_TIME = 'time', // timestamp
META_SERIALIZED = 'serialized', // is content serialized?
Expand Down Expand Up @@ -205,8 +205,8 @@ public function write(string $key, $data, array $dp): void
$meta[self::META_SERIALIZED] = true;
}

$head = serialize($meta) . '?>';
$head = '<?php //netteCache[01]' . str_pad((string) strlen($head), 6, '0', STR_PAD_LEFT) . $head;
$head = serialize($meta);
$head = str_pad((string) strlen($head), 6, '0', STR_PAD_LEFT) . $head;
$headLen = strlen($head);

do {
Expand Down Expand Up @@ -321,9 +321,9 @@ protected function readMetaAndLock(string $file, int $lock): ?array

flock($handle, $lock);

$head = stream_get_contents($handle, self::META_HEADER_LEN);
if ($head && strlen($head) === self::META_HEADER_LEN) {
$size = (int) substr($head, -6);
$size = stream_get_contents($handle, self::META_HEADER_LEN);
if ($size && strlen($size) === self::META_HEADER_LEN) {
$size = (int) $size;
$meta = stream_get_contents($handle, $size, self::META_HEADER_LEN);
$meta = unserialize($meta);
$meta[self::FILE] = $file;
Expand Down

0 comments on commit 31225fa

Please sign in to comment.