Skip to content

Commit

Permalink
Implementing a way to set permissions in CopyDir.
Browse files Browse the repository at this point in the history
The default value for new folders is 0777. This can be changed by calling chmod().
  • Loading branch information
Florian Krämer committed Mar 12, 2015
1 parent a3e75bb commit d198e20
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/Task/FileSystem/CopyDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
class CopyDir extends BaseDir
{
/** @var int $chmod */
protected $chmod = 0755;

public function run()
{
foreach ($this->dirs as $src => $dst) {
Expand All @@ -26,14 +29,37 @@ 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);
if (false === $dir) {
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 !== '..')) {
Expand Down

0 comments on commit d198e20

Please sign in to comment.