From f1f2185b8d9f5e5adb214df4ce083660189ff90b Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 26 Apr 2016 12:51:05 +0200 Subject: [PATCH] Use mirror to copy files --- main/inc/lib/fileManage.lib.php | 52 ++++----------------------------- 1 file changed, 5 insertions(+), 47 deletions(-) diff --git a/main/inc/lib/fileManage.lib.php b/main/inc/lib/fileManage.lib.php index e1d6472254..abd84dc129 100755 --- a/main/inc/lib/fileManage.lib.php +++ b/main/inc/lib/fileManage.lib.php @@ -261,54 +261,12 @@ function move($source, $target, $forceMove = false, $moveContent = false) */ function copyDirTo($orig_dir_path, $destination, $move = true) { - if ($orig_dir_path == $destination) { - return false; - } - - $save_dir = getcwd(); - // Extract directory name - create it at destination - update destination trail - $dir_name = basename($orig_dir_path); - $dir_to_copy = array(); - if (is_dir($orig_dir_path)) { - if (!is_dir($destination.'/'.$dir_name)) { - mkdir( - $destination.'/'.$dir_name, - api_get_permissions_for_new_directories() - ); - } - $destination_trail = $destination.'/'.$dir_name; - if (is_dir($destination)) { - chdir($orig_dir_path) ; - $handle = opendir($orig_dir_path); + $fs = new \Symfony\Component\Filesystem\Filesystem(); + $fs->mirror($orig_dir_path, $destination); - while ($element = readdir($handle)) { - if ($element == '.' || $element == '..') { - continue; // Skip the current and parent directories - } elseif (is_file($element)) { - copy($element, $destination_trail.'/'.$element); - - if ($move) { - unlink($element) ; - } - } elseif (is_dir($element)) { - $dir_to_copy[] = $orig_dir_path.'/'.$element; - } - } - - closedir($handle) ; - - if (sizeof($dir_to_copy) > 0) { - foreach ($dir_to_copy as $this_dir) { - copyDirTo($this_dir, $destination_trail, $move); // Recursivity - } - } - - if ($move) { - rmdir($orig_dir_path) ; - } - chdir($save_dir); - } - } + if ($move) { + $fs->remove($orig_dir_path); + } }