cvs: pear-core /PEAR Installer.php /PEAR/PackageFile v1.php v2.php /tests/PEAR_Installer setup.php.inc test_install_subpackage.phpt
test_install_subpackage_fail.phpt test_uninstall_complex_params_invalid1.phpt test_uninstall_complex_params_invalid2.phpt
/tests/PEAR_Installer/test_install_subpackage bar.php foo.php package.xml subpackage.xml

From: Date: Wed, 20 Oct 2004 16:23:12 +0000
Subject: cvs: pear-core /PEAR Installer.php /PEAR/PackageFile v1.php v2.php /tests/PEAR_Installer setup.php.inc test_install_subpackage.phpt
test_install_subpackage_fail.phpt test_uninstall_complex_params_invalid1.phpt test_uninstall_complex_params_invalid2.phpt
/tests/PEAR_Installer/test_install_subpackage bar.php foo.php package.xml subpackage.xml
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-1086@lists.php.net to get a copy of this message
cellog Wed Oct 20 12:23:12 2004 EDT Added files: /pear-core/tests/PEAR_Installer test_install_subpackage.phpt test_install_subpackage_fail.phpt /pear-core/tests/PEAR_Installer/test_install_subpackage bar.php foo.php package.xml subpackage.xml Modified files: /pear-core/PEAR Installer.php /pear-core/PEAR/PackageFile v1.php v2.php /pear-core/tests/PEAR_Installer setup.php.inc test_uninstall_complex_params_invalid1.phpt test_uninstall_complex_params_invalid2.phpt Log: implement subpackage dependency properly (subpackages are just like packages, except they are allowed to conflict with installed parent package files)

http://cvs.php.net/diff.php/pear-core/PEAR/Installer.php?r1=1.165&r2=1.166&ty=u Index: pear-core/PEAR/Installer.php diff -u pear-core/PEAR/Installer.php:1.165 pear-core/PEAR/Installer.php:1.166 --- pear-core/PEAR/Installer.php:1.165 Wed Oct 20 11:24:22 2004 +++ pear-core/PEAR/Installer.php Wed Oct 20 12:23:11 2004 @@ -18,7 +18,7 @@ // | Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Installer.php,v 1.165 2004/10/20 15:24:22 cellog Exp $ +// $Id: Installer.php,v 1.166 2004/10/20 16:23:11 cellog Exp $ require_once 'PEAR/Downloader.php'; require_once 'PEAR/Task/Common.php'; @@ -758,6 +758,11 @@ $this->_downloadedPackages = &$pkgs; } + function getInstallPackages() + { + return $this->_downloadedPackages; + } + // {{{ install() /** @@ -851,22 +856,54 @@ unset($test[$file]); } } else { + if ($channel != 'pear.php.net') { + continue; + } if (strtolower($info) == strtolower($pkgname)) { unset($test[$file]); } } } if (sizeof($test)) { - $msg = "$channel/$pkgname: conflicting files found:\n"; - $longest = max(array_map("strlen", array_keys($test))); - $fmt = "%${longest}s (%s)\n"; - foreach ($test as $file => $info) { - if (is_array($info)) { - $info = $info[0] . '/' . $info[1]; + $pkgs = $this->getInstallPackages(); + $found = false; + foreach ($pkgs as $param) { + if ($pkg->isSubpackageOf($param)) { + $found = true; + break; + } + } + if ($found) { + // subpackages can conflict with earlier versions of parent packages + $tmp = $test; + foreach ($tmp as $file => $info) { + if (is_array($info)) { + if (strtolower($info[1]) == strtolower($param->getPackage()) && + strtolower($info[0]) == strtolower($param->getChannel())) { + unset($test[$file]); + } + } else { + if (strtolower($param->getChannel()) != 'pear.php.net') { + continue; + } + if (strtolower($info) == strtolower($param->getPackage())) { + unset($test[$file]); + } + } + } + } + if (sizeof($test)) { + $msg = "$channel/$pkgname: conflicting files found:\n"; + $longest = max(array_map("strlen", array_keys($test))); + $fmt = "%${longest}s (%s)\n"; + foreach ($test as $file => $info) { + if (is_array($info)) { + $info = $info[0] . '/' . $info[1]; + } + $msg .= sprintf($fmt, $file, $info); } - $msg .= sprintf($fmt, $file, $info); + return $this->raiseError($msg); } - return $this->raiseError($msg); } } } http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/v1.php?r1=1.19&r2=1.20&ty=u Index: pear-core/PEAR/PackageFile/v1.php diff -u pear-core/PEAR/PackageFile/v1.php:1.19 pear-core/PEAR/PackageFile/v1.php:1.20 --- pear-core/PEAR/PackageFile/v1.php:1.19 Tue Oct 19 18:27:55 2004 +++ pear-core/PEAR/PackageFile/v1.php Wed Oct 20 12:23:11 2004 @@ -583,6 +583,16 @@ return false; } + function isSubpackageOf($p) + { + return $p->isSubpackage($this); + } + + function isSubpackage($p) + { + return false; + } + function dependsOn($package, $channel) { if (strtolower($channel) != 'pear.php.net') { http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/v2.php?r1=1.29&r2=1.30&ty=u Index: pear-core/PEAR/PackageFile/v2.php diff -u pear-core/PEAR/PackageFile/v2.php:1.29 pear-core/PEAR/PackageFile/v2.php:1.30 --- pear-core/PEAR/PackageFile/v2.php:1.29 Tue Oct 19 18:27:55 2004 +++ pear-core/PEAR/PackageFile/v2.php Wed Oct 20 12:23:11 2004 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: v2.php,v 1.29 2004/10/19 22:27:55 cellog Exp $ +// $Id: v2.php,v 1.30 2004/10/20 16:23:11 cellog Exp $ require_once 'PEAR/ErrorStack.php'; require_once 'PEAR/PackageFile/Generator/v2.php'; /** @@ -238,6 +238,9 @@ } if ($contents = $this->getContents()) { $ret = array(); + if (!isset($contents['dir']['file'][0])) { + $contents['dir']['file'] = array($contents['dir']['file']); + } foreach ($contents['dir']['file'] as $file) { $name = $file['attribs']['name']; if (!$preserve) { @@ -882,6 +885,79 @@ return false; } + function isSubpackageOf($p) + { + return $p->isSubpackage($this); + } + + /** + * Determines whether the passed in package is a subpackage of this package + * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2 + */ + function isSubpackage($p) + { + if (isset($this->_packageInfo['dependencies']['required']['subpackage'])) { + $sub = $this->_packageInfo['dependencies']['required']['subpackage']; + if (!isset($sub[0])) { + $sub = array($sub); + } + foreach ($sub as $dep) { + if ($dep['name'] == $p->getPackage()) { + if (isset($dep['channel'])) { + if ($dep['channel'] == $p->getChannel()) { + return true; + } + } else { + return true; + } + } + } + } + if (isset($this->_packageInfo['dependencies']['optional']['subpackage'])) { + $sub = $this->_packageInfo['dependencies']['optional']['subpackage']; + if (!isset($sub[0])) { + $sub = array($sub); + } + foreach ($sub as $dep) { + if ($dep['name'] == $p->getPackage()) { + if (isset($dep['channel'])) { + if ($dep['channel'] == $p->getChannel()) { + return true; + } + } else { + return true; + } + } + } + } + if (isset($this->_packageInfo['dependencies']['group'])) { + $group = $this->_packageInfo['dependencies']['group']; + if (!isset($group[0])) { + $group = array($group); + } + foreach ($group as $deps) { + if (isset($deps['subpackage'])) { + $sub = $deps['subpackage']; + if (!isset($sub[0])) { + $sub = array($sub); + } + foreach ($sub as $dep) { + if ($dep['name'] == $p->getPackage()) { + if (isset($dep['channel'])) { + if ($dep['channel'] == $p->getChannel()) { + return true; + } + } else { + return true; + } + } + } + } + } + } + return false; + } + function dependsOn($package, $channel) { if (!($deps = $this->getDeps(true))) { http://cvs.php.net/diff.php/pear-core/tests/PEAR_Installer/setup.php.inc?r1=1.1&r2=1.2&ty=u Index: pear-core/tests/PEAR_Installer/setup.php.inc diff -u pear-core/tests/PEAR_Installer/setup.php.inc:1.1 pear-core/tests/PEAR_Installer/setup.php.inc:1.2 --- pear-core/tests/PEAR_Installer/setup.php.inc:1.1 Wed Oct 20 11:36:49 2004 +++ pear-core/tests/PEAR_Installer/setup.php.inc Wed Oct 20 12:23:12 2004 @@ -112,4 +112,5 @@ $downloader = &new test_PEAR_Downloader($fakelog, $options, $config); return $downloader; } +$installer = &new test_PEAR_Installer($fakelog); ?> \ No newline at end of file http://cvs.php.net/diff.php/pear-core/tests/PEAR_Installer/test_uninstall_complex_params_invalid1.phpt?r1=1.1&r2=1.2&ty=u Index: pear-core/tests/PEAR_Installer/test_uninstall_complex_params_invalid1.phpt diff -u pear-core/tests/PEAR_Installer/test_uninstall_complex_params_invalid1.phpt:1.1 pear-core/tests/PEAR_Installer/test_uninstall_complex_params_invalid1.phpt:1.2 --- pear-core/tests/PEAR_Installer/test_uninstall_complex_params_invalid1.phpt:1.1 Wed Oct 20 11:36:49 2004 +++ pear-core/tests/PEAR_Installer/test_uninstall_complex_params_invalid1.phpt Wed Oct 20 12:23:12 2004 @@ -42,9 +42,8 @@ $params[] = $reg->getPackage('next'); $params[] = $reg->getPackage('foo'); -$dl = &new PEAR_Installer($fakelog); -$dl->setDownloadedPackages($params); -$dl->uninstall('foo'); +$installer->setDownloadedPackages($params); +$installer->uninstall('foo'); $phpunit->assertErrors(array( array('package' => 'PEAR_Error', 'message' => 'channel://pear.php.net/foo cannot be uninstalled, other installed packages depend on this package') @@ -52,8 +51,8 @@ $phpunit->assertEquals( array ( 0 => array ( - 0 => 'channel://pear.php.net/foo (version >= 1.0) is required by package "channel://pear.php.net/next"', - 1 => true, + 0 => 0, + 1 => 'channel://pear.php.net/foo (version >= 1.0) is required by package "channel://pear.php.net/next"', ), ), $fakelog->getLog(), 'foo'); echo 'tests done'; http://cvs.php.net/diff.php/pear-core/tests/PEAR_Installer/test_uninstall_complex_params_invalid2.phpt?r1=1.1&r2=1.2&ty=u Index: pear-core/tests/PEAR_Installer/test_uninstall_complex_params_invalid2.phpt diff -u pear-core/tests/PEAR_Installer/test_uninstall_complex_params_invalid2.phpt:1.1 pear-core/tests/PEAR_Installer/test_uninstall_complex_params_invalid2.phpt:1.2 --- pear-core/tests/PEAR_Installer/test_uninstall_complex_params_invalid2.phpt:1.1 Wed Oct 20 11:36:49 2004 +++ pear-core/tests/PEAR_Installer/test_uninstall_complex_params_invalid2.phpt Wed Oct 20 12:23:12 2004 @@ -42,9 +42,8 @@ $params[] = $reg->getPackage('foo'); $params[] = $reg->getPackage('bar'); -$dl = &new PEAR_Installer($fakelog); -$dl->setDownloadedPackages($params); -$dl->uninstall('foo'); +$installer->setDownloadedPackages($params); +$installer->uninstall('foo'); $phpunit->assertErrors(array( array('package' => 'PEAR_Error', 'message' => 'channel://pear.php.net/foo cannot be uninstalled, other installed packages depend on this package') @@ -52,8 +51,8 @@ $phpunit->assertEquals( array ( 0 => array ( - 0 => 'channel://pear.php.net/foo (version >= 1.0) is required by package "channel://pear.php.net/next"', - 1 => true, + 0 => 0, + 1 => 'channel://pear.php.net/foo (version >= 1.0) is required by package "channel://pear.php.net/next"', ), ), $fakelog->getLog(), 'foo'); echo 'tests done'; http://cvs.php.net/co.php/pear-core/tests/PEAR_Installer/test_install_subpackage.phpt?r=1.1&p=1 Index: pear-core/tests/PEAR_Installer/test_install_subpackage.phpt +++ pear-core/tests/PEAR_Installer/test_install_subpackage.phpt --TEST-- PEAR_Installer->install() (subpackage that conflicts) --SKIPIF-- <?php if (!getenv('PHP_PEAR_RUNTESTS')) { echo 'skip'; } ?> --FILE-- <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'setup.php.inc'; require_once 'PEAR/PackageFile.php'; require_once 'PEAR/PackageFile/v1.php'; $pf = new PEAR_PackageFile($config); $package = $pf->fromPackageFile(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test_install_subpackage' . DIRECTORY_SEPARATOR . 'package.xml', PEAR_VALIDATE_INSTALLING); $subpackage = $pf->fromPackageFile(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test_install_subpackage' . DIRECTORY_SEPARATOR . 'subpackage.xml', PEAR_VALIDATE_INSTALLING); $oldpackage = new PEAR_PackageFile_v1; $oldpackage->setPackage('foo'); $oldpackage->setSummary('foo'); $oldpackage->setDescription('foo'); $oldpackage->setDate('2004-10-01'); $oldpackage->setLicense('PHP License'); $oldpackage->setVersion('1.0'); $oldpackage->setState('stable'); $oldpackage->setNotes('foo'); $oldpackage->addFile('/', 'foo.php', array('role' => 'php')); $oldpackage->addFile('/', 'bar.php', array('role' => 'php')); $oldpackage->addMaintainer('lead', 'cellog', 'Greg Beaver', 'cellog@php.net'); $oldpackage->addPackageDep('bar', '1.0', 'ge'); $reg = &$config->getRegistry(); $reg->addPackage2($oldpackage); $phpunit->assertNoErrors('setup'); $params = array(&$package, &$subpackage); $installer->setDownloadedPackages($params); $installer->install($subpackage, array('upgrade' => true)); $phpunit->assertNoErrors('install'); echo 'tests done'; ?> --EXPECT-- tests done http://cvs.php.net/co.php/pear-core/tests/PEAR_Installer/test_install_subpackage_fail.phpt?r=1.1&p=1 Index: pear-core/tests/PEAR_Installer/test_install_subpackage_fail.phpt +++ pear-core/tests/PEAR_Installer/test_install_subpackage_fail.phpt --TEST-- PEAR_Installer->install() (subpackage that conflicts) --SKIPIF-- <?php if (!getenv('PHP_PEAR_RUNTESTS')) { echo 'skip'; } ?> --FILE-- <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'setup.php.inc'; require_once 'PEAR/PackageFile.php'; require_once 'PEAR/PackageFile/v1.php'; $pf = new PEAR_PackageFile($config); $package = $pf->fromPackageFile(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test_install_subpackage' . DIRECTORY_SEPARATOR . 'package.xml', PEAR_VALIDATE_INSTALLING); $subpackage = $pf->fromPackageFile(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'test_install_subpackage' . DIRECTORY_SEPARATOR . 'subpackage.xml', PEAR_VALIDATE_INSTALLING); $oldpackage = new PEAR_PackageFile_v1; $oldpackage->setPackage('foo'); $oldpackage->setSummary('foo'); $oldpackage->setDescription('foo'); $oldpackage->setDate('2004-10-01'); $oldpackage->setLicense('PHP License'); $oldpackage->setVersion('1.0'); $oldpackage->setState('stable'); $oldpackage->setNotes('foo'); $oldpackage->addFile('/', 'foo.php', array('role' => 'php')); $oldpackage->addFile('/', 'bar.php', array('role' => 'php')); $oldpackage->addMaintainer('lead', 'cellog', 'Greg Beaver', 'cellog@php.net'); $oldpackage->addPackageDep('bar', '1.0', 'ge'); $reg = &$config->getRegistry(); $reg->addPackage2($oldpackage); $phpunit->assertNoErrors('setup'); $params = array(&$subpackage); $installer->setDownloadedPackages($params); $installer->install($subpackage, array('upgrade' => true)); $phpunit->assertErrors(array( array('package' => 'PEAR_Error', 'message' => 'pear.php.net/bar: conflicting files found: bar.php (foo) ')), 'install'); $params = array(&$oldpackage, &$subpackage); $installer->setDownloadedPackages($params); $installer->install($subpackage, array('upgrade' => true)); $phpunit->assertErrors(array( array('package' => 'PEAR_Error', 'message' => 'pear.php.net/bar: conflicting files found: bar.php (foo) ')), 'install 2');echo 'tests done'; ?> --EXPECT-- tests done http://cvs.php.net/co.php/pear-core/tests/PEAR_Installer/test_install_subpackage/bar.php?r=1.1&p=1 Index: pear-core/tests/PEAR_Installer/test_install_subpackage/bar.php +++ pear-core/tests/PEAR_Installer/test_install_subpackage/bar.php <?php ?> http://cvs.php.net/co.php/pear-core/tests/PEAR_Installer/test_install_subpackage/foo.php?r=1.1&p=1 Index: pear-core/tests/PEAR_Installer/test_install_subpackage/foo.php +++ pear-core/tests/PEAR_Installer/test_install_subpackage/foo.php <?php ?> http://cvs.php.net/co.php/pear-core/tests/PEAR_Installer/test_install_subpackage/package.xml?r=1.1&p=1 Index: pear-core/tests/PEAR_Installer/test_install_subpackage/package.xml +++ pear-core/tests/PEAR_Installer/test_install_subpackage/package.xml <?xml version="1.0"?> <package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> <name>foo</name> <channel>pear.php.net</channel> <summary>foo</summary> <description>foo</description> <lead> <name>Greg Beaver</name> <user>cellog</user> <email>cellog@php.net</email> <active>yes</active> </lead> <date>2004-10-01</date> <version> <release>1.1</release> <api>1.1</api> </version> <stability> <release>stable</release> <api>stable</api> </stability> <license>PHP License</license> <notes>foo</notes> <contents> <dir name="/"> <file name="foo.php" role="php" /> </dir> <!-- / --> </contents> <dependencies> <required> <php> <min>4.3.0</min> <max>6.0.0</max> </php> <pearinstaller> <min>1.4.0dev13</min> </pearinstaller> <subpackage> <name>bar</name> <channel>pear.php.net</channel> </subpackage> </required> </dependencies> <phprelease /> </package> http://cvs.php.net/co.php/pear-core/tests/PEAR_Installer/test_install_subpackage/subpackage.xml?r=1.1&p=1 Index: pear-core/tests/PEAR_Installer/test_install_subpackage/subpackage.xml +++ pear-core/tests/PEAR_Installer/test_install_subpackage/subpackage.xml <?xml version="1.0"?> <package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> <name>bar</name> <channel>pear.php.net</channel> <summary>bar</summary> <description>bar</description> <lead> <name>Greg Beaver</name> <user>cellog</user> <email>cellog@php.net</email> <active>yes</active> </lead> <date>2004-10-01</date> <version> <release>1.0</release> <api>1.0</api> </version> <stability> <release>stable</release> <api>stable</api> </stability> <license>PHP License</license> <notes>foo</notes> <contents> <dir name="/"> <file name="bar.php" role="php" /> </dir> <!-- / --> </contents> <dependencies> <required> <php> <min>4.3.0</min> <max>6.0.0</max> </php> <pearinstaller> <min>1.4.0dev13</min> </pearinstaller> </required> </dependencies> <phprelease /> </package>
« previous php.pear.core (#1086) next »