From: Tomas V.V.Cox Date: Fri, 29 Aug 2003 18:23:31 +0000 (+0000) Subject: This patch allows: X-Git-Tag: RELEASE_0_7~373 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e18e3a6edde9e0308a12edbf3fbcdadab4010150;p=php This patch allows: pear install DB-1.2 -> specific version pear install DB-stable -> latest stable version (stable, beta, alpha, ..) pear install DB-1.2.tar -> download in tar format Currently only "install" and "upgrade" support this more will come shortly. --- diff --git a/pear/PEAR/Command/Install.php b/pear/PEAR/Command/Install.php index 8d7f8d9f3d..bc0e95803b 100644 --- a/pear/PEAR/Command/Install.php +++ b/pear/PEAR/Command/Install.php @@ -256,7 +256,7 @@ package if needed. $this->installer = &new PEAR_Installer($this->ui); } if ($command == 'upgrade') { - $options[$command] = true; + $options['upgrade'] = true; } if ($command == 'upgrade-all') { include_once "PEAR/Remote.php"; @@ -292,7 +292,12 @@ package if needed. $errors = array(); $downloaded = array(); $this->installer->download($params, $options, $this->config, $downloaded, - $errors); + $errors); + if ($command != 'upgrade-all') { + for ($i = 0; $i < count($params); $i++) { + $params[$i] = $this->installer->extractDownloadFileName($params[$i], $_tmp); + } + } if (count($errors)) { $err['data'] = array($errors); $err['headline'] = 'Install Errors'; diff --git a/pear/PEAR/Common.php b/pear/PEAR/Common.php index 46d78b3672..96d1ebfb50 100644 --- a/pear/PEAR/Common.php +++ b/pear/PEAR/Common.php @@ -28,6 +28,9 @@ require_once 'PEAR/Config.php'; define('PEAR_COMMON_PACKAGE_NAME_PREG', '/^([A-Z][a-zA-Z0-9_]+|[a-z][a-z0-9_]+)$/'); +// XXX far from perfect :-) +define('PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '/^([A-Z][a-zA-Z0-9_]+|[a-z][a-z0-9_]+)(-([.0-9a-zA-Z]+))?$/'); + /** * List of temporary files and directories registered by * PEAR_Common::addTempFile(). diff --git a/pear/PEAR/Installer.php b/pear/PEAR/Installer.php index 4b66e2b4fc..0ca07c15a6 100644 --- a/pear/PEAR/Installer.php +++ b/pear/PEAR/Installer.php @@ -424,8 +424,11 @@ class PEAR_Installer extends PEAR_Common // }}} // {{{ getPackageDownloadUrl() - function getPackageDownloadUrl($package) + function getPackageDownloadUrl($package, $version = null) { + if ($version) { + $package .= "-$version"; + } if ($this === null || $this->config === null) { $package = "http://pear.php.net/get/$package"; } else { @@ -448,7 +451,6 @@ class PEAR_Installer extends PEAR_Common } // }}} - // {{{ _prependPath($path, $prepend) function _prependPath($path, $prepend) @@ -463,9 +465,23 @@ class PEAR_Installer extends PEAR_Common return $path; } + // }}} + // {{ extractDownloadFileName($pkgfile, &$version) + + function extractDownloadFileName($pkgfile, &$version) + { + // regex defined in Common.php + if (preg_match(PEAR_COMMON_PACKAGE_DOWNLOAD_PREG, $pkgfile, $m)) { + $version = (isset($m[3])) ? $m[3] : null; + return $m[1]; + } + $version = null; + return $pkgfile; + } + // }}} // {{{ _downloadFile() - function _downloadFile($pkgfile, &$config, $options, &$errors) + function _downloadFile($pkgfile, &$config, $options, &$errors, $version) { $need_download = false; if (preg_match('#^(http|ftp)://#', $pkgfile)) { @@ -478,7 +494,7 @@ class PEAR_Installer extends PEAR_Common return; } } - $pkgfile = $this->getPackageDownloadUrl($pkgfile); + $pkgfile = $this->getPackageDownloadUrl($pkgfile, $version); $need_download = true; } else { if (strlen($pkgfile)) { @@ -532,7 +548,7 @@ class PEAR_Installer extends PEAR_Common * @param false private recursion variable */ function download($packages, $options, &$config, &$installpackages, - &$errors, $installed = false, $willinstall = false, $state = false) + &$errors, $installed = false, $willinstall = false, $state = false) { // recognized options: // - onlyreqdeps : install all required dependencies as well @@ -556,13 +572,15 @@ class PEAR_Installer extends PEAR_Common // download files in this list if necessary foreach($packages as $pkgfile) { + $pkgfile = $this->extractDownloadFileName($pkgfile, $version); if ($this->validPackageName($pkgfile) && !isset($options['upgrade'])) { if ($this->registry->packageExists($pkgfile)) { + $this->log(0, "Package '$pkgfile' already installed, skipping"); // ignore dependencies that are installed unless we are upgrading continue; } } - $pkgfile = $this->_downloadFile($pkgfile, $config, $options, $errors); + $pkgfile = $this->_downloadFile($pkgfile, $config, $options, $errors, $version); if (PEAR::isError($pkgfile)) { return $pkgfile; } @@ -722,7 +740,6 @@ class PEAR_Installer extends PEAR_Common $this->installroot = ''; } $this->registry = &new PEAR_Registry($php_dir); - $need_download = false; // ==> XXX should be removed later on $flag_old_format = false;