"Fixing segmentation fault if the TMP/* directories are not writable.

Corrected CakeLog::write() so it will only attempt to write the log file is LOGS directory is writable "

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6094 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-11-28 09:20:48 +00:00
parent ae8ccbd817
commit a09167a8a6
2 changed files with 39 additions and 9 deletions

View file

@ -59,6 +59,20 @@ class FileEngine extends CacheEngine {
* @access public
*/
var $settings = array();
/**
* Set to true if FileEngine::init(); and FileEngine::__active(); do not fail.
*
* @var boolean
* @access private
*/
var $__active = false;
/**
* True unless FileEngine::__active(); fails
*
* @var boolean
* @access private
*/
var $__init = true;
/**
* Initialize the Cache Engine
*
@ -80,11 +94,7 @@ class FileEngine extends CacheEngine {
if(empty($this->settings['path'])) {
return false;
}
if (!is_writable($this->settings['path'])) {
trigger_error(sprintf(__('%s is not writable', true), $this->settings['path']), E_USER_WARNING);
return false;
}
return true;
return $this->__active();
}
/**
* Garbage collection. Permanently remove all expired and deleted data
@ -105,7 +115,7 @@ class FileEngine extends CacheEngine {
* @access public
*/
function write($key, &$data, $duration) {
if (empty($data)) {
if (empty($data) || !$this->__init) {
return false;
}
@ -140,7 +150,7 @@ class FileEngine extends CacheEngine {
* @access public
*/
function read($key) {
if($this->__setKey($key) === false) {
if($this->__setKey($key) === false || !$this->__init) {
return false;
}
if ($this->settings['lock']) {
@ -168,7 +178,7 @@ class FileEngine extends CacheEngine {
* @access public
*/
function delete($key) {
if($this->__setKey($key) === false) {
if($this->__setKey($key) === false || !$this->__init) {
return false;
}
return $this->__File->delete();
@ -181,6 +191,9 @@ class FileEngine extends CacheEngine {
* @access public
*/
function clear($check) {
if (!$this->__init) {
return false;
}
$dir = dir($this->settings['path']);
if ($check) {
$now = time();
@ -223,5 +236,20 @@ class FileEngine extends CacheEngine {
return false;
}
}
/**
* Determine is cache directory is writable
*
* @return boolean
* @access private
*/
function __active() {
if (!$this->__active && $this->__init && !is_writable($this->settings['path'])) {
$this->__init = false;
trigger_error(sprintf(__('%s is not writable', true), $this->settings['path']), E_USER_WARNING);
} else {
$this->__active = true;
}
return true;
}
}
?>

View file

@ -91,7 +91,9 @@ class CakeLog {
}
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $msg . "\n";
$log = new File($filename);
return $log->append($output);
if ($log->writable()) {
return $log->append($output);
}
}
}
?>