Use rcopy from Utils class

This commit is contained in:
Andy Miller
2015-02-15 16:09:16 -07:00
parent f8c203c033
commit 534bb57d3f

View File

@@ -2,6 +2,7 @@
namespace Grav\Console\Cli;
use Grav\Common\Filesystem\Folder;
use Grav\Common\Utils;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputArgument;
@@ -188,7 +189,7 @@ class SandboxCommand extends Command
$to = $this->destination . $target;
$this->output->writeln(' <cyan>' . $source . '</cyan> <comment>-></comment> ' . $to);
$this->rcopy($from, $to);
Utils::rcopy($from, $to);
}
}
@@ -326,42 +327,4 @@ class SandboxCommand extends Command
exit;
}
}
/**
* @param $src
* @param $dest
*
* @return bool
*/
private function rcopy($src, $dest)
{
// If the src is not a directory do a simple file copy
if (!is_dir($src)) {
copy($src, $dest);
return true;
}
// If the destination directory does not exist create it
if (!is_dir($dest)) {
if (!mkdir($dest)) {
// If the destination directory could not be created stop processing
return false;
}
}
// Open the source directory to read in files
$i = new \DirectoryIterator($src);
/** @var \DirectoryIterator $f */
foreach ($i as $f) {
if ($f->isFile()) {
copy($f->getRealPath(), "$dest/" . $f->getFilename());
} else {
if (!$f->isDot() && $f->isDir()) {
$this->rcopy($f->getRealPath(), "$dest/$f");
}
}
}
return true;
}
}