mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding better file locking in write(). This should reduce issues
with file locking and unserialize(). Fixes #1660
This commit is contained in:
parent
b5a533b287
commit
ea7c8c4710
1 changed files with 16 additions and 5 deletions
21
cake/libs/cache/file.php
vendored
21
cake/libs/cache/file.php
vendored
|
@ -136,13 +136,24 @@ class FileEngine extends CacheEngine {
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->settings['lock']) {
|
||||
$this->_File->lock = true;
|
||||
}
|
||||
$expires = time() + $duration;
|
||||
$contents = $expires . $lineBreak . $data . $lineBreak;
|
||||
$success = $this->_File->write($contents);
|
||||
$this->_File->close();
|
||||
|
||||
if (!$handle = fopen($this->_File->path, 'c')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->settings['lock']) {
|
||||
flock($handle, LOCK_EX);
|
||||
}
|
||||
|
||||
$success = ftruncate($handle, 0) && fwrite($handle, $contents) && fflush($handle);
|
||||
|
||||
if ($this->settings['lock']) {
|
||||
flock($handle, LOCK_UN);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
return $success;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue