X-Git-Url: http://git.moodle.org/gw?p=moodle.git;a=blobdiff_plain;f=cache%2Fstores%2Ffile%2Flib.php;fp=cache%2Fstores%2Ffile%2Flib.php;h=514a4bd4fb6d6b5083e6ccc21856c4e4b2be0b10;hp=4830d71765d38b928b62eed7f4f5efc035f600d1;hb=51eba172e68b14bfa0fbc7ba39eec62d8092b2c9;hpb=a0df83441b62bf246e4f84d7ce5582e0a82588ff diff --git a/cache/stores/file/lib.php b/cache/stores/file/lib.php index 4830d71765d..514a4bd4fb6 100644 --- a/cache/stores/file/lib.php +++ b/cache/stores/file/lib.php @@ -353,23 +353,19 @@ class cachestore_file extends cache_store implements cache_is_key_aware, cache_i if (!$readfile) { return false; } - // Check the filesize first, likely not needed but important none the less. - $filesize = filesize($file); - if (!$filesize) { - return false; - } - // Open ensuring the file for writing, truncating it and setting the pointer to the start. + // Open ensuring the file for reading in binary format. if (!$handle = fopen($file, 'rb')) { return false; } // Lock it up! // We don't care if this succeeds or not, on some systems it will, on some it won't, meah either way. flock($handle, LOCK_SH); - // HACK ALERT - // There is a problem when reading from the file during PHPUNIT tests. For one reason or another the filesize is not correct - // Doesn't happen during normal operation, just during unit tests. - // Read it. - $data = fread($handle, $filesize+128); + $data = ''; + // Read the data in 1Mb chunks. Small caches will not loop more than once. We don't use filesize as it may + // be cached with a different value than what we need to read from the file. + do { + $data .= fread($handle, 1048576); + } while (!feof($handle)); // Unlock it. flock($handle, LOCK_UN); // Return it unserialised.