mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Merge pull request #1226 from ADmad/2.3-file-clearstatcache
Fixed issue where incorrect cached filesize was reported when appending ...
This commit is contained in:
commit
672dd6178f
2 changed files with 14 additions and 3 deletions
|
@ -433,16 +433,24 @@ class FileTest extends CakeTestCase {
|
||||||
$TmpFile = new File($tmpFile);
|
$TmpFile = new File($tmpFile);
|
||||||
$this->assertFalse(file_exists($tmpFile));
|
$this->assertFalse(file_exists($tmpFile));
|
||||||
|
|
||||||
$fragments = array('CakePHP\'s', ' test suite', ' was here ...', '');
|
$fragments = array('CakePHP\'s', ' test suite', ' was here ...');
|
||||||
$data = null;
|
$data = null;
|
||||||
|
$size = 0;
|
||||||
foreach ($fragments as $fragment) {
|
foreach ($fragments as $fragment) {
|
||||||
$r = $TmpFile->append($fragment);
|
$r = $TmpFile->append($fragment);
|
||||||
$this->assertTrue($r);
|
$this->assertTrue($r);
|
||||||
$this->assertTrue(file_exists($tmpFile));
|
$this->assertTrue(file_exists($tmpFile));
|
||||||
$data = $data . $fragment;
|
$data = $data . $fragment;
|
||||||
$this->assertEquals($data, file_get_contents($tmpFile));
|
$this->assertEquals($data, file_get_contents($tmpFile));
|
||||||
|
$newSize = $TmpFile->size();
|
||||||
|
$this->assertTrue($newSize > $size);
|
||||||
|
$size = $newSize;
|
||||||
$TmpFile->close();
|
$TmpFile->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$TmpFile->append('');
|
||||||
|
$this->assertEquals($data, file_get_contents($tmpFile));
|
||||||
|
$TmpFile->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -130,7 +130,6 @@ class File {
|
||||||
if (!$force && is_resource($this->handle)) {
|
if (!$force && is_resource($this->handle)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
clearstatcache();
|
|
||||||
if ($this->exists() === false) {
|
if ($this->exists() === false) {
|
||||||
if ($this->create() === false) {
|
if ($this->create() === false) {
|
||||||
return 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
|
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::delete
|
||||||
*/
|
*/
|
||||||
public function delete() {
|
public function delete() {
|
||||||
clearstatcache();
|
|
||||||
if (is_resource($this->handle)) {
|
if (is_resource($this->handle)) {
|
||||||
fclose($this->handle);
|
fclose($this->handle);
|
||||||
$this->handle = null;
|
$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
|
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::exists
|
||||||
*/
|
*/
|
||||||
public function 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));
|
return (file_exists($this->path) && is_file($this->path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue