Skip to content

Commit

Permalink
added recursive option to copy to turn off it needed
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-lang committed May 12, 2015
1 parent f10d283 commit b970a0e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Filesystem/Folder.php
Expand Up @@ -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.
Expand All @@ -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'];
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand All @@ -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'])) {
Expand Down
18 changes: 18 additions & 0 deletions tests/TestCase/Filesystem/FolderTest.php
Expand Up @@ -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/
Expand Down

0 comments on commit b970a0e

Please sign in to comment.