Пример #1
0
 /**
  * Recurisvely copy files and directories via FTP.
  * @param Typeframe_Ftp $ftp
  * @param string $src The source directory.
  * @param string $dst The destination directory.
  */
 private static function _CopyFiles(Typeframe_File $ftp, $src, $dst, $package, $force)
 {
     $files = scandir($src);
     $xml = null;
     if (file_exists(TYPEF_SOURCE_DIR . '/packages/' . $package . '.xml')) {
         $xml = simplexml_load_file(TYPEF_SOURCE_DIR . '/packages/' . $package . '.xml');
     }
     foreach ($files as $file) {
         if (substr($file, 0, 1) == '.') {
             continue;
         }
         if (is_file("{$src}/{$file}")) {
             // Copy the file depending on $force rules
             $copy = false;
             if (!file_exists(TYPEF_DIR . "{$dst}/{$file}")) {
                 $copy = true;
             } else {
                 if ($force === true) {
                     $copy = true;
                 } else {
                     // Check for filename in $force
                     if (is_array($force) && in_array(substr("{$dst}/{$file}", 1), $force)) {
                         $copy = true;
                     } else {
                         if ($xml) {
                             foreach ($xml->file as $xfile) {
                                 $fn = trim("{$xfile}");
                                 if (substr($fn, 0, 1) == '/') {
                                     $fn = substr($fn, 1);
                                 }
                                 $fn = preg_replace('/\\/+/', '/', $fn);
                                 $dn = "{$dst}/{$file}";
                                 if (substr($dn, 0, 1) == '/') {
                                     $dn = substr($dn, 1);
                                 }
                                 $dn = preg_replace('/\\/+/', '/', $dn);
                                 if ($fn == $dn) {
                                     $md5 = md5_file(TYPEF_DIR . '/' . $fn);
                                     if ($xfile['md5'] == $md5) {
                                         $copy = true;
                                     }
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
             if ($copy) {
                 $ftp->copy("{$src}/{$file}", "{$dst}/{$file}");
             }
         } else {
             if (is_dir("{$src}/{$file}")) {
                 // TODO: Make the directory if it does not exist
                 if (!file_exists(TYPEF_DIR . "/{$dst}/{$file}")) {
                     $ftp->mkdir("{$dst}/{$file}");
                 }
                 self::_CopyFiles($ftp, "{$src}/{$file}", "{$dst}/{$file}", $package, $force);
                 // TODO: What if the file exists and is not a directory?
             }
         }
         // TODO: Is there another possibility?
     }
 }