Skip to content

Commit

Permalink
Moved stat cache clearing into a method for consitent usage.
Browse files Browse the repository at this point in the history
Fixes issue where incorrect cached filesize was reported when appending to file.
Thanks dogmatic69 for the patch.
  • Loading branch information
dogmatic69 authored and ADmad committed Apr 11, 2013
1 parent 5c83bc1 commit 7b0e5d9
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/Cake/Utility/File.php
Expand Up @@ -130,7 +130,6 @@ public function open($mode = 'r', $force = false) {
if (!$force && is_resource($this->handle)) {
return true;
}
clearstatcache();
if ($this->exists() === false) {
if ($this->create() === false) {
return false;
Expand Down Expand Up @@ -278,7 +277,6 @@ public function close() {
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::delete
*/
public function delete() {
clearstatcache();
if (is_resource($this->handle)) {
fclose($this->handle);
$this->handle = null;
Expand Down Expand Up @@ -410,6 +408,7 @@ public function pwd() {
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::exists
*/
public function exists() {
$this->clearStatCache();
return (file_exists($this->path) && is_file($this->path));
}

Expand Down Expand Up @@ -566,4 +565,21 @@ public function mime() {
return false;
}

/**
* Clear PHP's internal stat cache
*
* For 5.3 onwards its possible to clear cache for just a single file. Passing true
* will clear all the stat cache.
*
* @param boolean $all Clear all cache or not
* @return void
*/
public function clearStatCache($all = false) {
if ($all === false && version_compare(PHP_VERSION, '5.3.0') >= 0) {
return clearstatcache(true, $this->path);
}

return clearstatcache();
}

}

0 comments on commit 7b0e5d9

Please sign in to comment.