From b37cffd315c8d11f2982d2ba8e0e5d7c9e3ce15e Mon Sep 17 00:00:00 2001 From: Nestor <npegane@hotmail.com> Date: Thu, 11 Jan 2018 11:16:28 +0100 Subject: [PATCH] FIX #6180 symlinks not copied in copy_dir --- install/class/Class_Install.php | 40 ++++++++++++++++++++++--------- install/scripts/backupVersion.php | 4 +--- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/install/class/Class_Install.php b/install/class/Class_Install.php index 0b2966a780f..73b385eefac 100755 --- a/install/class/Class_Install.php +++ b/install/class/Class_Install.php @@ -2099,7 +2099,7 @@ class Install extends functions $db->query($query, array($sec->getPasswordHash($newPass))); } - public function copy_dir($dir2copy, $dir_paste, $excludeExt=false) + public function copy_dir($dir2copy, $dir_paste, $excludeExt=false, $excludeSymlink = false) { // On vérifie si $dir2copy est un dossier if (is_dir($dir2copy)) { @@ -2114,19 +2114,37 @@ class Install extends functions mkdir($dir_paste, 0777); } // S'il s'agit d'un dossier, on relance la fonction recursive - if (is_dir($dir2copy.$file) && $file != '..' && $file != '.') { - $this->copy_dir($dir2copy.$file.'/', $dir_paste.$file.'/', $excludeExt); - } elseif ($file != '..' && $file != '.') { - if (count($excludeExt>0) && is_array($excludeExt)) { - $copyIt = true; - foreach ($excludeExt as $key => $value) { - if (strtolower($value) == strtolower(pathinfo($dir2copy . $file, PATHINFO_EXTENSION))) { - $copyIt = false; + if($excludeSymlink){ + if (is_dir($dir2copy.$file) && $file != '..' && $file != '.' && !is_link($dir2copy.$file)) { + $this->copy_dir($dir2copy.$file.'/' , $dir_paste.$file.'/', $excludeExt, $excludeSymlink); + } elseif ($file != '..' && $file != '.' && !is_link($dir2copy.$file)) { + if (count($excludeExt>0) && is_array($excludeExt)) { + $copyIt = true; + foreach ($excludeExt as $key => $value) { + if (strtolower($value) == strtolower(pathinfo($dir2copy . $file, PATHINFO_EXTENSION))) { + $copyIt = false; + } } } + if ($copyIt) { + copy($dir2copy.$file, $dir_paste.$file); + } } - if ($copyIt) { - copy($dir2copy.$file, $dir_paste.$file); + } else { + if (is_dir($dir2copy.$file) && $file != '..' && $file != '.') { + $this->copy_dir($dir2copy.$file.'/' , $dir_paste.$file.'/', $excludeExt, $excludeSymlink); + } elseif ($file != '..' && $file != '.') { + if (count($excludeExt>0) && is_array($excludeExt)) { + $copyIt = true; + foreach ($excludeExt as $key => $value) { + if (strtolower($value) == strtolower(pathinfo($dir2copy . $file, PATHINFO_EXTENSION))) { + $copyIt = false; + } + } + } + if ($copyIt) { + copy($dir2copy.$file, $dir_paste.$file); + } } } } diff --git a/install/scripts/backupVersion.php b/install/scripts/backupVersion.php index fdc8f4c9230..2263ba23683 100755 --- a/install/scripts/backupVersion.php +++ b/install/scripts/backupVersion.php @@ -50,9 +50,7 @@ if (!$Class_Install->createPath($path)) { exit; } -$cmd = "cp -R ".$_SESSION['config']['corepath']." ".$path . DIRECTORY_SEPARATOR; - -if (!exec($cmd)) { +if (!$Class_Install->copy_dir($_SESSION['config']['corepath'] , $path . DIRECTORY_SEPARATOR, false, true)) { $return['status'] = 0; $return['text'] = _CAN_NOT_COPY_TO . ':' . $path; -- GitLab