From d198e20a83e3414753fd8497cd27a917bd5faa2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Thu, 12 Mar 2015 23:35:44 +0100 Subject: [PATCH] Implementing a way to set permissions in CopyDir. The default value for new folders is 0777. This can be changed by calling chmod(). --- src/Task/FileSystem/CopyDir.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Task/FileSystem/CopyDir.php b/src/Task/FileSystem/CopyDir.php index f5817e4e4..df38f1612 100644 --- a/src/Task/FileSystem/CopyDir.php +++ b/src/Task/FileSystem/CopyDir.php @@ -17,6 +17,9 @@ */ class CopyDir extends BaseDir { + /** @var int $chmod */ + protected $chmod = 0755; + public function run() { foreach ($this->dirs as $src => $dst) { @@ -26,6 +29,29 @@ public function run() return Result::success($this); } + /** + * Sets the default folder permissions for the destination if it doesn't exist + * + * @link http://en.wikipedia.org/wiki/Chmod + * @link http://php.net/manual/en/function.mkdir.php + * @link http://php.net/manual/en/function.chmod.php + * @param int $value + * @return $this + */ + public function chmod($value) + { + $this->chmod = (int)$value; + return $this; + } + + /** + * Copies a directory to another location. + * + * @param string $src Source directory + * @param string $dst Destination directory + * @throws \Robo\Exception\TaskException + * @return void + */ protected function copyDir($src, $dst) { $dir = @opendir($src); @@ -33,7 +59,7 @@ protected function copyDir($src, $dst) throw new TaskException($this, "Cannot open source directory '" . $src . "'"); } if (!is_dir($dst)) { - mkdir($dst, 0777, true); + mkdir($dst, $this->chmod, true); } while (false !== ($file = readdir($dir))) { if (($file !== '.') && ($file !== '..')) {