cvs: pear-core /PEAR/Command Remote.php

From: Date: Fri, 13 Aug 2004 23:57:30 +0000
Subject: cvs: pear-core /PEAR/Command Remote.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-cvs+get-22873@lists.php.net to get a copy of this message
cellog Fri Aug 13 19:57:30 2004 EDT Modified files: /pear-core/PEAR/Command Remote.php Log: leverage the power of the existing PEAR_Downloader class to the $ pear download xxx command. http://cvs.php.net/diff.php/pear-core/PEAR/Command/Remote.php?r1=1.42&r2=1.43&ty=u Index: pear-core/PEAR/Command/Remote.php diff -u pear-core/PEAR/Command/Remote.php:1.42 pear-core/PEAR/Command/Remote.php:1.43 --- pear-core/PEAR/Command/Remote.php:1.42 Tue Jul 13 17:13:47 2004 +++ pear-core/PEAR/Command/Remote.php Fri Aug 13 19:57:30 2004 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Remote.php,v 1.42 2004/07/13 21:13:47 cox Exp $ +// $Id: Remote.php,v 1.43 2004/08/13 23:57:30 cellog Exp $ require_once 'PEAR/Command/Common.php'; require_once 'PEAR/Common.php'; @@ -363,45 +363,23 @@ return PEAR::raiseError("download expects one argument: the package to download"); } //$params[0] -> The package to download - $savechannel = $channel = $this->config->get('default_channel'); - $reg = new PEAR_Registry($this->config->get('php_dir', null, 'pear')); - $package = $params[0]; - if (strpos($params[0], '::')) { - list($channel, $package) = explode('::', $params[0]); - if ($reg->channelExists($channel)) { - $this->config->set('default_channel', $channel); - } else { - return $this->raiseError("Channel '$channel' does not exist"); - } - } - $channelobj = $reg->getChannel($channel); - if (!$channelobj) { - $this->config->set('default_channel', $savechannel); - return $this->raiseError("Serious registry error: channel '$channel' is corrupt, re-set up with channel-update or update-channels"); - } - $server = $channelobj->getServer(); - if (!$channelobj->supports('download')) { - $this->config->set('default_channel', $savechannel); - return $this->raiseError("Channel '$channel' does not support downloading"); - } - $get = $channelobj->getProtocol('download'); - $get = $get['name']; - if (!ereg('^http://', $params[0])) { - $getoption = isset($options['nocompress'])&&$options['nocompress']==1?'?uncompress=on':''; - $pkgfile = "http://$server/$get/$package".$getoption; - } else { - $pkgfile = $params[0]; - } - $this->bytes_downloaded = 0; - $saved = PEAR_Common::downloadHttp($pkgfile, $this->ui, '.', - array(&$this, 'downloadCallback')); - if (PEAR::isError($saved)) { - $this->config->set('default_channel', $savechannel); - return $this->raiseError($saved); + include_once 'PEAR/Downloader.php'; + $downloader = &new PEAR_Downloader($this->ui, array('force' => 1), $this->config); + $errors = array(); + $downloaded = array(); + $downloader->download($params); + $errors = $downloader->getErrorMsgs(); + if (count($errors)) { + $err['data'] = array($errors); + $err['headline'] = 'Download Errors'; + $this->ui->outputData($err); + return $this->raiseError("$command failed"); + } + $downloaded = $downloader->getDownloadedPackages(); + foreach ($downloaded as $pkg) { + @copy($pkg['file'], $fname = getcwd() . basename($pkg['file'])); + $this->ui->outputData("File $fname downloaded", $command); } - $fname = basename($saved); - $this->ui->outputData("File $fname downloaded ($this->bytes_downloaded bytes)", $command); - $this->config->set('default_channel', $savechannel); return true; }

« previous php.pear.cvs (#22873) next »