cvs: pear-core /PEAR Downloader.php Installer.php /PEAR/Command Install.php /PEAR/PackageFile v1.php v2.php
| From: | Greg Beaver | Date: | Tue, 19 Oct 2004 21:12:28 +0000 |
| Subject: | cvs: pear-core /PEAR Downloader.php Installer.php /PEAR/Command Install.php /PEAR/PackageFile v1.php v2.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-1074@lists.php.net to get a copy of this message | ||
cellog Tue Oct 19 17:12:28 2004 EDT
Modified files:
/pear-core/PEAR/Command Install.php
/pear-core/PEAR Downloader.php Installer.php
/pear-core/PEAR/PackageFile v1.php v2.php
Log:
TRUE installation and download dependency resolution.
@todo write and unit test uninstall dependency resolution
http://cvs.php.net/diff.php/pear-core/PEAR/Command/Install.php?r1=1.61&r2=1.62&ty=u Index: pear-core/PEAR/Command/Install.php diff -u pear-core/PEAR/Command/Install.php:1.61 pear-core/PEAR/Command/Install.php:1.62 --- pear-core/PEAR/Command/Install.php:1.61 Thu Sep 30 15:22:08 2004 +++ pear-core/PEAR/Command/Install.php Tue Oct 19 17:12:27 2004 @@ -16,7 +16,7 @@ // | Author: Stig Sæther Bakken <ssb@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Install.php,v 1.61 2004/09/30 19:22:08 cellog Exp $ +// $Id: Install.php,v 1.62 2004/10/19 21:12:27 cellog Exp $ require_once "PEAR/Command/Common.php"; require_once "PEAR/Installer.php"; @@ -307,7 +307,7 @@ $this->downloader = &new PEAR_Downloader($this->ui, $options, $this->config); $errors = array(); $downloaded = array(); - $this->downloader->download($params); + $downloaded = &$this->downloader->download($params); $errors = $this->downloader->getErrorMsgs(); if (count($errors)) { foreach ($errors as $error) { @@ -317,12 +317,13 @@ $this->ui->outputData($err); return $this->raiseError("$command failed"); } - $downloaded = $this->downloader->getDownloadedPackages(); - $this->installer->sortPkgDeps($downloaded); + $this->installer->sortPackagesForInstall($downloaded); + $this->installer->setDownloadedPackages($downloaded); $reg = &$this->config->getRegistry(); - foreach ($downloaded as $pkg) { + foreach ($downloaded as $param) { PEAR::pushErrorHandling(PEAR_ERROR_RETURN); - $info = $this->installer->install($pkg['info'], $options, $this->config); + $info = $this->installer->install($param->getPackageFile(), $options, + $this->config); PEAR::popErrorHandling(); if (PEAR::isError($info)) { $this->ui->outputData('ERROR: ' .$info->getMessage()); @@ -330,12 +331,12 @@ } if (is_array($info)) { if ($this->config->get('verbose') > 0) { - $channel = $pkg['info']->getChannel(); + $channel = $param->getChannel(); $label = $reg->parsedPackageNameToString( array( 'channel' => $channel, - 'package' => $pkg['info']->getPackage(), - 'version' => $pkg['info']->getVersion(), + 'package' => $param->getPackage(), + 'version' => $param->getVersion(), )); $out = array('data' => "$command ok: $label"); if (isset($info['release_warnings'])) { http://cvs.php.net/diff.php/pear-core/PEAR/Downloader.php?r1=1.35&r2=1.36&ty=u Index: pear-core/PEAR/Downloader.php diff -u pear-core/PEAR/Downloader.php:1.35 pear-core/PEAR/Downloader.php:1.36 --- pear-core/PEAR/Downloader.php:1.35 Mon Oct 18 14:06:02 2004 +++ pear-core/PEAR/Downloader.php Tue Oct 19 17:12:27 2004 @@ -19,11 +19,13 @@ // | Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Downloader.php,v 1.35 2004/10/18 18:06:02 cellog Exp $ +// $Id: Downloader.php,v 1.36 2004/10/19 21:12:27 cellog Exp $ require_once 'PEAR/Common.php'; require_once 'PEAR/Registry.php'; require_once 'PEAR/Dependency.php'; +require_once 'PEAR/Dependency2.php'; +require_once 'PEAR/DependencyDB.php'; require_once 'PEAR/Remote.php'; require_once 'PEAR/PackageFile.php'; require_once 'PEAR/Downloader/Package.php'; @@ -539,249 +541,218 @@ } // }}} - // {{{ sortPkgDeps() /** - * Sort a list of arrays of array(downloaded packagefilename) by dependency. - * - * It also removes duplicate dependencies - * @param array - * @param boolean Sort packages in reverse order if true - * @return array array of array(packagefilename, package.xml contents) + * for BC */ function sortPkgDeps(&$packages, $uninstall = false) { - $ret = array(); - if ($uninstall) { - foreach($packages as $packageinfo) { - $ret[] = array('info' => $packageinfo); + $uninstall ? + $this->sortPackagesForUninstall($packages) : + $this->sortPackagesForInstall($packages); + } + + function _getDepTreeDP($package, $packages, &$deps, &$checked) + { + $pf = $package->getPackageFile(); + $checked[strtolower($package->getChannel())][strtolower($package->getPackage())] + = true; + $pdeps = $pf->getDeps(true); + if (!$pdeps) { + return; + } + if ($pf->getPackagexmlVersion() == '1.0') { + foreach ($pdeps as $dep) { + if ($dep['type'] != 'pkg') { + continue; + } + $deps['pear.php.net'][strtolower($dep['name'])] = true; + foreach ($packages as $p) { + $dep['channel'] = 'pear.php.net'; + $dep['package'] = $dep['name']; + unset($dep['version']); + if ($p->isEqual($dep)) { + if (!isset($checked[strtolower($p->getChannel())] + [strtolower($p->getPackage())])) { + // add the dependency's dependencies to the tree + $this->_getDepTreeDP($p, $packages, $deps, $checked); + } + } + } } } else { - foreach($packages as $packagefile) { - if (!is_array($packagefile)) { - $a = new PEAR_PackageFile($this->config, $this->_debug); - $a = &$a->fromAnyFile($packagefile, PEAR_VALIDATE_INSTALLING); - $ret[] = array('file' => $packagefile, - 'info' => $a, - 'pkg' => $a->getPackage()); + $tdeps = array(); + if (isset($pdeps['required']['package'])) { + $t = $pdeps['required']['package']; + if (!isset($t[0])) { + $t = array($t); + } + $tdeps = array_merge($tdeps, $t); + } + if (isset($pdeps['required']['subpackage'])) { + $t = $pdeps['required']['subpackage']; + if (!isset($t[0])) { + $t = array($t); + } + $tdeps = array_merge($tdeps, $t); + } + if (isset($pdeps['optional']['package'])) { + $t = $pdeps['optional']['package']; + if (!isset($t[0])) { + $t = array($t); + } + $tdeps = array_merge($tdeps, $t); + } + if (isset($pdeps['optional']['subpackage'])) { + $t = $pdeps['optional']['subpackage']; + if (!isset($t[0])) { + $t = array($t); + } + $tdeps = array_merge($tdeps, $t); + } + if (isset($pdeps['group'])) { + if (!isset($pdeps['group'][0])) { + $pdeps['group'] = array($pdeps['group']); + } + foreach ($pdeps['group'] as $group) { + if (isset($group['package'])) { + $t = $group['package']; + if (!isset($t[0])) { + $t = array($t); + } + $tdeps = array_merge($tdeps, $t); + } + if (isset($group['subpackage'])) { + $t = $group['subpackage']; + if (!isset($t[0])) { + $t = array($t); + } + $tdeps = array_merge($tdeps, $t); + } + } + } + foreach ($tdeps as $dep) { + if (!isset($dep['channel'])) { + $depchannel = '__private'; } else { - $ret[] = $packagefile; + $depchannel = $dep['channel']; + } + $deps[$depchannel][strtolower($dep['name'])] = true; + foreach ($packages as $p) { + $dep['channel'] = $depchannel; + $dep['package'] = $dep['name']; + if ($p->isEqual($dep)) { + if (!isset($checked[strtolower($p->getChannel())] + [strtolower($p->getPackage())])) { + // add the dependency's dependencies to the tree + $this->_getDepTreeDP($p, $packages, $deps, $checked); + } + } } } } - $checkdupes = array(); - $newret = array(); - foreach($ret as $i => $p) { - $channel = $p['info']->getChannel(); - if (!isset($checkdupes[$channel . '/' . $p['info']->getPackage()])) { - $checkdupes[$channel . '/' . $p['info']->getPackage()][] = $i; - $newret[] = $p; - } - } - $this->_packageSortTree = $this->_getPkgDepTree($newret); - - $func = $uninstall ? '_sortPkgDepsRev' : '_sortPkgDeps'; - usort($newret, array(&$this, $func)); - $this->_packageSortTree = null; - $packages = $newret; } - // }}} - // {{{ _sortPkgDeps() - /** - * Compare two package's package.xml, and sort - * so that dependencies are installed first + * Sort a list of arrays of array(downloaded packagefilename) by dependency. * - * This is a crude compare, real dependency checking is done on install. - * The only purpose this serves is to make the command-line - * order-independent (you can list a dependent package first, and - * installation occurs in the order required) - * @access private + * It also removes duplicate dependencies + * @param array an array of downloaded PEAR_Downloader_Packages + * @return array array of array(packagefilename, package.xml contents) */ - function _sortPkgDeps($p1, $p2) + function sortPackagesForInstall(&$packages) { - $c1 = $p1['info']->getChannel(); - $c2 = $p2['info']->getChannel(); - $p1name = $c1 . '/' . $p1['info']->getPackage(); - $p2name = $c2 . '/' . $p2['info']->getPackage(); - $p1deps = $this->_getPkgDeps($p1); - $p2deps = $this->_getPkgDeps($p2); - if (!count($p1deps) && !count($p2deps)) { - return 0; // order makes no difference - } - if (!count($p1deps)) { - return -1; // package 2 has dependencies, package 1 doesn't - } - if (!count($p2deps)) { - return 1; // package 1 has dependencies, package 2 doesn't + foreach ($packages as $i => $package) { + $checked = $deps = array(); + $this->_getDepTreeDP($packages[$i], $packages, $deps, $checked); + $this->_depTree[$package->getChannel()][$package->getPackage()] = $deps; } - // both have dependencies - if (in_array($p1name, $p2deps)) { - return -1; // put package 1 first: package 2 depends on package 1 - } - if (in_array($p2name, $p1deps)) { - return 1; // put package 2 first: package 1 depends on package 2 - } - if ($this->_removedDependency($p1name, $p2name)) { - return -1; // put package 1 first: package 2 depends on packages that depend on package 1 - } - if ($this->_removedDependency($p2name, $p1name)) { - return 1; // put package 2 first: package 1 depends on packages that depend on package 2 - } - // doesn't really matter if neither depends on the other - return 0; + usort($packages, array(&$this, '_sortInstall')); } - // }}} - // {{{ _sortPkgDepsRev() + function _dependsOn($a, $b) + { + return $this->_checkDepTree(strtolower($a->getChannel()), strtolower($a->getPackage()), + $b); + } - /** - * Compare two package's package.xml, and sort - * so that dependencies are uninstalled last - * - * This is a crude compare, real dependency checking is done on uninstall. - * The only purpose this serves is to make the command-line - * order-independent (you can list a dependency first, and - * uninstallation occurs in the order required) - * @access private - */ - function _sortPkgDepsRev($p1, $p2) + function _checkDepTree($channel, $package, $b, $checked = array()) { - $c1 = $p1['info']->getChannel(); - $c2 = $p2['info']->getChannel(); - $p1name = $c1 . '/' . $p1['info']->getPackage(); - $p2name = $c2 . '/' . $p2['info']->getPackage(); - $p1deps = $this->_getRevPkgDeps($p1); - $p2deps = $this->_getRevPkgDeps($p2); - if (!count($p1deps) && !count($p2deps)) { - return 0; // order makes no difference + $checked[$channel][$package] = true; + if (!isset($this->_depTree[$channel][$package])) { + return false; + } + if (isset($this->_depTree[$channel][$package][strtolower($b->getChannel())] + [strtolower($b->getPackage())])) { + return true; } - if (!count($p1deps)) { - return 1; // package 2 has dependencies, package 1 doesn't + foreach ($this->_depTree[$channel][$package] as $ch => $packages) { + foreach ($packages as $pa => $true) { + if ($this->_checkDepTree($ch, $pa, $b, $checked)) { + return true; + } + } } - if (!count($p2deps)) { - return -1; // package 2 has dependencies, package 1 doesn't + return false; + } + + function _sortInstall($a, $b) + { + if (!$a->getDeps() && !$b->getDeps()) { + return 0; // neither package has dependencies, order is insignificant } - // both have dependencies - if (in_array($p1name, $p2deps)) { - return 1; // put package 1 last + if ($a->getDeps() && !$b->getDeps()) { + return 1; // $a must be installed after $b because $a has dependencies } - if (in_array($p2name, $p1deps)) { - return -1; // put package 2 last + if (!$a->getDeps() && $b->getDeps()) { + return -1; // $b must be installed after $a because $b has dependencies } - if ($this->_removedDependency($p1name, $p2name)) { - return 1; // put package 1 last: package 2 depends on packages that depend on package 1 + // both packages have dependencies + if ($this->_dependsOn($a, $b)) { + return 1; } - if ($this->_removedDependency($p2name, $p1name)) { - return -1; // put package 2 last: package 1 depends on packages that depend on package 2 + if ($this->_dependsOn($b, $a)) { + return -1; } - // doesn't really matter if neither depends on the other return 0; } - // }}} - // {{{ _getPkgDeps() - /** - * get an array of package dependency names - * @param array - * @return array - * @access private + * Sort a list of arrays of array(downloaded packagefilename) by dependency. + * + * It also removes duplicate dependencies + * @param array an array of PEAR_PackageFile_v[1/2] objects + * @return array array of array(packagefilename, package.xml contents) */ - function _getPkgDeps($p) + function sortPackagesForUninstall(&$packages) { - if (!is_array($p['info'])) { - return $this->_getRevPkgDeps($p); - } - $rel = array_shift($p['info']['releases']); - if (!isset($rel['deps'])) { - return array(); - } - $ret = array(); - foreach($rel['deps'] as $dep) { - if ($dep['type'] == 'pkg') { - $channel = isset($dep['channel']) ? $dep['channel'] : 'pear.php.net'; - $ret[] = $channel . '/' . $dep['name']; - } - } - return $ret; } - // }}} - // {{{ _getPkgDeps() - - /** - * get an array representation of the package dependency tree - * @return array - * @access private - */ - function _getPkgDepTree($packages) + function _uninstallDependsOn($a, $b) { - $tree = array(); - foreach ($packages as $p) { - $channel = $p['info']->getChannel(); - $package = $channel . '/' . $p['info']->getPackage(); - $deps = $this->_getPkgDeps($p); - $tree[$package] = $deps; - } - return $tree; } - // }}} - // {{{ _removedDependency($p1, $p2) - - /** - * get an array of package dependency names for uninstall - * @param string package 1 name - * @param string package 2 name - * @return bool - * @access private - */ - function _removedDependency($p1, $p2) + function _sortUninstall($a, $b) { - if (empty($this->_packageSortTree[$p2])) { - return false; + if (!$a->getDeps() && !$b->getDeps()) { + return 0; // neither package has dependencies, order is insignificant } - if (!in_array($p1, $this->_packageSortTree[$p2])) { - foreach ($this->_packageSortTree[$p2] as $potential) { - if ($this->_removedDependency($p1, $potential)) { - return true; - } - } - return false; + if ($a->getDeps() && !$b->getDeps()) { + return 1; // $a must be installed after $b because $a has dependencies } - return true; - } - - // }}} - // {{{ _getRevPkgDeps() - - /** - * get an array of package dependency names for uninstall - * @param array - * @return array - * @access private - */ - function _getRevPkgDeps($p) - { - if (!$deps = $p['info']->getDeps()) { - return array(); + if (!$a->getDeps() && $b->getDeps()) { + return -1; // $b must be installed after $a because $b has dependencies } - $ret = array(); - foreach($deps as $dep) { - if ($dep['type'] == 'pkg') { - $channel = isset($dep['channel']) ? $dep['channel'] : 'pear.php.net'; - $ret[] = $channel . '/' . $dep['name']; - } + // both packages have dependencies + if ($this->_dependsOn($a, $b)) { + return 1; } - return $ret; + if ($this->_dependsOn($b, $a)) { + return -1; + } + return 0; } - // }}} - - // {{{ downloadHttp() - /** * Download a file through HTTP. Considers suggested file name in * Content-disposition: header and can run a callback function for @@ -953,8 +924,6 @@ } return $dest_file; } - - // }}} } // }}} http://cvs.php.net/diff.php/pear-core/PEAR/Installer.php?r1=1.161&r2=1.162&ty=u Index: pear-core/PEAR/Installer.php diff -u pear-core/PEAR/Installer.php:1.161 pear-core/PEAR/Installer.php:1.162 --- pear-core/PEAR/Installer.php:1.161 Mon Oct 11 11:38:12 2004 +++ pear-core/PEAR/Installer.php Tue Oct 19 17:12:27 2004 @@ -18,7 +18,7 @@ // | Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Installer.php,v 1.161 2004/10/11 15:38:12 cellog Exp $ +// $Id: Installer.php,v 1.162 2004/10/19 21:12:27 cellog Exp $ require_once 'PEAR/Downloader.php'; require_once 'PEAR/Task/Common.php'; @@ -78,11 +78,18 @@ */ var $tmpdir; - /** PEAR_Registry object used by the installer - * @var object + /** + * PEAR_Registry object used by the installer + * @var PEAR_Registry */ var $registry; + /** + * array of PEAR_Downloader_Packages + * @var array + */ + var $_downloadedPackages; + /** List of file transactions queued for an install/upgrade/uninstall. * * Format: @@ -741,6 +748,16 @@ } // }}} + /** + * Set the list of PEAR_Downloader_Package objects to allow more sane + * dependency validation + * @param array + */ + function setDownloadedPackages(&$pkgs) + { + $this->_downloadedPackages = &$pkgs; + } + // {{{ install() /** http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/v1.php?r1=1.17&r2=1.18&ty=u Index: pear-core/PEAR/PackageFile/v1.php diff -u pear-core/PEAR/PackageFile/v1.php:1.17 pear-core/PEAR/PackageFile/v1.php:1.18 --- pear-core/PEAR/PackageFile/v1.php:1.17 Sun Oct 17 17:17:41 2004 +++ pear-core/PEAR/PackageFile/v1.php Tue Oct 19 17:12:27 2004 @@ -578,6 +578,25 @@ return false; } + function dependsOn($package, $channel) + { + if (strtolower($channel) != 'pear.php.net') { + return false; + } + if (!($deps = $this->getDeps())) { + return false; + } + foreach ($deps as $dep) { + if ($dep['type'] != 'pkg') { + continue; + } + if (strtolower($dep['name']) == strtolower($package)) { + return true; + } + } + return false; + } + /** * Reset dependencies prior to adding new ones */ http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/v2.php?r1=1.27&r2=1.28&ty=u Index: pear-core/PEAR/PackageFile/v2.php diff -u pear-core/PEAR/PackageFile/v2.php:1.27 pear-core/PEAR/PackageFile/v2.php:1.28 --- pear-core/PEAR/PackageFile/v2.php:1.27 Tue Oct 19 13:41:35 2004 +++ pear-core/PEAR/PackageFile/v2.php Tue Oct 19 17:12:27 2004 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: v2.php,v 1.27 2004/10/19 17:41:35 cellog Exp $ +// $Id: v2.php,v 1.28 2004/10/19 21:12:27 cellog Exp $ require_once 'PEAR/ErrorStack.php'; require_once 'PEAR/PackageFile/Generator/v2.php'; /** @@ -483,7 +483,7 @@ return '__private'; } if (isset($this->_packageInfo['channel'])) { - return $this->_packageInfo['channel']; + return strtolower($this->_packageInfo['channel']); } return false; } @@ -882,6 +882,93 @@ return false; } + function dependsOn($package, $channel) + { + if (!($deps = $this->getDeps(true))) { + return false; + } + if (isset($deps['required']['package'])) { + if (!isset($deps['required']['package'][0])) { + $deps['required']['package'] = array($deps['required']['package']); + } + foreach ($deps['required']['package'] as $dep) { + $depchannel = isset($dep['channel']) ? $dep['channel'] : '__private'; + if (strtolower($dep['name']) == strtolower($package) && + $depchannel == $channel) { + return true; + } + } + } + if (isset($deps['required']['subpackage'])) { + if (!isset($deps['required']['subpackage'][0])) { + $deps['required']['subpackage'] = array($deps['required']['subpackage']); + } + foreach ($deps['required']['subpackage'] as $dep) { + $depchannel = isset($dep['channel']) ? $dep['channel'] : '__private'; + if (strtolower($dep['name']) == strtolower($package) && + $depchannel == $channel) { + return true; + } + } + } + if (isset($deps['optional']['package'])) { + if (!isset($deps['optional']['package'][0])) { + $deps['optional']['package'] = array($deps['optional']['package']); + } + foreach ($deps['optional']['package'] as $dep) { + $depchannel = isset($dep['channel']) ? $dep['channel'] : '__private'; + if (strtolower($dep['name']) == strtolower($package) && + $depchannel == $channel) { + return true; + } + } + } + if (isset($deps['optional']['subpackage'])) { + if (!isset($deps['optional']['subpackage'][0])) { + $deps['optional']['subpackage'] = array($deps['optional']['subpackage']); + } + foreach ($deps['optional']['subpackage'] as $dep) { + $depchannel = isset($dep['channel']) ? $dep['channel'] : '__private'; + if (strtolower($dep['name']) == strtolower($package) && + $depchannel == $channel) { + return true; + } + } + } + if (isset($deps['group'])) { + if (!isset($deps['group'][0])) { + $dep['group'] = array($deps['group']); + } + foreach ($deps['group'] as $group) { + if (isset($group['package'])) { + if (!is_array($group['package'])) { + $group['package'] = array($group['package']); + } + foreach ($group['package'] as $dep) { + $depchannel = isset($dep['channel']) ? $dep['channel'] : '__private'; + if (strtolower($dep['name']) == strtolower($package) && + $depchannel == $channel) { + return true; + } + } + } + if (isset($group['subpackage'])) { + if (!is_array($group['subpackage'])) { + $group['subpackage'] = array($group['subpackage']); + } + foreach ($group['subpackage'] as $dep) { + $depchannel = isset($dep['channel']) ? $dep['channel'] : '__private'; + if (strtolower($dep['name']) == strtolower($package) && + $depchannel == $channel) { + return true; + } + } + } + } + } + return false; + } + /** * @todo handle <exclude> */ @@ -1179,6 +1266,7 @@ function addPackageDepWithChannel($type, $name, $channel, $min = false, $max = false, $recommended = false) { + $args = func_get_args(); if (count($args) > 6) { $exclude = array_slice($args, 6); if (count($exclude) == 1) { @@ -1205,6 +1293,10 @@ if (!isset($this->_packageInfo['dependencies'][$type]['package'])) { $this->_packageInfo['dependencies'][$type]['package'] = $dep; } else { + if (!isset($this->_packageInfo['dependencies'][$type]['package'][0])) { + $this->_packageInfo['dependencies'][$type]['package'] = + array($this->_packageInfo['dependencies'][$type]['package']); + } $this->_packageInfo['dependencies'][$type]['package'][] = $dep; } } @@ -1231,6 +1323,7 @@ function addSubpackageDepWithChannel($type, $name, $channel, $min = false, $max = false, $recommended = false) { + $args = func_get_args(); if (count($args) > 6) { $exclude = array_slice($args, 6); if (count($exclude) == 1) {
http://cvs.php.net/diff.php/pear-core/PEAR/Command/Install.php?r1=1.61&r2=1.62&ty=u Index: pear-core/PEAR/Command/Install.php diff -u pear-core/PEAR/Command/Install.php:1.61 pear-core/PEAR/Command/Install.php:1.62 --- pear-core/PEAR/Command/Install.php:1.61 Thu Sep 30 15:22:08 2004 +++ pear-core/PEAR/Command/Install.php Tue Oct 19 17:12:27 2004 @@ -16,7 +16,7 @@ // | Author: Stig Sæther Bakken <ssb@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Install.php,v 1.61 2004/09/30 19:22:08 cellog Exp $ +// $Id: Install.php,v 1.62 2004/10/19 21:12:27 cellog Exp $ require_once "PEAR/Command/Common.php"; require_once "PEAR/Installer.php"; @@ -307,7 +307,7 @@ $this->downloader = &new PEAR_Downloader($this->ui, $options, $this->config); $errors = array(); $downloaded = array(); - $this->downloader->download($params); + $downloaded = &$this->downloader->download($params); $errors = $this->downloader->getErrorMsgs(); if (count($errors)) { foreach ($errors as $error) { @@ -317,12 +317,13 @@ $this->ui->outputData($err); return $this->raiseError("$command failed"); } - $downloaded = $this->downloader->getDownloadedPackages(); - $this->installer->sortPkgDeps($downloaded); + $this->installer->sortPackagesForInstall($downloaded); + $this->installer->setDownloadedPackages($downloaded); $reg = &$this->config->getRegistry(); - foreach ($downloaded as $pkg) { + foreach ($downloaded as $param) { PEAR::pushErrorHandling(PEAR_ERROR_RETURN); - $info = $this->installer->install($pkg['info'], $options, $this->config); + $info = $this->installer->install($param->getPackageFile(), $options, + $this->config); PEAR::popErrorHandling(); if (PEAR::isError($info)) { $this->ui->outputData('ERROR: ' .$info->getMessage()); @@ -330,12 +331,12 @@ } if (is_array($info)) { if ($this->config->get('verbose') > 0) { - $channel = $pkg['info']->getChannel(); + $channel = $param->getChannel(); $label = $reg->parsedPackageNameToString( array( 'channel' => $channel, - 'package' => $pkg['info']->getPackage(), - 'version' => $pkg['info']->getVersion(), + 'package' => $param->getPackage(), + 'version' => $param->getVersion(), )); $out = array('data' => "$command ok: $label"); if (isset($info['release_warnings'])) { http://cvs.php.net/diff.php/pear-core/PEAR/Downloader.php?r1=1.35&r2=1.36&ty=u Index: pear-core/PEAR/Downloader.php diff -u pear-core/PEAR/Downloader.php:1.35 pear-core/PEAR/Downloader.php:1.36 --- pear-core/PEAR/Downloader.php:1.35 Mon Oct 18 14:06:02 2004 +++ pear-core/PEAR/Downloader.php Tue Oct 19 17:12:27 2004 @@ -19,11 +19,13 @@ // | Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Downloader.php,v 1.35 2004/10/18 18:06:02 cellog Exp $ +// $Id: Downloader.php,v 1.36 2004/10/19 21:12:27 cellog Exp $ require_once 'PEAR/Common.php'; require_once 'PEAR/Registry.php'; require_once 'PEAR/Dependency.php'; +require_once 'PEAR/Dependency2.php'; +require_once 'PEAR/DependencyDB.php'; require_once 'PEAR/Remote.php'; require_once 'PEAR/PackageFile.php'; require_once 'PEAR/Downloader/Package.php'; @@ -539,249 +541,218 @@ } // }}} - // {{{ sortPkgDeps() /** - * Sort a list of arrays of array(downloaded packagefilename) by dependency. - * - * It also removes duplicate dependencies - * @param array - * @param boolean Sort packages in reverse order if true - * @return array array of array(packagefilename, package.xml contents) + * for BC */ function sortPkgDeps(&$packages, $uninstall = false) { - $ret = array(); - if ($uninstall) { - foreach($packages as $packageinfo) { - $ret[] = array('info' => $packageinfo); + $uninstall ? + $this->sortPackagesForUninstall($packages) : + $this->sortPackagesForInstall($packages); + } + + function _getDepTreeDP($package, $packages, &$deps, &$checked) + { + $pf = $package->getPackageFile(); + $checked[strtolower($package->getChannel())][strtolower($package->getPackage())] + = true; + $pdeps = $pf->getDeps(true); + if (!$pdeps) { + return; + } + if ($pf->getPackagexmlVersion() == '1.0') { + foreach ($pdeps as $dep) { + if ($dep['type'] != 'pkg') { + continue; + } + $deps['pear.php.net'][strtolower($dep['name'])] = true; + foreach ($packages as $p) { + $dep['channel'] = 'pear.php.net'; + $dep['package'] = $dep['name']; + unset($dep['version']); + if ($p->isEqual($dep)) { + if (!isset($checked[strtolower($p->getChannel())] + [strtolower($p->getPackage())])) { + // add the dependency's dependencies to the tree + $this->_getDepTreeDP($p, $packages, $deps, $checked); + } + } + } } } else { - foreach($packages as $packagefile) { - if (!is_array($packagefile)) { - $a = new PEAR_PackageFile($this->config, $this->_debug); - $a = &$a->fromAnyFile($packagefile, PEAR_VALIDATE_INSTALLING); - $ret[] = array('file' => $packagefile, - 'info' => $a, - 'pkg' => $a->getPackage()); + $tdeps = array(); + if (isset($pdeps['required']['package'])) { + $t = $pdeps['required']['package']; + if (!isset($t[0])) { + $t = array($t); + } + $tdeps = array_merge($tdeps, $t); + } + if (isset($pdeps['required']['subpackage'])) { + $t = $pdeps['required']['subpackage']; + if (!isset($t[0])) { + $t = array($t); + } + $tdeps = array_merge($tdeps, $t); + } + if (isset($pdeps['optional']['package'])) { + $t = $pdeps['optional']['package']; + if (!isset($t[0])) { + $t = array($t); + } + $tdeps = array_merge($tdeps, $t); + } + if (isset($pdeps['optional']['subpackage'])) { + $t = $pdeps['optional']['subpackage']; + if (!isset($t[0])) { + $t = array($t); + } + $tdeps = array_merge($tdeps, $t); + } + if (isset($pdeps['group'])) { + if (!isset($pdeps['group'][0])) { + $pdeps['group'] = array($pdeps['group']); + } + foreach ($pdeps['group'] as $group) { + if (isset($group['package'])) { + $t = $group['package']; + if (!isset($t[0])) { + $t = array($t); + } + $tdeps = array_merge($tdeps, $t); + } + if (isset($group['subpackage'])) { + $t = $group['subpackage']; + if (!isset($t[0])) { + $t = array($t); + } + $tdeps = array_merge($tdeps, $t); + } + } + } + foreach ($tdeps as $dep) { + if (!isset($dep['channel'])) { + $depchannel = '__private'; } else { - $ret[] = $packagefile; + $depchannel = $dep['channel']; + } + $deps[$depchannel][strtolower($dep['name'])] = true; + foreach ($packages as $p) { + $dep['channel'] = $depchannel; + $dep['package'] = $dep['name']; + if ($p->isEqual($dep)) { + if (!isset($checked[strtolower($p->getChannel())] + [strtolower($p->getPackage())])) { + // add the dependency's dependencies to the tree + $this->_getDepTreeDP($p, $packages, $deps, $checked); + } + } } } } - $checkdupes = array(); - $newret = array(); - foreach($ret as $i => $p) { - $channel = $p['info']->getChannel(); - if (!isset($checkdupes[$channel . '/' . $p['info']->getPackage()])) { - $checkdupes[$channel . '/' . $p['info']->getPackage()][] = $i; - $newret[] = $p; - } - } - $this->_packageSortTree = $this->_getPkgDepTree($newret); - - $func = $uninstall ? '_sortPkgDepsRev' : '_sortPkgDeps'; - usort($newret, array(&$this, $func)); - $this->_packageSortTree = null; - $packages = $newret; } - // }}} - // {{{ _sortPkgDeps() - /** - * Compare two package's package.xml, and sort - * so that dependencies are installed first + * Sort a list of arrays of array(downloaded packagefilename) by dependency. * - * This is a crude compare, real dependency checking is done on install. - * The only purpose this serves is to make the command-line - * order-independent (you can list a dependent package first, and - * installation occurs in the order required) - * @access private + * It also removes duplicate dependencies + * @param array an array of downloaded PEAR_Downloader_Packages + * @return array array of array(packagefilename, package.xml contents) */ - function _sortPkgDeps($p1, $p2) + function sortPackagesForInstall(&$packages) { - $c1 = $p1['info']->getChannel(); - $c2 = $p2['info']->getChannel(); - $p1name = $c1 . '/' . $p1['info']->getPackage(); - $p2name = $c2 . '/' . $p2['info']->getPackage(); - $p1deps = $this->_getPkgDeps($p1); - $p2deps = $this->_getPkgDeps($p2); - if (!count($p1deps) && !count($p2deps)) { - return 0; // order makes no difference - } - if (!count($p1deps)) { - return -1; // package 2 has dependencies, package 1 doesn't - } - if (!count($p2deps)) { - return 1; // package 1 has dependencies, package 2 doesn't + foreach ($packages as $i => $package) { + $checked = $deps = array(); + $this->_getDepTreeDP($packages[$i], $packages, $deps, $checked); + $this->_depTree[$package->getChannel()][$package->getPackage()] = $deps; } - // both have dependencies - if (in_array($p1name, $p2deps)) { - return -1; // put package 1 first: package 2 depends on package 1 - } - if (in_array($p2name, $p1deps)) { - return 1; // put package 2 first: package 1 depends on package 2 - } - if ($this->_removedDependency($p1name, $p2name)) { - return -1; // put package 1 first: package 2 depends on packages that depend on package 1 - } - if ($this->_removedDependency($p2name, $p1name)) { - return 1; // put package 2 first: package 1 depends on packages that depend on package 2 - } - // doesn't really matter if neither depends on the other - return 0; + usort($packages, array(&$this, '_sortInstall')); } - // }}} - // {{{ _sortPkgDepsRev() + function _dependsOn($a, $b) + { + return $this->_checkDepTree(strtolower($a->getChannel()), strtolower($a->getPackage()), + $b); + } - /** - * Compare two package's package.xml, and sort - * so that dependencies are uninstalled last - * - * This is a crude compare, real dependency checking is done on uninstall. - * The only purpose this serves is to make the command-line - * order-independent (you can list a dependency first, and - * uninstallation occurs in the order required) - * @access private - */ - function _sortPkgDepsRev($p1, $p2) + function _checkDepTree($channel, $package, $b, $checked = array()) { - $c1 = $p1['info']->getChannel(); - $c2 = $p2['info']->getChannel(); - $p1name = $c1 . '/' . $p1['info']->getPackage(); - $p2name = $c2 . '/' . $p2['info']->getPackage(); - $p1deps = $this->_getRevPkgDeps($p1); - $p2deps = $this->_getRevPkgDeps($p2); - if (!count($p1deps) && !count($p2deps)) { - return 0; // order makes no difference + $checked[$channel][$package] = true; + if (!isset($this->_depTree[$channel][$package])) { + return false; + } + if (isset($this->_depTree[$channel][$package][strtolower($b->getChannel())] + [strtolower($b->getPackage())])) { + return true; } - if (!count($p1deps)) { - return 1; // package 2 has dependencies, package 1 doesn't + foreach ($this->_depTree[$channel][$package] as $ch => $packages) { + foreach ($packages as $pa => $true) { + if ($this->_checkDepTree($ch, $pa, $b, $checked)) { + return true; + } + } } - if (!count($p2deps)) { - return -1; // package 2 has dependencies, package 1 doesn't + return false; + } + + function _sortInstall($a, $b) + { + if (!$a->getDeps() && !$b->getDeps()) { + return 0; // neither package has dependencies, order is insignificant } - // both have dependencies - if (in_array($p1name, $p2deps)) { - return 1; // put package 1 last + if ($a->getDeps() && !$b->getDeps()) { + return 1; // $a must be installed after $b because $a has dependencies } - if (in_array($p2name, $p1deps)) { - return -1; // put package 2 last + if (!$a->getDeps() && $b->getDeps()) { + return -1; // $b must be installed after $a because $b has dependencies } - if ($this->_removedDependency($p1name, $p2name)) { - return 1; // put package 1 last: package 2 depends on packages that depend on package 1 + // both packages have dependencies + if ($this->_dependsOn($a, $b)) { + return 1; } - if ($this->_removedDependency($p2name, $p1name)) { - return -1; // put package 2 last: package 1 depends on packages that depend on package 2 + if ($this->_dependsOn($b, $a)) { + return -1; } - // doesn't really matter if neither depends on the other return 0; } - // }}} - // {{{ _getPkgDeps() - /** - * get an array of package dependency names - * @param array - * @return array - * @access private + * Sort a list of arrays of array(downloaded packagefilename) by dependency. + * + * It also removes duplicate dependencies + * @param array an array of PEAR_PackageFile_v[1/2] objects + * @return array array of array(packagefilename, package.xml contents) */ - function _getPkgDeps($p) + function sortPackagesForUninstall(&$packages) { - if (!is_array($p['info'])) { - return $this->_getRevPkgDeps($p); - } - $rel = array_shift($p['info']['releases']); - if (!isset($rel['deps'])) { - return array(); - } - $ret = array(); - foreach($rel['deps'] as $dep) { - if ($dep['type'] == 'pkg') { - $channel = isset($dep['channel']) ? $dep['channel'] : 'pear.php.net'; - $ret[] = $channel . '/' . $dep['name']; - } - } - return $ret; } - // }}} - // {{{ _getPkgDeps() - - /** - * get an array representation of the package dependency tree - * @return array - * @access private - */ - function _getPkgDepTree($packages) + function _uninstallDependsOn($a, $b) { - $tree = array(); - foreach ($packages as $p) { - $channel = $p['info']->getChannel(); - $package = $channel . '/' . $p['info']->getPackage(); - $deps = $this->_getPkgDeps($p); - $tree[$package] = $deps; - } - return $tree; } - // }}} - // {{{ _removedDependency($p1, $p2) - - /** - * get an array of package dependency names for uninstall - * @param string package 1 name - * @param string package 2 name - * @return bool - * @access private - */ - function _removedDependency($p1, $p2) + function _sortUninstall($a, $b) { - if (empty($this->_packageSortTree[$p2])) { - return false; + if (!$a->getDeps() && !$b->getDeps()) { + return 0; // neither package has dependencies, order is insignificant } - if (!in_array($p1, $this->_packageSortTree[$p2])) { - foreach ($this->_packageSortTree[$p2] as $potential) { - if ($this->_removedDependency($p1, $potential)) { - return true; - } - } - return false; + if ($a->getDeps() && !$b->getDeps()) { + return 1; // $a must be installed after $b because $a has dependencies } - return true; - } - - // }}} - // {{{ _getRevPkgDeps() - - /** - * get an array of package dependency names for uninstall - * @param array - * @return array - * @access private - */ - function _getRevPkgDeps($p) - { - if (!$deps = $p['info']->getDeps()) { - return array(); + if (!$a->getDeps() && $b->getDeps()) { + return -1; // $b must be installed after $a because $b has dependencies } - $ret = array(); - foreach($deps as $dep) { - if ($dep['type'] == 'pkg') { - $channel = isset($dep['channel']) ? $dep['channel'] : 'pear.php.net'; - $ret[] = $channel . '/' . $dep['name']; - } + // both packages have dependencies + if ($this->_dependsOn($a, $b)) { + return 1; } - return $ret; + if ($this->_dependsOn($b, $a)) { + return -1; + } + return 0; } - // }}} - - // {{{ downloadHttp() - /** * Download a file through HTTP. Considers suggested file name in * Content-disposition: header and can run a callback function for @@ -953,8 +924,6 @@ } return $dest_file; } - - // }}} } // }}} http://cvs.php.net/diff.php/pear-core/PEAR/Installer.php?r1=1.161&r2=1.162&ty=u Index: pear-core/PEAR/Installer.php diff -u pear-core/PEAR/Installer.php:1.161 pear-core/PEAR/Installer.php:1.162 --- pear-core/PEAR/Installer.php:1.161 Mon Oct 11 11:38:12 2004 +++ pear-core/PEAR/Installer.php Tue Oct 19 17:12:27 2004 @@ -18,7 +18,7 @@ // | Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Installer.php,v 1.161 2004/10/11 15:38:12 cellog Exp $ +// $Id: Installer.php,v 1.162 2004/10/19 21:12:27 cellog Exp $ require_once 'PEAR/Downloader.php'; require_once 'PEAR/Task/Common.php'; @@ -78,11 +78,18 @@ */ var $tmpdir; - /** PEAR_Registry object used by the installer - * @var object + /** + * PEAR_Registry object used by the installer + * @var PEAR_Registry */ var $registry; + /** + * array of PEAR_Downloader_Packages + * @var array + */ + var $_downloadedPackages; + /** List of file transactions queued for an install/upgrade/uninstall. * * Format: @@ -741,6 +748,16 @@ } // }}} + /** + * Set the list of PEAR_Downloader_Package objects to allow more sane + * dependency validation + * @param array + */ + function setDownloadedPackages(&$pkgs) + { + $this->_downloadedPackages = &$pkgs; + } + // {{{ install() /** http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/v1.php?r1=1.17&r2=1.18&ty=u Index: pear-core/PEAR/PackageFile/v1.php diff -u pear-core/PEAR/PackageFile/v1.php:1.17 pear-core/PEAR/PackageFile/v1.php:1.18 --- pear-core/PEAR/PackageFile/v1.php:1.17 Sun Oct 17 17:17:41 2004 +++ pear-core/PEAR/PackageFile/v1.php Tue Oct 19 17:12:27 2004 @@ -578,6 +578,25 @@ return false; } + function dependsOn($package, $channel) + { + if (strtolower($channel) != 'pear.php.net') { + return false; + } + if (!($deps = $this->getDeps())) { + return false; + } + foreach ($deps as $dep) { + if ($dep['type'] != 'pkg') { + continue; + } + if (strtolower($dep['name']) == strtolower($package)) { + return true; + } + } + return false; + } + /** * Reset dependencies prior to adding new ones */ http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/v2.php?r1=1.27&r2=1.28&ty=u Index: pear-core/PEAR/PackageFile/v2.php diff -u pear-core/PEAR/PackageFile/v2.php:1.27 pear-core/PEAR/PackageFile/v2.php:1.28 --- pear-core/PEAR/PackageFile/v2.php:1.27 Tue Oct 19 13:41:35 2004 +++ pear-core/PEAR/PackageFile/v2.php Tue Oct 19 17:12:27 2004 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: v2.php,v 1.27 2004/10/19 17:41:35 cellog Exp $ +// $Id: v2.php,v 1.28 2004/10/19 21:12:27 cellog Exp $ require_once 'PEAR/ErrorStack.php'; require_once 'PEAR/PackageFile/Generator/v2.php'; /** @@ -483,7 +483,7 @@ return '__private'; } if (isset($this->_packageInfo['channel'])) { - return $this->_packageInfo['channel']; + return strtolower($this->_packageInfo['channel']); } return false; } @@ -882,6 +882,93 @@ return false; } + function dependsOn($package, $channel) + { + if (!($deps = $this->getDeps(true))) { + return false; + } + if (isset($deps['required']['package'])) { + if (!isset($deps['required']['package'][0])) { + $deps['required']['package'] = array($deps['required']['package']); + } + foreach ($deps['required']['package'] as $dep) { + $depchannel = isset($dep['channel']) ? $dep['channel'] : '__private'; + if (strtolower($dep['name']) == strtolower($package) && + $depchannel == $channel) { + return true; + } + } + } + if (isset($deps['required']['subpackage'])) { + if (!isset($deps['required']['subpackage'][0])) { + $deps['required']['subpackage'] = array($deps['required']['subpackage']); + } + foreach ($deps['required']['subpackage'] as $dep) { + $depchannel = isset($dep['channel']) ? $dep['channel'] : '__private'; + if (strtolower($dep['name']) == strtolower($package) && + $depchannel == $channel) { + return true; + } + } + } + if (isset($deps['optional']['package'])) { + if (!isset($deps['optional']['package'][0])) { + $deps['optional']['package'] = array($deps['optional']['package']); + } + foreach ($deps['optional']['package'] as $dep) { + $depchannel = isset($dep['channel']) ? $dep['channel'] : '__private'; + if (strtolower($dep['name']) == strtolower($package) && + $depchannel == $channel) { + return true; + } + } + } + if (isset($deps['optional']['subpackage'])) { + if (!isset($deps['optional']['subpackage'][0])) { + $deps['optional']['subpackage'] = array($deps['optional']['subpackage']); + } + foreach ($deps['optional']['subpackage'] as $dep) { + $depchannel = isset($dep['channel']) ? $dep['channel'] : '__private'; + if (strtolower($dep['name']) == strtolower($package) && + $depchannel == $channel) { + return true; + } + } + } + if (isset($deps['group'])) { + if (!isset($deps['group'][0])) { + $dep['group'] = array($deps['group']); + } + foreach ($deps['group'] as $group) { + if (isset($group['package'])) { + if (!is_array($group['package'])) { + $group['package'] = array($group['package']); + } + foreach ($group['package'] as $dep) { + $depchannel = isset($dep['channel']) ? $dep['channel'] : '__private'; + if (strtolower($dep['name']) == strtolower($package) && + $depchannel == $channel) { + return true; + } + } + } + if (isset($group['subpackage'])) { + if (!is_array($group['subpackage'])) { + $group['subpackage'] = array($group['subpackage']); + } + foreach ($group['subpackage'] as $dep) { + $depchannel = isset($dep['channel']) ? $dep['channel'] : '__private'; + if (strtolower($dep['name']) == strtolower($package) && + $depchannel == $channel) { + return true; + } + } + } + } + } + return false; + } + /** * @todo handle <exclude> */ @@ -1179,6 +1266,7 @@ function addPackageDepWithChannel($type, $name, $channel, $min = false, $max = false, $recommended = false) { + $args = func_get_args(); if (count($args) > 6) { $exclude = array_slice($args, 6); if (count($exclude) == 1) { @@ -1205,6 +1293,10 @@ if (!isset($this->_packageInfo['dependencies'][$type]['package'])) { $this->_packageInfo['dependencies'][$type]['package'] = $dep; } else { + if (!isset($this->_packageInfo['dependencies'][$type]['package'][0])) { + $this->_packageInfo['dependencies'][$type]['package'] = + array($this->_packageInfo['dependencies'][$type]['package']); + } $this->_packageInfo['dependencies'][$type]['package'][] = $dep; } } @@ -1231,6 +1323,7 @@ function addSubpackageDepWithChannel($type, $name, $channel, $min = false, $max = false, $recommended = false) { + $args = func_get_args(); if (count($args) > 6) { $exclude = array_slice($args, 6); if (count($exclude) == 1) {