From a09167a8a63bb9de00e77eb64c7659a688b8b050 Mon Sep 17 00:00:00 2001 From: phpnut Date: Wed, 28 Nov 2007 09:20:48 +0000 Subject: [PATCH] "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 --- cake/libs/cache/file.php | 44 ++++++++++++++++++++++++++++++++-------- cake/libs/cake_log.php | 4 +++- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/cake/libs/cache/file.php b/cake/libs/cache/file.php index e96c6471d..ac1c93293 100644 --- a/cake/libs/cache/file.php +++ b/cake/libs/cache/file.php @@ -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; + } } ?> \ No newline at end of file diff --git a/cake/libs/cake_log.php b/cake/libs/cake_log.php index 65f6cb05d..f6bae5938 100644 --- a/cake/libs/cake_log.php +++ b/cake/libs/cake_log.php @@ -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); + } } } ?> \ No newline at end of file