From 046b95b8a2b22c9c7830d0825eeeebb7c13e5eb0 Mon Sep 17 00:00:00 2001 From: Peter Gasser Date: Sat, 28 Feb 2015 02:04:49 +0100 Subject: [PATCH 1/9] add cli/CopyDirRecursiveCept --- tests/_data/claypit/some/deeply/existing_file | 1 + tests/_data/claypit/some/deeply/nested/structu.re | 1 + .../claypit/some_destination/deeply/existing_file | 1 + tests/cli/CopyDirRecursiveCept.php | 10 ++++++++++ 4 files changed, 13 insertions(+) create mode 100644 tests/_data/claypit/some/deeply/existing_file create mode 100644 tests/_data/claypit/some/deeply/nested/structu.re create mode 100644 tests/_data/claypit/some_destination/deeply/existing_file create mode 100644 tests/cli/CopyDirRecursiveCept.php diff --git a/tests/_data/claypit/some/deeply/existing_file b/tests/_data/claypit/some/deeply/existing_file new file mode 100644 index 000000000..37cfa2826 --- /dev/null +++ b/tests/_data/claypit/some/deeply/existing_file @@ -0,0 +1 @@ +some existing file diff --git a/tests/_data/claypit/some/deeply/nested/structu.re b/tests/_data/claypit/some/deeply/nested/structu.re new file mode 100644 index 000000000..98a202cbc --- /dev/null +++ b/tests/_data/claypit/some/deeply/nested/structu.re @@ -0,0 +1 @@ +Just a file diff --git a/tests/_data/claypit/some_destination/deeply/existing_file b/tests/_data/claypit/some_destination/deeply/existing_file new file mode 100644 index 000000000..1765b73ba --- /dev/null +++ b/tests/_data/claypit/some_destination/deeply/existing_file @@ -0,0 +1 @@ +some_destination existing file diff --git a/tests/cli/CopyDirRecursiveCept.php b/tests/cli/CopyDirRecursiveCept.php new file mode 100644 index 000000000..7ca8e4fd1 --- /dev/null +++ b/tests/cli/CopyDirRecursiveCept.php @@ -0,0 +1,10 @@ +wantTo('copy dir recursively with CopyDir task'); +$I->amInPath(codecept_data_dir() . 'sandbox'); +$I->seeDirFound('some/deeply/nested'); +$I->seeFileFound('structu.re', 'some/deeply/nested'); +$I->taskCopyDir(['some/deeply' => 'some_destination/deeply']) + ->run(); +$I->seeDirFound('some_destination/deeply/nested'); +$I->seeFileFound('structu.re', 'some_destination/deeply/nested'); From 2b70f13ed21b3c646d001d01a2e0b7b2c2e52386 Mon Sep 17 00:00:00 2001 From: Peter Gasser Date: Sat, 28 Feb 2015 02:06:26 +0100 Subject: [PATCH 2/9] add cli/CopyDirOverwritesFilesCept --- tests/cli/CopyDirOverwritesFilesCept.php | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/cli/CopyDirOverwritesFilesCept.php diff --git a/tests/cli/CopyDirOverwritesFilesCept.php b/tests/cli/CopyDirOverwritesFilesCept.php new file mode 100644 index 000000000..133d6e7f8 --- /dev/null +++ b/tests/cli/CopyDirOverwritesFilesCept.php @@ -0,0 +1,11 @@ +wantTo('overwrite a file with CopyDir task'); +$I->amInPath(codecept_data_dir() . 'sandbox'); +$I->seeDirFound('some'); +$I->seeFileFound('existing_file', 'some'); +$I->taskCopyDir(['some' => 'some_destination']) + ->run(); +$I->seeFileFound('existing_file', 'some_destination/deeply'); +$I->openFile('some_destination/deeply/existing_file'); +$I->seeInThisFile('some existing file'); From 41632785e2561673e4e146660d81ec83ec15fb9c Mon Sep 17 00:00:00 2001 From: Peter Gasser Date: Sat, 28 Feb 2015 02:06:45 +0100 Subject: [PATCH 3/9] build CliGuy --- tests/cli/CliGuy.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/cli/CliGuy.php b/tests/cli/CliGuy.php index 206ffa51b..c45bf69d6 100644 --- a/tests/cli/CliGuy.php +++ b/tests/cli/CliGuy.php @@ -748,7 +748,7 @@ public function taskConcat($files) { * [!] Method is generated. Documentation taken from corresponding module. * * @param $file - * @return ReplaceInFile + * @return Replace * @see \Codeception\Module\CliHelper::taskReplaceInFile() */ public function taskReplaceInFile($file) { @@ -760,7 +760,7 @@ public function taskReplaceInFile($file) { * [!] Method is generated. Documentation taken from corresponding module. * * @param $file - * @return WriteToFile + * @return Write * @see \Codeception\Module\CliHelper::taskWriteToFile() */ public function taskWriteToFile($file) { @@ -807,7 +807,7 @@ public function taskCopyDir($dirs) { /** * [!] Method is generated. Documentation taken from corresponding module. * - * @return Filesystem + * @return FilesystemStack * @see \Codeception\Module\CliHelper::taskFilesystemStack() */ public function taskFilesystemStack() { From 4bcc7ec5eee51bc36250fed0e496a9abce111b61 Mon Sep 17 00:00:00 2001 From: Peter Gasser Date: Sat, 28 Feb 2015 02:07:59 +0100 Subject: [PATCH 4/9] CopyDir: check for destination (remove @-operator) --- src/Task/FileSystem/CopyDir.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Task/FileSystem/CopyDir.php b/src/Task/FileSystem/CopyDir.php index 45f31993f..f68976977 100644 --- a/src/Task/FileSystem/CopyDir.php +++ b/src/Task/FileSystem/CopyDir.php @@ -32,7 +32,9 @@ protected function copyDir($src, $dst) if (false === $dir) { throw new TaskException($this, "Cannot open source directory '" . $src . "'"); } - @mkdir($dst); + if (!is_dir($dst)) { + mkdir($dst); + } while (false !== ($file = readdir($dir))) { if (($file !== '.') && ($file !== '..')) { $srcFile = $src . '/' . $file; From a3e75bbadfaefc78d0b86b91f5d7312ea5a26851 Mon Sep 17 00:00:00 2001 From: Peter Gasser Date: Sat, 28 Feb 2015 02:09:49 +0100 Subject: [PATCH 5/9] CopyDir: create destination recursively --- src/Task/FileSystem/CopyDir.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Task/FileSystem/CopyDir.php b/src/Task/FileSystem/CopyDir.php index f68976977..f5817e4e4 100644 --- a/src/Task/FileSystem/CopyDir.php +++ b/src/Task/FileSystem/CopyDir.php @@ -33,7 +33,7 @@ protected function copyDir($src, $dst) throw new TaskException($this, "Cannot open source directory '" . $src . "'"); } if (!is_dir($dst)) { - mkdir($dst); + mkdir($dst, 0777, true); } while (false !== ($file = readdir($dir))) { if (($file !== '.') && ($file !== '..')) { 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 6/9] 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 !== '..')) { From 883146e35b3e47932b50284c39d8d491288c1033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Thu, 12 Mar 2015 23:38:44 +0100 Subject: [PATCH 7/9] Adding an accidentally removed line back and setting chmod there as well. --- src/Task/FileSystem/CopyDir.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Task/FileSystem/CopyDir.php b/src/Task/FileSystem/CopyDir.php index df38f1612..991d41703 100644 --- a/src/Task/FileSystem/CopyDir.php +++ b/src/Task/FileSystem/CopyDir.php @@ -58,6 +58,7 @@ protected function copyDir($src, $dst) if (false === $dir) { throw new TaskException($this, "Cannot open source directory '" . $src . "'"); } + @mkdir($dst, $this->chmod); if (!is_dir($dst)) { mkdir($dst, $this->chmod, true); } From 6fa55a05a643cc341036dadf6ad745695505daf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Sun, 15 Mar 2015 23:15:39 +0100 Subject: [PATCH 8/9] Removing the line that caused the initial error in CopyDir.php --- src/Task/FileSystem/CopyDir.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Task/FileSystem/CopyDir.php b/src/Task/FileSystem/CopyDir.php index 991d41703..df38f1612 100644 --- a/src/Task/FileSystem/CopyDir.php +++ b/src/Task/FileSystem/CopyDir.php @@ -58,7 +58,6 @@ protected function copyDir($src, $dst) if (false === $dir) { throw new TaskException($this, "Cannot open source directory '" . $src . "'"); } - @mkdir($dst, $this->chmod); if (!is_dir($dst)) { mkdir($dst, $this->chmod, true); } From 3a8b232bc598cca37d29cf8e22b2bf3c87ce0cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Sun, 15 Mar 2015 23:26:07 +0100 Subject: [PATCH 9/9] Changing the method name from chmod() to dirPermissions() in CopyDir. --- src/Task/FileSystem/CopyDir.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Task/FileSystem/CopyDir.php b/src/Task/FileSystem/CopyDir.php index df38f1612..8a4be564a 100644 --- a/src/Task/FileSystem/CopyDir.php +++ b/src/Task/FileSystem/CopyDir.php @@ -38,7 +38,7 @@ public function run() * @param int $value * @return $this */ - public function chmod($value) + public function dirPermissions($value) { $this->chmod = (int)$value; return $this;