From f33c5896aceb2c7d8cd71fa2b286793376cb9bc7 Mon Sep 17 00:00:00 2001 From: "Tomas V.V.Cox" Date: Fri, 7 Jun 2002 18:07:38 +0000 Subject: [PATCH] Experimental dependencies database handling functions (not yet in production) --- pear/PEAR/Registry.php | 113 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 3 deletions(-) diff --git a/pear/PEAR/Registry.php b/pear/PEAR/Registry.php index 42b9c8d0cd..2f337e4806 100644 --- a/pear/PEAR/Registry.php +++ b/pear/PEAR/Registry.php @@ -14,6 +14,8 @@ // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Stig Bakken | +// | Tomas V.V.Cox | +// | | // +----------------------------------------------------------------------+ // // $Id$ @@ -208,7 +210,7 @@ class PEAR_Registry extends PEAR */ function _lock($mode = LOCK_EX) { - if(!strstr(php_uname(), 'Windows 95/98')) { + if(!strstr(php_uname(), 'Windows 95/98')) { if ($mode != LOCK_UN && is_resource($this->lock_fp)) { // XXX does not check type of lock (LOCK_SH/LOCK_EX) return true; @@ -224,11 +226,11 @@ class PEAR_Registry extends PEAR } $open_mode = 'r'; } - + @ini_set('track_errors', true); $this->lock_fp = @fopen($this->lockfile, $open_mode); @ini_restore('track_errors'); - + if (!is_resource($this->lock_fp)) { return $this->raiseError("could not create lock file: $php_errormsg"); } @@ -421,6 +423,111 @@ class PEAR_Registry extends PEAR } // }}} + + /** + Experimental dependencies database handling functions (not yet in production) + **/ + + function rebuildDepsFile() + { + $packages = $this->listPackages(); + $files = array(); + foreach ($packages as $package) { + $deps = $this->packageInfo($package, 'release_deps'); + $this->depUpdatePackage($package, $deps); + } + // XXX Change with serialize + write + return $this->dependencies; + } + /* + 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( + 0 => 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] + 0 => 'Package Name', + 1 => 3 // (int)key + ), + ), + ) + ) + */ + function _addDependency($package, $deps) + { + if (!is_array($deps) || !count($deps)) { + return; + } + $data = &$this->dependencies; + foreach ($deps as $dep) { + if ($dep && $dep['type'] == 'pkg' && isset($dep['name'])) { + settype($data['deps'][$dep['name']], 'array'); + $data['deps'][$dep['name']][] = array('depend' => $package, + 'version' => $dep['version'], + 'rel' => $dep['rel']); + $data['pkgs'][$package][] = array($dep['name'], key($data['deps'][$dep['name']])); + } + } + } + + function depRemovePackage($package) + { + $data = &$this->dependencies; + // Other packages depends on this package, can't be removed + if (isset($data['deps'][$package])) { + return $data['deps'][$package]; + } + if (isset($data['pkgs'][$package])) { + foreach ($data['pkgs'][$package] as $remove) { + // remove the dependency + unset($data['deps'][$remove[0]][$remove[1]]); + // if no more dependencies, remove the subject too + if (!count($data['deps'][$remove[0]])) { + unset($data['deps'][$remove[0]]); + } + } + // remove the package from the index list + unset($data['pkgs'][$package]); + } + return $data; + } + + function depUpdatePackage($package, $new_version, $release_deps) + { + $data = &$this->dependencies; + // Other packages depend on this package, check deps + if (isset($data['deps'][$package])) { + foreach ($data['deps'][$package] as $dep) { + $require = $dep['version']; + $relation = $dep['rel']; + if ($relation != 'has') { + if (!version_compare($new_version, $require, $relation)) { + $fails[] = $dep; + } + } + } + if (isset($fails)) { + return $fails; + } + } + $this->_addDependency($package, $release_deps); + } } ?> \ No newline at end of file -- 2.40.0