improved control over and handling of file and dir permissions

- rename FileHelper::mkdir for API consistency
- changed default permission for directories to 775 instead of 777
- added some properties to classes that deal with files to allow control
  over directory permissions.
This commit is contained in:
Carsten Brandt
2013-08-30 16:52:33 +02:00
parent fa07d31310
commit 4b7f5a728a
6 changed files with 74 additions and 21 deletions

View File

@@ -9,6 +9,7 @@ namespace yii\log;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\FileHelper;
/**
* FileTarget records log messages in a file.
@@ -37,6 +38,19 @@ class FileTarget extends Target
* @var integer number of log files used for rotation. Defaults to 5.
*/
public $maxLogFiles = 5;
/**
* @var integer the permission to be set for newly created log files.
* This value will be used by PHP chmod() function. No umask will be applied.
* If not set, the permission will be determined by the current environment.
*/
public $fileMode;
/**
* @var integer the permission to be set for newly created directories.
* This value will be used by PHP chmod() function. No umask will be applied.
* Defaults to 0775, meaning the directory is read-writable by owner and group,
* but read-only for other users.
*/
public $dirMode = 0775;
/**
@@ -53,7 +67,7 @@ class FileTarget extends Target
}
$logPath = dirname($this->logFile);
if (!is_dir($logPath)) {
@mkdir($logPath, 0777, true);
FileHelper::createDirectory($logPath, $this->dirMode, true);
}
if ($this->maxLogFiles < 1) {
$this->maxLogFiles = 1;
@@ -87,6 +101,9 @@ class FileTarget extends Target
@flock($fp, LOCK_UN);
@fclose($fp);
}
if ($this->fileMode !== null) {
@chmod($this->logFile, $this->fileMode);
}
}
/**