Skip to content
Permalink
Browse files

added recursive option to copy to turn off it needed

  • Loading branch information...
daniel-lang committed May 12, 2015
1 parent f10d283 commit b970a0ec46b6f3fbc5ba19f74cc058212fdf3717
Showing with 27 additions and 2 deletions.
  1. +9 −2 src/Filesystem/Folder.php
  2. +18 −0 tests/TestCase/Filesystem/FolderTest.php
@@ -661,6 +661,7 @@ public function delete($path = null)
* - `mode` The mode to copy the files/directories with as integer, e.g. 0775.
* - `skip` Files/directories to skip.
* - `scheme` Folder::MERGE, Folder::OVERWRITE, Folder::SKIP
* - `recursive` Whether to copy recursively or not (default: true - recursive)
*
* @param array|string $options Either an array of options (see above) or a string of the destination directory.
* @return bool Success.
@@ -680,7 +681,8 @@ public function copy($options)
'from' => $this->path,
'mode' => $this->mode,
'skip' => [],
'scheme' => Folder::MERGE
'scheme' => Folder::MERGE,
'recursive' => true
];
$fromDir = $options['from'];
@@ -723,6 +725,10 @@ public function copy($options)
$this->delete($to);
}
if(is_dir($from) && $options['recursive'] === false) {
continue;
}
if (is_dir($from) && !file_exists($to)) {
$old = umask(0);
if (mkdir($to, $mode, true)) {
@@ -763,6 +769,7 @@ public function copy($options)
* - `chmod` The mode to copy the files/directories with.
* - `skip` Files/directories to skip.
* - `scheme` Folder::MERGE, Folder::OVERWRITE, Folder::SKIP
* - `recursive` Whether to copy recursively or not (default: true - recursive)
*
* @param array|string $options (to, from, chmod, skip, scheme)
* @return bool Success
@@ -774,7 +781,7 @@ public function move($options)
$to = $options;
$options = (array)$options;
}
$options += ['to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => []];
$options += ['to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => [], 'recursive' => true];
if ($this->copy($options)) {
if ($this->delete($options['from'])) {
@@ -1030,6 +1030,24 @@ public function testCopyWithOverwrite()
$this->assertTrue(file_exists($folderThree . DS . 'folderB' . DS . 'fileB.php'));
}
/**
* testCopyWithoutResursive
*
* Verify that only the files exist in the target directory.
*
* @return void
*/
public function testCopyWithoutRecursive()
{
extract($this->_setupFilesystem());
$Folder = new Folder($folderOne);
$result = $Folder->copy(['to' => $folderThree, 'recursive' => false]);
$this->assertTrue(file_exists($folderThree . DS . 'file1.php'));
$this->assertFalse(file_exists($folderThree . DS . 'folderA' . DS . 'fileA.php'));
}
/**
* Setup filesystem for copy tests
* $path: folder_test/

0 comments on commit b970a0e

Please sign in to comment.
You can’t perform that action at this time.