recursive_copy function use cp -R if it exists

This commit is contained in:
Mark Crane 2014-05-16 05:14:44 +00:00
parent 59e112e7ff
commit b9643b60ee
2 changed files with 30 additions and 28 deletions

View File

@ -37,38 +37,42 @@ include "root.php";
//$option '-n' --no-clobber //$option '-n' --no-clobber
function recursive_copy($src, $dst, $option = '') { function recursive_copy($src, $dst, $option = '') {
if (file_exists('/bin/cp')) {
$dir = opendir($src); exec ('cp -R $option '.$src_dir.' '.$dst_dir);
if (!$dir) {
if (!mkdir($src, 0755, true)) {
throw new Exception("recursive_copy() source directory '".$src."' does not exist.");
}
} }
if (!is_dir($dst)) { else {
if (!mkdir($dst, 0755, true)) { $dir = opendir($src);
throw new Exception("recursive_copy() failed to create destination directory '".$dst."'"); if (!$dir) {
} if (!mkdir($src, 0755, true)) {
} throw new Exception("recursive_copy() source directory '".$src."' does not exist.");
while(false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src.'/'.$file)) {
$this->recursive_copy($src.'/'.$file, $dst.'/'.$file);
} }
else { }
//copy only missing files -n --no-clobber if (!is_dir($dst)) {
if ($option == '-n') { if (!mkdir($dst, 0755, true)) {
if (!file_exists($dst.'/'.$file)) { throw new Exception("recursive_copy() failed to create destination directory '".$dst."'");
copy($src.'/'.$file, $dst.'/'.$file); }
//echo "copy(".$src."/".$file.", ".$dst."/".$file.");<br />\n"; }
while(false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src.'/'.$file)) {
$this->recursive_copy($src.'/'.$file, $dst.'/'.$file);
}
else {
//copy only missing files -n --no-clobber
if ($option == '-n') {
if (!file_exists($dst.'/'.$file)) {
copy($src.'/'.$file, $dst.'/'.$file);
//echo "copy(".$src."/".$file.", ".$dst."/".$file.");<br />\n";
}
} }
} else {
else { copy($src.'/'.$file, $dst.'/'.$file);
copy($src.'/'.$file, $dst.'/'.$file); }
} }
} }
} }
closedir($dir);
} }
closedir($dir);
} }
function recursive_delete($dir) { function recursive_delete($dir) {

View File

@ -1279,8 +1279,6 @@ if ($_POST["install_step"] == "3" && count($_POST) > 0 && strlen($_POST["persist
$install->switch_conf_dir = $switch_conf_dir; $install->switch_conf_dir = $switch_conf_dir;
$install->switch_scripts_dir = $switch_scripts_dir; $install->switch_scripts_dir = $switch_scripts_dir;
$install->switch_sounds_dir = $switch_sounds_dir; $install->switch_sounds_dir = $switch_sounds_dir;
$install->recursive_delete($switch_conf_dir);
clearstatcache();
$install->copy_conf(); $install->copy_conf();
$install->copy(); $install->copy();