@@ -31,9 +31,9 @@ class FileStorage implements Nette\Caching\IStorage
3131 * delete* = try unlink, if fails (on NTFS) { lock(EX), truncate, close, unlink } else close (on ext3)
3232 */
3333
34- /** @internal cache file structure */
34+ /** @internal cache file structure: meta-struct size + serialized meta-struct + data */
3535 private const
36- META_HEADER_LEN = 28 , // 22b signature + 6b meta-struct size + serialized meta-struct + data
36+ META_HEADER_LEN = 6 ,
3737 // meta structure: array of
3838 META_TIME = 'time ' , // timestamp
3939 META_SERIALIZED = 'serialized ' , // is content serialized?
@@ -205,8 +205,8 @@ public function write(string $key, $data, array $dp): void
205205 $ meta [self ::META_SERIALIZED ] = true ;
206206 }
207207
208- $ head = serialize ($ meta ) . ' ?> ' ;
209- $ head = ' <?php //netteCache[01] ' . str_pad ((string ) strlen ($ head ), 6 , '0 ' , STR_PAD_LEFT ) . $ head ;
208+ $ head = serialize ($ meta );
209+ $ head = str_pad ((string ) strlen ($ head ), 6 , '0 ' , STR_PAD_LEFT ) . $ head ;
210210 $ headLen = strlen ($ head );
211211
212212 do {
@@ -321,9 +321,9 @@ protected function readMetaAndLock(string $file, int $lock): ?array
321321
322322 flock ($ handle , $ lock );
323323
324- $ head = stream_get_contents ($ handle , self ::META_HEADER_LEN );
325- if ($ head && strlen ($ head ) === self ::META_HEADER_LEN ) {
326- $ size = (int ) substr ( $ head , - 6 ) ;
324+ $ size = stream_get_contents ($ handle , self ::META_HEADER_LEN );
325+ if ($ size && strlen ($ size ) === self ::META_HEADER_LEN ) {
326+ $ size = (int ) $ size ;
327327 $ meta = stream_get_contents ($ handle , $ size , self ::META_HEADER_LEN );
328328 $ meta = unserialize ($ meta );
329329 $ meta [self ::FILE ] = $ file ;
0 commit comments