mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Moved stat cache clearing into a method for consitent usage.
Fixes issue where incorrect cached filesize was reported when appending to file. Thanks dogmatic69 for the patch.
This commit is contained in:
parent
5c83bc177d
commit
7b0e5d9375
1 changed files with 18 additions and 2 deletions
|
@ -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,7 @@ 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() {
|
||||||
|
$this->clearStatCache();
|
||||||
return (file_exists($this->path) && is_file($this->path));
|
return (file_exists($this->path) && is_file($this->path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,4 +565,21 @@ class File {
|
||||||
return false;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue