From ba56fb706447320df23958a4217a028efdeff28c Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 13 Apr 2013 19:45:20 +0530 Subject: [PATCH] Fixed issue where incorrect cached filesize was reported when appending to file. --- lib/Cake/Test/Case/Utility/FileTest.php | 10 +++++++++- lib/Cake/Utility/File.php | 7 +++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/FileTest.php b/lib/Cake/Test/Case/Utility/FileTest.php index 998e0c21f..3b3bf0db9 100644 --- a/lib/Cake/Test/Case/Utility/FileTest.php +++ b/lib/Cake/Test/Case/Utility/FileTest.php @@ -433,16 +433,24 @@ class FileTest extends CakeTestCase { $TmpFile = new File($tmpFile); $this->assertFalse(file_exists($tmpFile)); - $fragments = array('CakePHP\'s', ' test suite', ' was here ...', ''); + $fragments = array('CakePHP\'s', ' test suite', ' was here ...'); $data = null; + $size = 0; foreach ($fragments as $fragment) { $r = $TmpFile->append($fragment); $this->assertTrue($r); $this->assertTrue(file_exists($tmpFile)); $data = $data . $fragment; $this->assertEquals($data, file_get_contents($tmpFile)); + $newSize = $TmpFile->size(); + $this->assertTrue($newSize > $size); + $size = $newSize; $TmpFile->close(); } + + $TmpFile->append(''); + $this->assertEquals($data, file_get_contents($tmpFile)); + $TmpFile->close(); } /** diff --git a/lib/Cake/Utility/File.php b/lib/Cake/Utility/File.php index 78635d39b..a64f47335 100644 --- a/lib/Cake/Utility/File.php +++ b/lib/Cake/Utility/File.php @@ -130,7 +130,6 @@ class File { if (!$force && is_resource($this->handle)) { return true; } - clearstatcache(); if ($this->exists() === false) { if ($this->create() === false) { return false; @@ -278,7 +277,6 @@ class File { * @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; @@ -410,6 +408,11 @@ class File { * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::exists */ public function exists() { + if (version_compare(PHP_VERSION, '5.3.0') >= 0) { + clearstatcache(true, $this->path); + } else { + clearstatcache(); + } return (file_exists($this->path) && is_file($this->path)); }