/** * */ function copy(iDir $source, iDir $target, iDir $backup) { if (!$backup->exists()) { mkdir($backup); } foreach (glob($source . '/*') as $full_path) { $name = substr($full_path, strlen($source) + 1); if (is_file($full_path)) { //TODO compare file by md5_file and copy only different. $tf = $target->getFile($name); if ($tf->exists()) { if ($tf->copy($backup->getFile($name))) { $act = 'U'; } else { io::out('11throw Exception', IO::MESSAGE_FAIL); } } else { $act = 'A'; touch($this->delList); file_put_contents($this->delList, substr($full_path, strlen($this->source) + 1) . PHP_EOL . file_get_contents($this->delList)); } io::info("\t[~PURPLE~" . $act . "~~~] " . substr($full_path, strlen($this->source)), false); $r = $source->getFile($name)->copy($tf); if ($r) { io::info(); } else { io::out('throw Exception unable copy file ' . $source->getFile($name) . ' to ' . $tf, IO::MESSAGE_FAIL); } } else { if (is_dir($full_path)) { $td = $target->getDir($name); if (!$td->exists()) { if (!$target->mkdir($name)) { io::out('uNable create folder EXception', IO::MESSAGE_FAIL); } touch($this->delList); file_put_contents($this->delList, substr($full_path, strlen($this->source) + 1) . PHP_EOL . file_get_contents($this->delList)); } //IO::out('===> '.$name); $r = $this->copy($source->getDir($name), $target->getDir($name), $backup->getDir($name)); if ($r) { } else { io::out('throw Exception', IO::MESSAGE_FAIL); } if (count(glob($backup->getDir($name) . '/*')) == 0) { $backup->getDir($name)->delete(); } //IO::out(' <=== '. $name); } } } return true; }