Merge branch 'MDL-41291-master' of git://github.com/mr-russ/moodle
authorDan Poltawski <dan@moodle.com>
Mon, 26 Aug 2013 09:50:08 +0000 (17:50 +0800)
committerDan Poltawski <dan@moodle.com>
Mon, 26 Aug 2013 09:50:08 +0000 (17:50 +0800)
1  2 
cache/stores/file/lib.php

@@@ -336,7 -336,6 +336,7 @@@ class cachestore_file extends cache_sto
          $filename = $key.'.cache';
          $file = $this->file_path_for_key($key);
          $ttl = $this->definition->get_ttl();
 +        $maxtime = 0;
          if ($ttl) {
              $maxtime = cache::now() - $ttl;
          }
          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.