示例#1
0
 /**
  *
  */
 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;
 }
示例#2
0
文件: Dir.php 项目: point/cassea
 /**
  * Рекурсивное копирование директории.
  *
  *
  *
  */
 public function copy(iDir $target, $createDirectory = true)
 {
     if (!$target->canWrite()) {
         throw new FileSystemException('Copy: target directory isnt writable: ' . $target);
     }
     if ($createDirectory) {
         $target = $target->mkdir($this->getName());
     }
     $list = $this->ls(null, Dir::LS_BOTH, GLOB_NOSORT);
     foreach ($list as $o) {
         //$name = $o->getName();
         //print_pre('>>> '.(is_dir($o)?" D ":"").$name);
         if ($o instanceof File) {
             $o->copy($target->getFile($o->getName()));
         } elseif ($o instanceof Dir) {
             $o->copy($target, true);
         } else {
             throw new FileSystemException('Unsupported object class: ' . get_class($o));
         }
     }
     return $target;
 }