diff --git a/libraries/joomla/cache/storage/file.php b/libraries/joomla/cache/storage/file.php index f2dba86e5f9ab..0c849755f868f 100644 --- a/libraries/joomla/cache/storage/file.php +++ b/libraries/joomla/cache/storage/file.php @@ -45,6 +45,32 @@ public function __construct($options = array()) { parent::__construct($options); $this->_root = $options['cachebase']; + + // Workaround for php 5.3 + $locked_files = &$this->_locked_files; + + // Remove empty locked files at script shutdown. + $clearAtShutdown = function () use (&$locked_files) + { + foreach ($locked_files as $path => $handle) + { + if (is_resource($handle)) + { + @flock($handle, LOCK_UN); + @fclose($handle); + } + + // Delete only the existing file if it is empty. + if (@filesize($path) === 0) + { + @unlink($path); + } + + unset($locked_files[$path]); + } + }; + + register_shutdown_function($clearAtShutdown); } /** @@ -420,6 +446,12 @@ protected function _checkExpire($id, $group) return false; } + // If now the file does not exist then return false too. + if (@filesize($path) == 0) + { + return false; + } + return true; }