From 65a5fa5494dbd18249d9ff46e2b9fbb75cf30ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Kri=C5=A1ka?= Date: Thu, 8 Aug 2013 13:36:57 +0200 Subject: [PATCH] added options to set mode (used by mkdir and chmod) for cache directory and files --- framework/caching/CFileCache.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/framework/caching/CFileCache.php b/framework/caching/CFileCache.php index 33a8abdb3..6562927f4 100644 --- a/framework/caching/CFileCache.php +++ b/framework/caching/CFileCache.php @@ -30,10 +30,24 @@ class CFileCache extends CCache * using 'protected/runtime/cache' as the directory. */ public $cachePath; + /** + * @var integer the permission to be set for directory to store cache files + * This value will be used by PHP chmod function. + * Defaults to 0777, meaning the directory can be read, written and executed by all users. + * @since 1.1.15 + */ + public $cachePathMode=0777; /** * @var string cache file suffix. Defaults to '.bin'. */ public $cacheFileSuffix='.bin'; + /** + * @var integer the permission to be set for new cache files. + * This value will be used by PHP chmod function. + * Defaults to 0666, meaning the file is read-writable by all users. + * @since 1.1.15 + */ + public $cacheFileMode=0666; /** * @var integer the level of sub-directories to store cache files. Defaults to 0, * meaning no sub-directories. If the system has huge number of cache files (e.g. 10K+), @@ -65,8 +79,8 @@ class CFileCache extends CCache $this->cachePath=Yii::app()->getRuntimePath().DIRECTORY_SEPARATOR.'cache'; if(!is_dir($this->cachePath)) { - mkdir($this->cachePath,0777,true); - chmod($this->cachePath,0777); + mkdir($this->cachePath,$this->cachePathMode,true); + chmod($this->cachePath,$this->cachePathMode); } } @@ -145,10 +159,14 @@ class CFileCache extends CCache $cacheFile=$this->getCacheFile($key); if($this->directoryLevel>0) - @mkdir(dirname($cacheFile),0777,true); + { + $cacheDir = dirname($cacheFile); + @mkdir($cacheDir,$this->cachePathMode,true); + @chmod($cacheDir,$this->cachePathMode); + } if(@file_put_contents($cacheFile,$this->embedExpiry ? $expire.$value : $value,LOCK_EX)!==false) { - @chmod($cacheFile,0777); + @chmod($cacheFile,$this->cacheFileMode); return $this->embedExpiry ? true : @touch($cacheFile,$expire); } else