Skip to content

Commit

Permalink
Expect true if $_fileopen is false.
Browse files Browse the repository at this point in the history
see: http://issues.joomla.org/tracker/joomla-cms/2535

#### Steps to reproduce the issue
1. configure caching to be file based in configuration.php
2. use callback as handler 
3. lock the id
4. remove the cache file 
5. unlock the id now   

#### Expected result
If the cache file has beem removed, the unlock should just return true. 



#### Actual result
Get php undefined variable notice: 
Notice: Undefined variable: ret in web/libraries/joomla/cache/storage/file.php on line <i>333</i>


#### System information (as much as possible)
Linux, Joomla 3.2 latest.
  • Loading branch information
zero-24 committed Oct 17, 2014
1 parent 275bbe7 commit 6b89041
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions libraries/joomla/cache/storage/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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 @@ -90,14 +89,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 @@ -124,8 +123,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 @@ -196,7 +195,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 @@ -207,8 +206,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 @@ -277,7 +276,7 @@ public function lock($id, $group, $locktime)
$returning->locklooped = false;

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

$_fileopen = @fopen($path, "r+b");

Expand All @@ -300,7 +299,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 @@ -337,6 +336,11 @@ public function unlock($id, $group = null)
$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 @@ -386,14 +390,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 @@ -497,6 +501,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 @@ -581,7 +586,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 @@ -673,7 +678,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 6b89041

Please sign in to comment.