Skip to content

Commit

Permalink
Merge pull request #4752 from zero-24/patch-3
Browse files Browse the repository at this point in the history
Fix: PHP undefined notice in caching file storage
  • Loading branch information
wilsonge committed Jun 17, 2015
2 parents 0141332 + 9d44712 commit 92ca4ad
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions libraries/joomla/cache/storage/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function __construct($options = array())
public function get($id, $group, $checkTime = true)
{
$data = false;

$path = $this->_getFilePath($id, $group);

if ($checkTime == false || ($checkTime == true && $this->_checkExpire($id, $group) === true))
Expand Down Expand Up @@ -88,14 +87,14 @@ public function getAll()
{
parent::getAll();

$path = $this->_root;
$path = $this->_root;
$folders = $this->_folders($path);
$data = array();
$data = array();

foreach ($folders as $folder)
{
$files = $this->_filesInFolder($path . '/' . $folder);
$item = new JCacheStorageHelper($folder);
$item = new JCacheStorageHelper($folder);

foreach ($files as $file)
{
Expand All @@ -122,8 +121,8 @@ public function getAll()
public function store($id, $group, $data)
{
$written = false;
$path = $this->_getFilePath($id, $group);
$die = '<?php die("Access Denied"); ?>#x#';
$path = $this->_getFilePath($id, $group);
$die = '<?php die("Access Denied"); ?>#x#';

// Prepend a die string
$data = $die . $data;
Expand Down Expand Up @@ -194,7 +193,7 @@ public function clean($group, $mode = null)

switch ($mode)
{
case 'notgroup':
case 'notgroup' :
$folders = $this->_folders($this->_root);

for ($i = 0, $n = count($folders); $i < $n; $i++)
Expand All @@ -205,8 +204,8 @@ public function clean($group, $mode = null)
}
}
break;
case 'group':
default:
case 'group' :
default :
if (is_dir($this->_root . '/' . $folder))
{
$return = $this->_deleteFolder($this->_root . '/' . $folder);
Expand Down Expand Up @@ -274,9 +273,8 @@ public function lock($id, $group, $locktime)
$returning = new stdClass;
$returning->locklooped = false;

$looptime = $locktime * 10;
$path = $this->_getFilePath($id, $group);

$looptime = $locktime * 10;
$path = $this->_getFilePath($id, $group);
$_fileopen = @fopen($path, "r+b");

if ($_fileopen)
Expand All @@ -298,7 +296,7 @@ public function lock($id, $group, $locktime)
{
if ($lock_counter > $looptime)
{
$returning->locked = false;
$returning->locked = false;
$returning->locklooped = true;
break;
}
Expand Down Expand Up @@ -326,15 +324,19 @@ public function lock($id, $group, $locktime)
*/
public function unlock($id, $group = null)
{
$path = $this->_getFilePath($id, $group);

$path = $this->_getFilePath($id, $group);
$_fileopen = @fopen($path, "r+b");

if ($_fileopen)
{
$ret = @flock($_fileopen, LOCK_UN);
@fclose($_fileopen);
}
else
{
// Expect true if $_fileopen is false. Ref: http://issues.joomla.org/tracker/joomla-cms/2535
$ret = true;
}

return $ret;
}
Expand Down Expand Up @@ -384,14 +386,14 @@ protected function _checkExpire($id, $group)
protected function _getFilePath($id, $group)
{
$name = $this->_getCacheId($id, $group);
$dir = $this->_root . '/' . $group;
$dir = $this->_root . '/' . $group;

// If the folder doesn't exist try to create it
if (!is_dir($dir))
{
// Make sure the index file is there
$indexFile = $dir . '/index.html';
@ mkdir($dir) && file_put_contents($indexFile, '<!DOCTYPE html><title></title>');
@mkdir($dir) && file_put_contents($indexFile, '<!DOCTYPE html><title></title>');
}

// Make sure the folder exists
Expand Down Expand Up @@ -495,6 +497,7 @@ protected function _deleteFolder($path)
else
{
JLog::add('JCacheStorageFile::_deleteFolder' . JText::sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_DELETE', $path), JLog::WARNING, 'jerror');

$ret = false;
}

Expand Down Expand Up @@ -579,7 +582,7 @@ protected function _filesInFolder($path, $filter = '.', $recurse = false, $fullp
{
if (($file != '.') && ($file != '..') && (!in_array($file, $exclude)) && (!$excludefilter || !preg_match($excludefilter, $file)))
{
$dir = $path . '/' . $file;
$dir = $path . '/' . $file;
$isDir = is_dir($dir);

if ($isDir)
Expand Down Expand Up @@ -671,7 +674,7 @@ protected function _folders($path, $filter = '.', $recurse = false, $fullpath =
&& (!in_array($file, $exclude))
&& (empty($excludefilter_string) || !preg_match($excludefilter_string, $file)))
{
$dir = $path . '/' . $file;
$dir = $path . '/' . $file;
$isDir = is_dir($dir);

if ($isDir)
Expand Down

0 comments on commit 92ca4ad

Please sign in to comment.