]> granicus.if.org Git - php/commitdiff
- MFH
authorPierre Joye <pajoye@php.net>
Tue, 8 Jul 2003 20:39:46 +0000 (20:39 +0000)
committerPierre Joye <pajoye@php.net>
Tue, 8 Jul 2003 20:39:46 +0000 (20:39 +0000)
pear/PEAR.php
pear/PEAR/Command/Registry.php
pear/PEAR/Config.php
pear/PEAR/Dependency.php
pear/PEAR/Installer.php
pear/PEAR/Registry.php
pear/install-pear.php
pear/package-PEAR.xml
pear/package.dtd

index 3062194d5cbcd29c9e37fb48d4bc33907b8370b0..5305537fb17c956b37d06ba036aac67e19b87b6d 100644 (file)
@@ -225,7 +225,7 @@ class PEAR
      * @param   mixed $data   the value to test
      * @param   int   $code   if $data is an error object, return true
      *                        only if $code is a string and
-     *                        $obj->getMessage() == $code or 
+     *                        $obj->getMessage() == $code or
      *                        $code is an integer and $obj->getCode() == $code
      * @access  public
      * @return  bool    true if parameter is an error
@@ -477,7 +477,7 @@ class PEAR
      * @see PEAR::setErrorHandling
      * @since PHP 4.0.5
      */
-    function &raiseError($message = null,
+    function raiseError($message = null,
                          $code = null,
                          $mode = null,
                          $options = null,
@@ -621,6 +621,10 @@ class PEAR
     function loadExtension($ext)
     {
         if (!extension_loaded($ext)) {
+            // if either returns true dl() will produce a FATAL error, stop that
+            if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
+                return false;
+            }
             if (OS_WINDOWS) {
                 $suffix = '.dll';
             } elseif (PHP_OS == 'HP-UX') {
index a4a40c81110d8d7275a76c9575c37ad4a02b31e3..31ebd8b65353061020b1df1ebd34e96560cc3999 100644 (file)
@@ -291,6 +291,7 @@ installed package.'
                         } else {
                             $pstr = '';
                         }
+                        $i = 0;
                         foreach ($info[$key] as $p) {
                             if ($debug < 2 && $p['type'] != "class") {
                                 continue;
index 44d23e21177beb512c45f618041805714cd5bbc0..fb12ded5f61191f6a20a12c5631e9abae9e28bf2 100644 (file)
@@ -558,11 +558,11 @@ class PEAR_Config extends PEAR
      *
      * @access public.
      */
-    function writeConfigFile($file = null, $layer = 'user')
+    function writeConfigFile($file = null, $layer = 'user', $data = null)
     {
         if ($layer == 'both' || $layer == 'all') {
             foreach ($this->files as $type => $file) {
-                $err = $this->writeConfigFile($file, $type);
+                $err = $this->writeConfigFile($file, $type, $data);
                 if (PEAR::isError($err)) {
                     return $err;
                 }
@@ -575,7 +575,7 @@ class PEAR_Config extends PEAR
         if ($file === null) {
             $file = $this->files[$layer];
         }
-        $data = $this->configuration[$layer];
+        $data = ($data === null) ? $this->configuration[$layer] : $data;
         $this->_encodeOutput($data);
         if (!@System::mkDir("-p " . dirname($file))) {
             return $this->raiseError("could not create directory: " . dirname($file));
@@ -641,6 +641,19 @@ class PEAR_Config extends PEAR
         return $data;
     }
 
+    // }}}
+    // {{{ getConfFile(layer)
+    /**
+    * Gets the file used for storing the config for a layer
+    *
+    * @param string $layer 'user' or 'system'
+    */
+
+    function getConfFile($layer)
+    {
+        return $this->files[$layer];
+    }
+
     // }}}
     // {{{ _encodeOutput(&data)
 
@@ -1008,8 +1021,7 @@ class PEAR_Config extends PEAR
     function removeLayer($layer)
     {
         if (isset($this->configuration[$layer])) {
-            unset($this->configuration[$layer]);
-            $this->layers = array_keys($this->configuration);
+            $this->configuration[$layer] = array();
             return true;
         }
         return false;
@@ -1027,9 +1039,9 @@ class PEAR_Config extends PEAR
      *
      * @access public
      */
-    function store($layer = 'user')
+    function store($layer = 'user', $data = null)
     {
-        return $this->writeConfigFile(null, $layer);
+        return $this->writeConfigFile(null, $layer, $data);
     }
 
     // }}}
index b9c70ef3189e5a72199e0a1269ad33ef0232ae96..c4c27605043107e984f58dd3cdb8b782ebdde7f5 100644 (file)
@@ -146,6 +146,35 @@ class PEAR_Dependency
         return PEAR_DEPENDENCY_BAD_DEPENDENCY;
     }
 
+    /**
+     * Check package dependencies on uninstall
+     *
+     * @param string $error     The resultant error string
+     * @param string $name      Name of the package to test
+     *
+     * @return bool true if there were errors
+     */
+    function checkPackageUninstall(&$error, $package)
+    {
+        $error = null;
+        $packages = $this->registry->listPackages();
+        foreach ($packages as $pkg) {
+            if ($pkg == $package) {
+                continue;
+            }
+            $deps = $this->registry->packageInfo($pkg, 'release_deps');
+            if (empty($deps)) {
+                continue;
+            }
+            foreach ($deps as $dep) {
+                if ($dep['type'] == 'pkg' && strcasecmp($dep['name'], $package) == 0) {
+                    $error .= "Package '$pkg' depends on '$package'\n";
+                }
+            }
+        }
+        return ($error) ? true : false;
+    }
+
     /**
      * Extension dependencies check method
      *
index 58541c5a67d34b5fbd39958fa13833927e71d9a6..9f95e25aa6794d05c034707c0ec370cc4d0618bd 100644 (file)
@@ -773,7 +773,13 @@ class PEAR_Installer extends PEAR_Common
             $this->installroot = '';
         }
         $this->registry = &new PEAR_Registry($php_dir);
-
+        if (empty($options['nodeps'])) {
+            $depchecker = &new PEAR_Dependency($this->registry);
+            $error = $depchecker->checkPackageUninstall($errors, $package);
+            if ($error) {
+                return $this->raiseError($errors . 'uninstall failed');
+            }
+        }
         // Delete the files
         if (PEAR::isError($err = $this->_deletePackageFiles($package))) {
             $this->rollbackFileTransaction();
index 27a5f9649c04b357ee7d0b633893d8c6a8fe8810..a93713f1846ebac25c5d5f8cf5acc0c3daaa8ac5 100644 (file)
@@ -522,181 +522,6 @@ class PEAR_Registry extends PEAR
 
     // }}}
 
-    // {{{ rebuildDepsFile()
-
-    /**
-    Experimental dependencies database handling functions (not yet in production)
-
-    TODO:
-        - test it
-        - Think on the "not" dep relation. It's supposed that a package can't
-          be installed if conflicts with another. The problem comes when the
-          user forces the installation and later upgrades it
-    **/
-
-    // XXX Terrible slow, a lot of read, lock, write, unlock
-    function rebuildDepsFile()
-    {
-        // Init the file with empty data
-        $error = $this->_depWriteDepDB(array());
-        if (PEAR::isError($error)) {
-            return $error;
-        }
-        $packages = $this->listPackages();
-        foreach ($packages as $package) {
-            $deps = $this->packageInfo($package, 'release_deps');
-            $error = $this->setPackageDep($package, $deps);
-            if (PEAR::isError($error)) {
-                return $error;
-            }
-        }
-        return true;
-    }
-
-    function &_depGetDepDB()
-    {
-        if (!$fp = fopen($this->depfile, 'r')) {
-            return $this->raiseError("Could not open dependencies file `".$this->depfile."'");
-        }
-        $data = fread($fp, filesize($this->depfile));
-        fclose($fp);
-        return unserialize($data);
-    }
-
-    function _depWriteDepDB(&$deps)
-    {
-        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
-            return $e;
-        }
-        if (!$fp = fopen($this->depfile, 'wb')) {
-            $this->_unlock();
-            return $this->raiseError("Could not open dependencies file `".$this->depfile."' for writting");
-        }
-        fwrite($fp, serialize($deps));
-        fclose($fp);
-        $this->_unlock();
-        return true;
-    }
-
-    /*
-    The data structure is as follows:
-    $dep_db = array(
-        // Other packages depends in some manner on this packages
-        'deps' => array(
-            'Package Name' => array(
-                0 => array(
-                    // This package depends on 'Package Name'
-                    'depend' => 'Package',
-                    // Which version 'Package' needs of 'Package Name'
-                    'version' => '1.0',
-                    // The requirement (version_compare() operator)
-                    'rel' => 'ge'
-                ),
-            ),
-        )
-        // This packages are dependant on other packages
-        'pkgs' => array(
-            'Package Dependant' => array(
-                // This is a index list with paths over the 'deps' array for quick
-                // searching things like "what dependecies has this package?"
-                // $dep_db['deps']['Package Name'][3]
-                'Package Name' => 3 // key in array ['deps']['Package Name']
-            ),
-        )
-    )
-
-    Note: It only supports package dependencies no other type
-    */
-
-    function removePackageDep($package)
-    {
-        $data = &$this->_depGetDepDB();
-        if (PEAR::isError($data)) {
-            return $data;
-        }
-        // Other packages depends on this package, can't be removed
-        if (isset($data['deps'][$package])) {
-            return $data['deps'][$package];
-        }
-        // The package depends on others, remove those dependencies
-        if (isset($data['pkgs'][$package])) {
-            foreach ($data['pkgs'][$package] as $pkg => $key) {
-                // remove the dependency
-                unset($data['deps'][$pkg][$key]);
-                // if no more dependencies, remove the subject too
-                if (!count($data['deps'][$pkg])) {
-                    unset($data['deps'][$pkg]);
-                }
-            }
-            // remove the package from the index list
-            unset($data['pkgs'][$package]);
-        }
-        return $this->_depWriteDepDB();
-    }
-
-    /**
-    * Update or insert a the dependencies of a package, prechecking
-    * that the package won't break any dependency in the process
-    */
-    function setPackageDep($package, $new_version, $rel_deps = array())
-    {
-        $data = &$this->_depGetDepDB();
-        if (PEAR::isError($deps)) {
-            return $deps;
-        }
-        // Other packages depend on this package, check deps. Mostly for
-        // handling uncommon cases like:
-        // <dep type='pkg' rel='lt' version='1.0'>Foo</dep> and we are trying to
-        // update Foo to version 2.0
-        if (isset($data['deps'][$package])) {
-            foreach ($data['deps'][$package] as $dep) {
-                $require  = $dep['version'];
-                $relation = $dep['rel'];
-                // XXX (cox) Possible problem with changes in the way
-                // PEAR_Dependency::checkPackage() works
-                if ($relation != 'has') {
-                    if (!version_compare("$new_version", "$require", $relation)) {
-                        $fails[] = $dep;
-                    }
-                }
-            }
-            if (isset($fails)) {
-                return $fails;
-            }
-        }
-
-        // This package has no dependencies
-        if (!is_array($rel_deps) || !count($rel_deps)) {
-            return true;
-        }
-
-        // The package depends on others, register that
-        foreach ($rel_deps as $dep) {
-            // We only support deps of type 'pkg's
-            if ($dep && $dep['type'] == 'pkg' && isset($dep['name'])) {
-                $write = array('depend'  => $package,
-                               'version' => $dep['version'],
-                               'rel'     => $dep['rel']);
-                settype($data['deps'][$dep['name']], 'array');
-
-                // The dependency already exists, update it
-                if (isset($data['pkgs'][$package][$dep['name']])) {
-                    $key = $data['pkgs'][$package][$dep['name']];
-                    $data['deps'][$dep['name']][$key] = $write;
-
-                // New dependency, insert it
-                } else {
-                    $data['deps'][$dep['name']][] = $write;
-                    $key = key($data['deps'][$dep['name']]);
-                    settype($data['pkgs'][$package], 'array');
-                    $data['pkgs'][$package][$dep['name']] = $key;
-                }
-            }
-        }
-        return $this->_depWriteDepDB($data);
-    }
-
-    // }}}
 }
 
 ?>
index 216fbff32fd00f2966cb352dd0009710e80159fa..1dd72d3a26447d86877c74e74d3639670503c7b8 100644 (file)
@@ -1,8 +1,5 @@
 <?php
 
-// XXX TODO write the config file at the end as for example
-// in 'system' layer
-
 /* $Id$ */
 
 $pear_dir = dirname(__FILE__);
@@ -112,6 +109,19 @@ foreach ($install_files as $package => $instfile) {
         $new_ver = $reg->packageInfo($package, 'version');
         $ui->outputData(sprintf("[PEAR] %-15s- installed: %s", $package, $new_ver));
     }
+    if ($package == 'PEAR') {
+        if (is_file($ufile = $config->getConfFile('user'))) {
+            $ui->outputData('Warning! a PEAR user config file already exists from ' .
+                            'a previous PEAR installation at ' .
+                            "'$ufile'. You may probably want to remove it.");
+        }
+        $ui->outputData('Writing PEAR system config file at: ' . $config->files['system']);
+        $ui->outputData('You may want to add: ' . $config->get('php_dir') . ' to your php.ini include_path');
+        $config->set('verbose', 1, 'default');
+        foreach ($config->getKeys() as $key) {
+            $data[$key] = $config->get($key);
+        }
+        $config->store('system', $data);
+    }
 }
-
 ?>
index 5aa793ba18e80066da4ebf3b1b86905a59e3a0d3..f88fc848eb845b20901cd71efab46fe992efbe18 100644 (file)
     </maintainer>
   </maintainers>
   <release>
-    <version>1.2b2</version>
+    <version>1.2b3</version>
     <state>beta</state>
-    <date>2003-06-23</date>
+    <date>2003-07-08</date>
     <notes>
 * Changed license from PHP 2.02 to 3.0
 * Added support for optional dependencies
 * Made upgrade and uninstall package case insensitive
 * pear makerpm, now works and generates a better system independant spec file
 * pear install|build &lt;pecl-package&gt;, now exposes the compilation progress
+* Installer now checks dependencies on package uninstall
 * Added new pear bundle command, which downloads and uncompress a &lt;pecl-package&gt;.
 The main purpouse of this command is for easily adding extensions to the PHP sources
 before compiling it.
index a570325899e0c51ff8be7f7dcbeac5ffe21edcd6..f67bdab606c55e6ceb0aff84ddad988544561d6e 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-     $Id: package.dtd,v 1.27.4.6 2003-07-02 10:38:07 pajoye Exp $
+     $Id: package.dtd,v 1.27.4.7 2003-07-08 20:39:45 pajoye Exp $
 
      This is the PEAR package description, version 1.0.
      It should be used with the informal public identifier: