Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove empty locked cache file if callback function terminate process (
…joomla#15592)

* Remove empty locked cache file if callback function terminate process

* Add comments and @
  • Loading branch information
csthomas authored and rdeutz committed May 1, 2017
1 parent 9232f57 commit f904610
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions libraries/joomla/cache/storage/file.php
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f904610

Please sign in to comment.