From f9046105b8f19b6defc669c1bc28b0b3bad7642b Mon Sep 17 00:00:00 2001 From: Tomasz Narloch Date: Fri, 28 Apr 2017 22:05:10 +0200 Subject: [PATCH] Remove empty locked cache file if callback function terminate process (#15592) * Remove empty locked cache file if callback function terminate process * Add comments and @ --- libraries/joomla/cache/storage/file.php | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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; }