diff --git a/system/src/Grav/Common/Filesystem/Folder.php b/system/src/Grav/Common/Filesystem/Folder.php
index 9355038b8..8309bebff 100644
--- a/system/src/Grav/Common/Filesystem/Folder.php
+++ b/system/src/Grav/Common/Filesystem/Folder.php
@@ -278,6 +278,46 @@ abstract class Folder
}
}
+ /**
+ * Recursive copy of one directory to another
+ *
+ * @param $src
+ * @param $dest
+ *
+ * @return bool
+ */
+ public static 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()) {
+ static::rcopy($f->getRealPath(), "$dest/$f");
+ }
+ }
+ }
+ return true;
+ }
+
/**
* @param string $folder
* @return bool
@@ -290,13 +330,24 @@ abstract class Folder
return @unlink($folder);
}
- // Go through all items in filesystem and recursively remove everything.
- $files = array_diff(scandir($folder), array('.', '..'));
- foreach ($files as $file) {
- $path = "{$folder}/{$file}";
- (is_dir($path)) ? self::doDelete($path) : @unlink($path);
+ $files = new \RecursiveIteratorIterator(
+ new \RecursiveDirectoryIterator($folder, \RecursiveDirectoryIterator::SKIP_DOTS),
+ \RecursiveIteratorIterator::CHILD_FIRST
+ );
+
+ /** @var \DirectoryIterator $fileinfo */
+ foreach ($files as $fileinfo) {
+ if ($fileinfo->isDir()) {
+ if (false === rmdir($fileinfo->getRealPath())) {
+ return false;
+ }
+ } else {
+ if (false === unlink($fileinfo->getRealPath())) {
+ return false;
+ }
+ }
}
- return @rmdir($folder);
+ return rmdir($folder);
}
}
diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php
index eee0ee4f9..830cb6a6b 100644
--- a/system/src/Grav/Common/Utils.php
+++ b/system/src/Grav/Common/Utils.php
@@ -54,75 +54,6 @@ abstract class Utils
return (object) array_merge((array) $obj1, (array) $obj2);
}
- /**
- * Recursive remove a directory - DANGEROUS! USE WITH CARE!!!!
- *
- * @param $dir
- * @return bool
- */
- public static function rrmdir($dir)
- {
- $files = new \RecursiveIteratorIterator(
- new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
- \RecursiveIteratorIterator::CHILD_FIRST
- );
-
- /** @var \DirectoryIterator $fileinfo */
- foreach ($files as $fileinfo) {
- if ($fileinfo->isDir()) {
- if (false === rmdir($fileinfo->getRealPath())) {
- return false;
- }
- } else {
- if (false === unlink($fileinfo->getRealPath())) {
- return false;
- }
- }
- }
-
- return rmdir($dir);
- }
-
- /**
- * Recursive copy of one directory to another
- *
- * @param $src
- * @param $dest
- *
- * @return bool
- */
- public static 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()) {
- static::rcopy($f->getRealPath(), "$dest/$f");
- }
- }
- }
- return true;
- }
-
/**
* Truncate HTML by text length.
*
diff --git a/system/src/Grav/Console/Cli/SandboxCommand.php b/system/src/Grav/Console/Cli/SandboxCommand.php
index 4d984d219..c1e79ecdc 100644
--- a/system/src/Grav/Console/Cli/SandboxCommand.php
+++ b/system/src/Grav/Console/Cli/SandboxCommand.php
@@ -189,7 +189,7 @@ class SandboxCommand extends Command
$to = $this->destination . $target;
$this->output->writeln(' ' . $source . ' -> ' . $to);
- Utils::rcopy($from, $to);
+ Folder::rcopy($from, $to);
}
}
@@ -269,7 +269,7 @@ class SandboxCommand extends Command
if (count($pages_files) == 0) {
$destination = $this->source . '/user/pages';
- Utils::rcopy($destination, $pages_dir);
+ Folder::rcopy($destination, $pages_dir);
$this->output->writeln(' ' . $destination . ' -> Created');
}
diff --git a/system/src/Grav/Console/Gpm/InstallCommand.php b/system/src/Grav/Console/Gpm/InstallCommand.php
index c39087db4..60e01196f 100644
--- a/system/src/Grav/Console/Gpm/InstallCommand.php
+++ b/system/src/Grav/Console/Gpm/InstallCommand.php
@@ -255,7 +255,7 @@ class InstallCommand extends Command
// Confirmation received, copy over the data
$this->output->writeln(" |- Installing demo content... ok ");
- Utils::rcopy($demo_dir, $dest_dir);
+ Folder::rcopy($demo_dir, $dest_dir);
$this->output->writeln(" '- Success! ");
$this->output->writeln('');
}