--- Install_1.5.3.php	2007-04-28 15:45:54.000000000 +0200
+++ Install_packagingroot2.php	2007-04-28 21:26:28.000000000 +0200
@@ -167,12 +167,7 @@
                 'installroot' => array(
                     'shortopt' => 'R',
                     'arg' => 'DIR',
-                    'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT), use packagingroot for RPM',
-                    ),
-                'packagingroot' => array(
-                    'shortopt' => 'P',
-                    'arg' => 'DIR',
-                    'doc' => 'root directory used when packaging files, like RPM packaging',
+                    'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
                     ),
                 'ignore-errors' => array(
                     'doc' => 'force install even if there were errors',
@@ -228,7 +223,7 @@
                 'installroot' => array(
                     'shortopt' => 'R',
                     'arg' => 'DIR',
-                    'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT), use packagingroot for RPM',
+                    'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
                     ),
                 'ignore-errors' => array(
                     'doc' => 'force install even if there were errors',
@@ -532,13 +527,21 @@
         } else {
             $packages = $params;
         }
+        $reg = &$this->config->getRegistry();
+        $instreg = &$reg; // instreg used to check if package is installed
         if (isset($options['installroot']) && isset($options['packagingroot'])) {
             return $this->raiseError('ERROR: cannot use both --installroot and --packagingroot');
         }
-        if (isset($options['packagingroot']) && $this->config->get('verbose') > 2) {
-            $this->ui->outputData('using package root: ' . $options['packagingroot']);
+        if (isset($options['packagingroot']) && !isset($options['upgrade'])) {
+            $packrootphp_dir = $this->installer->_prependPath(
+                $this->config->get('php_dir', null, 'pear.php.net'),
+                $options['packagingroot']);
+            $instreg = new PEAR_Registry($packrootphp_dir); // other instreg!
+
+            if ($this->config->get('verbose') > 2) {
+                $this->ui->outputData('using package root: ' . $options['packagingroot']);
+            }
         }
-        $reg = &$this->config->getRegistry();
  
         $abstractpackages = array();
         $otherpackages = array();
@@ -560,9 +563,9 @@
                     $otherpackages[] = $param;
                     continue;
                 }
-                if ($reg->packageExists($pf->getPackage(), $pf->getChannel()) &&
+                if ($instreg->packageExists($pf->getPackage(), $pf->getChannel()) &&
                       version_compare($pf->getVersion(), 
-                      $reg->packageInfo($pf->getPackage(), 'version', $pf->getChannel()),
+                      $instreg->packageInfo($pf->getPackage(), 'version', $pf->getChannel()),
                       '<=')) {
                     if ($this->config->get('verbose')) {
                         $this->ui->outputData('Ignoring installed package ' .
@@ -597,7 +600,7 @@
                         // do not filter out install groups
                         continue;
                     }
-                    if ($reg->packageExists($package['package'], $package['channel'])) {
+                    if ($instreg->packageExists($package['package'], $package['channel'])) {
                         if ($this->config->get('verbose')) {
                             $this->ui->outputData('Ignoring installed package ' .
                                 $reg->parsedPackageNameToString($package, true));
@@ -652,14 +655,6 @@
             return true;
         }
         $extrainfo = array();
-        if (isset($options['packagingroot'])) {
-            $packrootphp_dir = $this->installer->_prependPath(
-                $this->config->get('php_dir', null, 'pear.php.net'),
-                $options['packagingroot']);
-            $instreg = new PEAR_Registry($packrootphp_dir);
-        } else {
-            $instreg = $reg;
-        }
         foreach ($downloaded as $param) {
             PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
             $info = $this->installer->install($param, $options);
@@ -782,14 +777,6 @@
                                   '#featurename"';
                     }
                 }
-                if (isset($options['installroot'])) {
-                    $reg = &$this->config->getRegistry();
-                }
-                if (isset($options['packagingroot'])) {
-                    $instreg = new PEAR_Registry($packrootphp_dir);
-                } else {
-                    $instreg = $reg;
-                }
                 $pkg = &$instreg->getPackage($param->getPackage(), $param->getChannel());
                 // $pkg may be NULL if install is a 'fake' install via --packagingroot
                 if (is_object($pkg)) {
