Esempio n. 1
0
/**
 * Mirrors a list of files to another directory.
 *
 * @param FinderResult|string $arg
 */
function mirror($files, $target_dir, $isSilent = false, $options = array())
{
    if (is_string($files)) {
        $files = \pantr\transformToIterable($files);
    }
    $origin_dir = $files->getSourceDirectory();
    $files = $files->getRelativeFilePaths();
    // switch silent <-> options
    if (is_array($isSilent)) {
        $options = $isSilent;
        $isSilent = false;
    }
    if ($isSilent) {
        writeAction('mirror', $origin_dir . ' -> ' . $target_dir);
        pantr::beginSilent();
    }
    foreach ($files as $file) {
        if (is_dir($origin_dir . DIRECTORY_SEPARATOR . $file)) {
            mkdirs($target_dir . DIRECTORY_SEPARATOR . $file);
        } else {
            if (is_file($origin_dir . DIRECTORY_SEPARATOR . $file)) {
                copy($origin_dir . DIRECTORY_SEPARATOR . $file, $target_dir . DIRECTORY_SEPARATOR . $file, $options);
            } else {
                if (is_link($origin_dir . DIRECTORY_SEPARATOR . $file)) {
                    symlink($origin_dir . DIRECTORY_SEPARATOR . $file, $target_dir . DIRECTORY_SEPARATOR . $file);
                } else {
                    throw new \Exception(sprintf('Unable to determine "%s" type', $file));
                }
            }
        }
    }
    if ($isSilent) {
        pantr::endSilent();
    }
}
Esempio n. 2
0
File: pantr.php Progetto: pago/pantr
 public static function mirror($arg, $origin_dir, $target_dir, $isSilent = false, $options = array())
 {
     $files = pantr::_getFinderFromArg($arg, $origin_dir, true);
     // switch silent <-> options
     if (is_array($isSilent)) {
         $options = $isSilent;
         $isSilent = false;
     }
     if ($isSilent) {
         pantr::writeAction('mirror', $origin_dir . ' -> ' . $target_dir);
         pantr::beginSilent();
     }
     foreach ($files as $file) {
         if (is_dir($origin_dir . DIRECTORY_SEPARATOR . $file)) {
             pantr::mkdirs($target_dir . DIRECTORY_SEPARATOR . $file);
         } else {
             if (is_file($origin_dir . DIRECTORY_SEPARATOR . $file)) {
                 pantr::copy($origin_dir . DIRECTORY_SEPARATOR . $file, $target_dir . DIRECTORY_SEPARATOR . $file, $options);
             } else {
                 if (is_link($origin_dir . DIRECTORY_SEPARATOR . $file)) {
                     pantr::symlink($origin_dir . DIRECTORY_SEPARATOR . $file, $target_dir . DIRECTORY_SEPARATOR . $file);
                 } else {
                     throw new \Exception(sprintf('Unable to determine "%s" type', $file));
                 }
             }
         }
     }
     if ($isSilent) {
         pantr::endSilent();
     }
 }
Esempio n. 3
0
 public function sync($silent = true)
 {
     $pkgs = $this->repo->listAllPackages();
     pantr::writeAction('sync', 'PEAR repository');
     foreach ($this->channels as $channel => $packages) {
         // discover channel if it is new
         if (!isset($pkgs[$channel])) {
             if ($silent) {
                 pantr::beginSilent('add', 'channel ' . $channel);
             }
             $this->repo->discoverChannel($channel);
             if ($silent) {
                 pantr::endSilent();
             }
             $pkgs[$channel] = array();
         }
         // now check if all packages from this channel are installed
         foreach ($packages as $pkg => $version) {
             if (!in_array($pkg, $pkgs[$channel])) {
                 // $channel/$pkg[-$version]
                 if ($silent) {
                     pantr::beginSilent('install', 'package ' . $pkg);
                 }
                 try {
                     $this->repo->install($channel . '/' . $pkg . ($version != '' ? '-' . $version : ''));
                 } catch (\Exception $ex) {
                     pantr::writeln($ex, pantr::WARNING);
                 }
                 if ($silent) {
                     pantr::endSilent();
                 }
                 $pkgs[$channel][] = $pkg;
             }
         }
         // check if packages are installed that are not specified
         foreach ($pkgs[$channel] as $pkg) {
             if (!isset($packages[$pkg])) {
                 if ($silent) {
                     pantr::beginSilent('delete', 'package ' . $pkg);
                 }
                 $this->repo->uninstall($channel . '/' . $pkg);
                 if ($silent) {
                     pantr::endSilent();
                 }
             }
         }
     }
     // delete unknown channels
     foreach ($pkgs as $channel => $packs) {
         if (!isset($this->channels[$channel])) {
             pantr::writeln($channel);
             foreach ($packs as $pkg) {
                 if ($silent) {
                     pantr::beginSilent('delete', 'package ' . $pkg);
                 }
                 $this->repo->uninstall($channel . '/' . $pkg);
                 if ($silent) {
                     pantr::endSilent();
                 }
             }
             if ($silent) {
                 pantr::beginSilent('delete', 'channel ' . $channel);
             }
             $this->repo->deleteChannel($channel);
             if ($silent) {
                 pantr::endSilent();
             }
         }
     }
 }