cvs: pear-core / package-PEAR.xml package2.xml /PEAR Installer.php /PEAR/Installer/Role Cfg.php /tests/PEAR_Installer
test_install_cfgrole_upgrade.phpt

From: Date: Tue, 13 May 2008 22:46:07 +0000
Subject: cvs: pear-core / package-PEAR.xml package2.xml /PEAR Installer.php /PEAR/Installer/Role Cfg.php /tests/PEAR_Installer
test_install_cfgrole_upgrade.phpt
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-7551@lists.php.net to get a copy of this message
cellog Tue May 13 22:46:07 2008 UTC Added files: /pear-core/tests/PEAR_Installer test_install_cfgrole_upgrade.phpt Modified files: /pear-core package-PEAR.xml package2.xml /pear-core/PEAR Installer.php /pear-core/PEAR/Installer/Role Cfg.php Log: * Fix Bug #12960 role=cfg should automatically replace file if it has not been modified [cellog]

http://cvs.php.net/viewvc.cgi/pear-core/package-PEAR.xml?r1=1.532&r2=1.533&diff_format=u Index: pear-core/package-PEAR.xml diff -u pear-core/package-PEAR.xml:1.532 pear-core/package-PEAR.xml:1.533 --- pear-core/package-PEAR.xml:1.532 Tue May 13 21:28:19 2008 +++ pear-core/package-PEAR.xml Tue May 13 22:46:07 2008 @@ -93,6 +93,7 @@ <state>stable</state> <notes> * Implement Request #13375: install-pear.php should have option to set cfg_dir [timj] + * Fix Bug #12960 role=cfg should automatically replace file if it has not been modified [cellog] * Fix Bug #13031 PEAR fails to authenticate when doing upgrade-all on non-default channel [timj] * Fix Bug #13033 Signature to PEAR_REST_XX::listAll() changes between REST1.0 and 1.1 [timj] * Fix Bug #13059 Invalid release type causes Undefined Property notice [gwynne, dufuz] http://cvs.php.net/viewvc.cgi/pear-core/package2.xml?r1=1.432&r2=1.433&diff_format=u Index: pear-core/package2.xml diff -u pear-core/package2.xml:1.432 pear-core/package2.xml:1.433 --- pear-core/package2.xml:1.432 Tue May 13 21:28:19 2008 +++ pear-core/package2.xml Tue May 13 22:46:07 2008 @@ -98,6 +98,7 @@ <license uri="http://www.php.net/license">PHP License</license> <notes> * Implement Request #13375: install-pear.php should have option to set cfg_dir [timj] + * Fix Bug #12960 role=cfg should automatically replace file if it has not been modified [cellog] * Fix Bug #13031 PEAR fails to authenticate when doing upgrade-all on non-default channel [timj] * Fix Bug #13033 Signature to PEAR_REST_XX::listAll() changes between REST1.0 and 1.1 [timj] * Fix Bug #13059 Invalid release type causes Undefined Property notice [gwynne, dufuz] http://cvs.php.net/viewvc.cgi/pear-core/PEAR/Installer.php?r1=1.252&r2=1.253&diff_format=u Index: pear-core/PEAR/Installer.php diff -u pear-core/PEAR/Installer.php:1.252 pear-core/PEAR/Installer.php:1.253 --- pear-core/PEAR/Installer.php:1.252 Tue May 13 21:28:19 2008 +++ pear-core/PEAR/Installer.php Tue May 13 22:46:07 2008 @@ -18,7 +18,7 @@ * @author Greg Beaver <cellog@php.net> * @copyright 1997-2008 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Installer.php,v 1.252 2008/05/13 21:28:19 cellog Exp $ + * @version CVS: $Id: Installer.php,v 1.253 2008/05/13 22:46:07 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 0.1 */ @@ -473,8 +473,9 @@ * @param array options from command-line * @access private */ - function _installFile2(&$pkg, $file, $atts, $tmp_path, $options) + function _installFile2(&$pkg, $file, &$real_atts, $tmp_path, $options) { + $atts = $real_atts; if (!isset($this->_registry)) { $this->_registry = &$this->config->getRegistry(); } @@ -602,6 +603,8 @@ } } } + } else { + $real_atts['attribs']['md5sum'] = md5_file($dest_file); } // }}} // {{{ set file permissions http://cvs.php.net/viewvc.cgi/pear-core/PEAR/Installer/Role/Cfg.php?r1=1.5&r2=1.6&diff_format=u Index: pear-core/PEAR/Installer/Role/Cfg.php diff -u pear-core/PEAR/Installer/Role/Cfg.php:1.5 pear-core/PEAR/Installer/Role/Cfg.php:1.6 --- pear-core/PEAR/Installer/Role/Cfg.php:1.5 Thu Mar 13 15:45:18 2008 +++ pear-core/PEAR/Installer/Role/Cfg.php Tue May 13 22:46:07 2008 @@ -1,89 +1,107 @@ -<?php -/** - * PEAR_Installer_Role_Cfg - * - * PHP versions 4 and 5 - * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. - * - * @category pear - * @package PEAR - * @author Greg Beaver <cellog@php.net> - * @copyright 2007-2008 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Cfg.php,v 1.5 2008/03/13 15:45:18 timj Exp $ - * @link http://pear.php.net/package/PEAR - * @since File available since Release 1.7.0 - */ - -/** - * @category pear - * @package PEAR - * @author Greg Beaver <cellog@php.net> - * @copyright 2007-2008 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: @package_version@ - * @link http://pear.php.net/package/PEAR - * @since Class available since Release 1.7.0 - */ -class PEAR_Installer_Role_Cfg extends PEAR_Installer_Role_Common -{ - var $installer; - /** - * Do any unusual setup here - * @param PEAR_Installer - * @param PEAR_PackageFile_v2 - * @param array file attributes - * @param string file name - */ - function setup(&$installer, $pkg, $atts, $file) - { - $this->installer = &$installer; - } - - function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null) - { - $test = parent::processInstallation($pkg, $atts, $file, $tmp_path, $layer); - if (@file_exists($test[2])) { - // configuration has already been installed, check for mods - if (md5_file($test[2]) !== md5_file($test[3])) { - // configuration has been modified, so save our version as - // configfile-version - $old = $test[2]; - $test[2] .= '.new-' . $pkg->getVersion(); - // backup original and re-install it - PEAR::pushErrorHandling(PEAR_ERROR_RETURN); - $tmpcfg = $this->config->get('temp_dir'); - $newloc = System::mkdir(array('-p', $tmpcfg)); - if (!$newloc) { - // try temp_dir - $newloc = System::mktemp(array('-d')); - if (!$newloc || PEAR::isError($newloc)) { - PEAR::popErrorHandling(); - return PEAR::raiseError('Could not save existing configuration file '. - $old . ', unable to install. Please set temp_dir ' . - 'configuration variable to a writeable location and try again'); - } - } else { - $newloc = $tmpcfg; - } +<?php +/** + * PEAR_Installer_Role_Cfg + * + * PHP versions 4 and 5 + * + * LICENSE: This source file is subject to version 3.0 of the PHP license + * that is available through the world-wide-web at the following URI: + * http://www.php.net/license/3_0.txt. If you did not receive a copy of + * the PHP License and are unable to obtain it through the web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category pear + * @package PEAR + * @author Greg Beaver <cellog@php.net> + * @copyright 2007-2008 The PHP Group + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version CVS: $Id: Cfg.php,v 1.6 2008/05/13 22:46:07 cellog Exp $ + * @link http://pear.php.net/package/PEAR + * @since File available since Release 1.7.0 + */ + +/** + * @category pear + * @package PEAR + * @author Greg Beaver <cellog@php.net> + * @copyright 2007-2008 The PHP Group + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version Release: @package_version@ + * @link http://pear.php.net/package/PEAR + * @since Class available since Release 1.7.0 + */ +class PEAR_Installer_Role_Cfg extends PEAR_Installer_Role_Common +{ + /** + * @var PEAR_Installer + */ + var $installer; + /** + * the md5 of the original file + * + * @var unknown_type + */ + var $md5 = null; + /** + * Do any unusual setup here + * @param PEAR_Installer + * @param PEAR_PackageFile_v2 + * @param array file attributes + * @param string file name + */ + function setup(&$installer, $pkg, $atts, $file) + { + $this->installer = &$installer; + $reg = &$this->installer->config->getRegistry(); + $package = $reg->getPackage($pkg->getPackage(), $pkg->getChannel()); + if ($package) { + $filelist = $package->getFilelist(); + if (isset($filelist[$file]) && isset($filelist[$file]['md5sum'])) { + $this->md5 = $filelist[$file]['md5sum']; + } + } + } + + function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null) + { + $test = parent::processInstallation($pkg, $atts, $file, $tmp_path, $layer); + if (@file_exists($test[2])) { + $md5 = md5_file($test[2]); + // configuration has already been installed, check for mods + if ($md5 !== $this->md5 && $md5 !== md5_file($test[3])) { + // configuration has been modified, so save our version as + // configfile-version + $old = $test[2]; + $test[2] .= '.new-' . $pkg->getVersion(); + // backup original and re-install it + PEAR::pushErrorHandling(PEAR_ERROR_RETURN); + $tmpcfg = $this->config->get('temp_dir'); + $newloc = System::mkdir(array('-p', $tmpcfg)); + if (!$newloc) { + // try temp_dir + $newloc = System::mktemp(array('-d')); + if (!$newloc || PEAR::isError($newloc)) { + PEAR::popErrorHandling(); + return PEAR::raiseError('Could not save existing configuration file '. + $old . ', unable to install. Please set temp_dir ' . + 'configuration variable to a writeable location and try again'); + } + } else { + $newloc = $tmpcfg; + } $temp_file = $newloc . DIRECTORY_SEPARATOR . uniqid('savefile'); - if (!@copy($old, $temp_file)) { - PEAR::popErrorHandling(); - return PEAR::raiseError('Could not save existing configuration file '. - $old . ', unable to install. Please set temp_dir ' . - 'configuration variable to a writeable location and try again'); - } - PEAR::popErrorHandling(); + if (!@copy($old, $temp_file)) { + PEAR::popErrorHandling(); + return PEAR::raiseError('Could not save existing configuration file '. + $old . ', unable to install. Please set temp_dir ' . + 'configuration variable to a writeable location and try again'); + } + PEAR::popErrorHandling(); $this->installer->addFileOperation('rename', array($temp_file, $old, false)); - $this->installer->addFileOperation('delete', array($temp_file)); - } - } - return $test; - } -} -?> + $this->installer->addFileOperation('delete', array($temp_file)); + } + } + return $test; + } +} +?> http://cvs.php.net/viewvc.cgi/pear-core/tests/PEAR_Installer/test_install_cfgrole_upgrade.phpt?view=markup&rev=1.1 Index: pear-core/tests/PEAR_Installer/test_install_cfgrole_upgrade.phpt +++ pear-core/tests/PEAR_Installer/test_install_cfgrole_upgrade.phpt --TEST-- PEAR_Installer->install() with cfg file role, change detection on upgrade --SKIPIF-- <?php if (!getenv('PHP_PEAR_RUNTESTS')) { echo 'skip'; } ?> --FILE-- <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'setup.php.inc'; $_test_dep->setPEARVersion('1.7.0'); $_test_dep->setPHPVersion('4.3.11'); $c1 = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'packages'. DIRECTORY_SEPARATOR . 'cfg1.xml'; $c2 = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'packages'. DIRECTORY_SEPARATOR . 'cfg2.xml'; copy($c1, $c1 = $temp_path . DIRECTORY_SEPARATOR . 'p1.xml'); copy($c2, $c2 = $temp_path . DIRECTORY_SEPARATOR . 'p2.xml'); file_put_contents($temp_path . DIRECTORY_SEPARATOR . 'foo.php', 'start'); $dp = &new PEAR_Downloader($fakelog, array('offline' => true), $config); $phpunit->assertNoErrors('after create'); $result = $dp->download(array($c1)); $after = $dp->getDownloadedPackages(); $installer->setOptions($dp->getOptions()); $installer->sortPackagesForInstall($result); $installer->setDownloadedPackages($result); $phpunit->assertNoErrors('set of downloaded packages'); $ret = &$installer->install($result[0], $dp->getOptions()); $phpunit->assertNoErrors('after install'); $phpunit->assertEquals(array ( 'attribs' => array ( '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' => 'PEAR', 'channel' => 'pear.php.net', 'summary' => 'PEAR Base System', 'description' => 'The PEAR package contains:', 'lead' => array ( 'name' => 'Stig Bakken', 'user' => 'ssb', 'email' => 'stig@php.net', 'active' => 'yes', ), 'date' => '2004-09-30', 'version' => array ( 'release' => '1.4.0', 'api' => '1.4.0', ), 'stability' => array ( 'release' => 'stable', 'api' => 'stable', ), 'license' => array ( 'attribs' => array ( 'uri' => 'http://www.php.net/license/3_0.txt', ), '_content' => 'PHP License', ), 'notes' => 'Installer Roles/Tasks:', 'contents' => array ( 'dir' => array ( 'attribs' => array ( 'name' => '/', ), 'file' => array ( 'attribs' => array ( 'name' => 'foo.php', 'role' => 'cfg', ), ), ), ), 'dependencies' => array ( 'required' => array ( 'php' => array ( 'min' => '4.2', ), 'pearinstaller' => array ( 'min' => '1.7.0', ), ), ), 'phprelease' => '', 'filelist' => array ( 'foo.php' => array ( 'name' => 'foo.php', 'role' => 'cfg', 'md5sum' => md5('start'), 'installed_as' => $temp_path . DIRECTORY_SEPARATOR . 'cfg' . DIRECTORY_SEPARATOR . 'PEAR' . DIRECTORY_SEPARATOR . 'foo.php', ), ), '_lastversion' => NULL, 'dirtree' => array ( $temp_path . DIRECTORY_SEPARATOR . 'cfg' . DIRECTORY_SEPARATOR . 'PEAR' => true, ), 'old' => array ( 'version' => '1.4.0', 'release_date' => '2004-09-30', 'release_state' => 'stable', 'release_license' => 'PHP License', 'release_notes' => 'Installer Roles/Tasks:', 'release_deps' => array ( 0 => array ( 'type' => 'php', 'rel' => 'ge', 'version' => '4.2', 'optional' => 'no', ), 1 => array ( 'type' => 'pkg', 'channel' => 'pear.php.net', 'name' => 'PEAR', 'rel' => 'ge', 'version' => '1.7.0', 'optional' => 'no', ), ), 'maintainers' => array ( 0 => array ( 'name' => 'Stig Bakken', 'email' => 'stig@php.net', 'active' => 'yes', 'handle' => 'ssb', 'role' => 'lead', ), ), ), 'xsdversion' => '2.0', ), $ret, 'return of install'); $phpunit->assertFileExists($temp_path . DIRECTORY_SEPARATOR . 'cfg' . DIRECTORY_SEPARATOR . 'PEAR' . DIRECTORY_SEPARATOR . 'foo.php', 'installed file'); $fakelog->getLog(); file_put_contents($temp_path . DIRECTORY_SEPARATOR . 'foo.php', 'next'); $dp = &new test_PEAR_Downloader($fakelog, array('upgrade' => true), $config); $result = $dp->download(array($c2)); $after = $dp->getDownloadedPackages(); $installer->setOptions($dp->getOptions()); $installer->sortPackagesForInstall($result); $installer->setDownloadedPackages($result); $phpunit->assertNoErrors('set of downloaded packages'); $ret = &$installer->install($result[0], $dp->getOptions()); $phpunit->assertNoErrors('after install'); $phpunit->assertFileExists($temp_path . DIRECTORY_SEPARATOR . 'cfg' . DIRECTORY_SEPARATOR . 'PEAR' . DIRECTORY_SEPARATOR . 'foo.php', 'installed file'); $phpunit->assertFileNotExists($temp_path . DIRECTORY_SEPARATOR . 'cfg' . DIRECTORY_SEPARATOR . 'PEAR' . DIRECTORY_SEPARATOR . 'foo.php.new-1.4.1', 'installed file'); $fakelog->getLog(); echo 'tests done'; ?> --CLEAN-- <?php require_once dirname(__FILE__) . '/teardown.php.inc'; ?> --EXPECT-- tests done
« previous php.pear.core (#7551) next »