summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas V.V.Cox <cox@php.net>2003-07-07 15:42:58 +0000
committerTomas V.V.Cox <cox@php.net>2003-07-07 15:42:58 +0000
commit01795e2ae1952c86f3dd350441c2986640cfa111 (patch)
tree2433e7025889cf3ece38c6af1b6fe2a35d1378ad
parent6d563b3bdcdef50fd3248054b9b8a909bf7ca470 (diff)
downloadphp-git-01795e2ae1952c86f3dd350441c2986640cfa111.tar.gz
Moved dependecy db code to its own file
-rw-r--r--pear/PEAR/Registry.php175
1 files changed, 0 insertions, 175 deletions
diff --git a/pear/PEAR/Registry.php b/pear/PEAR/Registry.php
index 27a5f9649c..a93713f184 100644
--- a/pear/PEAR/Registry.php
+++ b/pear/PEAR/Registry.php
@@ -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);
- }
-
- // }}}
}
?>