Permalink
Browse files

Fixed Bug #17350: "pear install --force" doesn't uninstall files from…

… previous pkg versions [dufuz]

# Clean up old package files even on install --force, make install and upgrade share code

git-svn-id: http://svn.php.net/repository/pear/pear-core/pear/pear-core/trunk@312944 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 3eb12ec commit 24853732b26053dc4d0a644dc61165e306ab2b4d dufuz committed Jul 5, 2011
View
@@ -1272,55 +1272,48 @@ function install($pkgfile, $options = array())
$this->startFileTransaction();
- if (empty($options['upgrade']) && empty($options['soft'])) {
- // checks to do only when installing new packages
- if ($channel == 'pecl.php.net') {
- $test = $installregistry->packageExists($name, $channel);
- if (!$test) {
- $test = $installregistry->packageExists($name, 'pear.php.net');
- }
- } else {
- $test = $installregistry->packageExists($name, $channel);
+ // Figure out what channel to use and if the package exists or not
+ $usechannel = $channel;
+ if ($channel == 'pecl.php.net') {
+ $test = $installregistry->packageExists($name, $channel);
+ if (!$test) {
+ $test = $installregistry->packageExists($name, 'pear.php.net');
+ $usechannel = 'pear.php.net';
}
+ } else {
+ $test = $installregistry->packageExists($name, $channel);
+ }
+ // checks to do only when installing new packages
+ if (empty($options['upgrade']) && empty($options['soft'])) {
if (empty($options['force']) && $test) {
return $this->raiseError("$channel/$name is already installed");
}
} else {
- $usechannel = $channel;
- if ($channel == 'pecl.php.net') {
- $test = $installregistry->packageExists($name, $channel);
- if (!$test) {
- $test = $installregistry->packageExists($name, 'pear.php.net');
- $usechannel = 'pear.php.net';
- }
- } else {
- $test = $installregistry->packageExists($name, $channel);
- }
-
+ // Upgrade
if ($test) {
$v1 = $installregistry->packageInfo($name, 'version', $usechannel);
$v2 = $pkg->getVersion();
$cmp = version_compare("$v1", "$v2", 'gt');
if (empty($options['force']) && !version_compare("$v2", "$v1", 'gt')) {
return $this->raiseError("upgrade to a newer version ($v2 is not newer than $v1)");
}
+ }
+ }
- if (empty($options['register-only'])) {
- // when upgrading, remove old release's files first:
- if (PEAR::isError($err = $this->_deletePackageFiles($name, $usechannel,
- true))) {
- if (!isset($options['ignore-errors'])) {
- return $this->raiseError($err);
- }
+ // Do cleanups for upgrade and install, remove old release's files first
+ if ($test && empty($options['register-only'])) {
+ $err = $this->_deletePackageFiles($name, $usechannel, true);
+ if (PEAR::isError($err)) {
+ if (!isset($options['ignore-errors'])) {
+ return $this->raiseError($err);
+ }
- if (!isset($options['soft'])) {
- $this->log(0, 'WARNING: ' . $err->getMessage());
- }
- } else {
- $backedup = $err;
- }
+ if (!isset($options['soft'])) {
+ $this->log(0, 'WARNING: ' . $err->getMessage());
}
+ } else {
+ $backedup = $err;
}
}
View
@@ -71,6 +71,23 @@ class System
function _parseArgs($argv, $short_options, $long_options = null)
{
if (!is_array($argv) && $argv !== null) {
+ /*
+ // Quote all items that are a short option
+ $av = preg_split('/(\A| )--?[a-z0-9]+[ =]?((?<!\\\\)((,\s*)|((?<!,)\s+))?)/i', $argv, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE);
+ $offset = 0;
+ foreach ($av as $a) {
+ $b = trim($a[0]);
+ if ($b{0} == '"' || $b{0} == "'") {
+ continue;
+ }
+
+ $escape = escapeshellarg($b);
+ $pos = $a[1] + $offset;
+ $argv = substr_replace($argv, $escape, $pos, strlen($b));
+ $offset += 2;
+ }
+ */
+
// Find all items, quoted or otherwise
preg_match_all("/(?:[\"'])(.*?)(?:['\"])|([^\s]+)/", $argv, $av);
$argv = $av[1];
View
@@ -105,6 +105,7 @@ http://pear.php.net/dtd/package-1.0.xsd">
Prior to this it was possible to do that by passing all values in as an array (related to #18362, #18440)
Bug Fixes:
+ * Bug #17350: "pear install --force" doesn't uninstall files from previous pkg versions [dufuz]
* Bug #18362: A whitespace TEMP_DIR path breaks install/upgrade functionality [dufuz]
* Bug #18440: bad tmp folder path on install : Unable to create path for C:/Program/tmp [dufuz]
* Bug #18581: "config-get -c" not returning channel's configuration when using alias [dufuz]
View
@@ -109,6 +109,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
Prior to this it was possible to do that by passing all values in as an array (related to #18362, #18440)
Bug Fixes:
+ * Bug #17350: "pear install --force" doesn't uninstall files from previous pkg versions [dufuz]
* Bug #18362: A whitespace TEMP_DIR path breaks install/upgrade functionality [dufuz]
* Bug #18440: bad tmp folder path on install : Unable to create path for C:/Program/tmp [dufuz]
* Bug #18581: "config-get -c" not returning channel's configuration when using alias [dufuz]
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>Test_Package99</name>
+ <channel>__uri</channel>
+ <summary>A test package</summary>
+ <description>Whatever</description>
+ <lead>
+ <name>Example User</name>
+ <user>example</user>
+ <email>example@example.comk</email>
+ <active>yes</active>
+ </lead>
+ <date>2007-02-03</date>
+ <version>
+ <release>1.0.0</release>
+ <api>1.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <license>Foo License</license>
+ <notes>This is the first release.
+ </notes>
+ <contents>
+ <dir name="/">
+ <file role="php" name="test1.php" />
+ <file role="php" name="test2.php" />
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>4.3.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.0</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <phprelease />
+</package>
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>Test_Package99</name>
+ <channel>__uri</channel>
+ <summary>A test package</summary>
+ <description>Whatever</description>
+ <lead>
+ <name>Example User</name>
+ <user>example</user>
+ <email>example@example.comk</email>
+ <active>yes</active>
+ </lead>
+ <date>2007-02-03</date>
+ <version>
+ <release>1.1.0</release>
+ <api>1.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <license>Foo License</license>
+ <notes>This is the first release.
+ </notes>
+ <contents>
+ <dir name="/">
+ <file role="php" name="test1.php" />
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>4.3.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.0</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <phprelease />
+</package>
@@ -0,0 +1,66 @@
+--TEST--
+PEAR_Installer - Bug #17350: "pear install --force" doesn't uninstall files from previous pkg versions
+--SKIPIF--
+<?php
+if (!getenv('PHP_PEAR_RUNTESTS')) {
+ echo 'skip';
+}
+?>
+--FILE--
+<?php
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'setup.php.inc';
+
+$dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bug17350' . DIRECTORY_SEPARATOR;
+$p1 = $dir . 'Test_Package99-1.0.0' . DIRECTORY_SEPARATOR . 'package.xml';
+$p2 = $dir . 'Test_Package99-1.1.0' . DIRECTORY_SEPARATOR . 'package.xml';
+
+$_test_dep->setPHPVersion('5.3.0');
+$_test_dep->setPEARVersion('1.9.0');
+$_test_dep->setExtensions(array('pcre' => '1.0'));
+
+
+$dp = &new test_PEAR_Downloader($fakelog, array(), $config);
+$phpunit->assertNoErrors('after create');
+
+$result = $dp->download(array($p1));
+$dlpackages = $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');
+$fakelog->getLog();
+
+$phpunit->assertFileExists($php_dir . DIRECTORY_SEPARATOR . 'test1.php', 'test1.php exists');
+$phpunit->assertFileExists($php_dir . DIRECTORY_SEPARATOR . 'test2.php', 'test2.php exists');
+
+$_test_dep->setPHPVersion('5.3.0');
+$_test_dep->setPEARVersion('1.9.0');
+$_test_dep->setExtensions(array('pcre' => '1.0'));
+
+$dp = &new test_PEAR_Downloader($fakelog, array('force' => true), $config);
+$phpunit->assertNoErrors('after create 2');
+
+$result = $dp->download(array($p2));
+$dlpackages = $dp->getDownloadedPackages();
+
+$installer->setOptions($dp->getOptions());
+$installer->sortPackagesForInstall($result);
+$installer->setDownloadedPackages($result);
+$phpunit->assertNoErrors('set of downloaded packages 2');
+$ret = $installer->install($result[0], $dp->getOptions());
+$phpunit->assertNoErrors('after install 2');
+
+$phpunit->assertFileExists($php_dir . DIRECTORY_SEPARATOR . 'test1.php', 'test1.php exists');
+$phpunit->assertFileNotExists($php_dir . DIRECTORY_SEPARATOR . 'test2.php', 'test2.php does not exists');
+
+echo 'tests done';
+?>
+--CLEAN--
+<?php
+require_once dirname(__FILE__) . '/teardown.php.inc';
+?>
+--EXPECT--
+tests done

0 comments on commit 2485373

Please sign in to comment.