]> granicus.if.org Git - php/commitdiff
* nuked PEAR_Packlist class and added PEAR_Registry instead
authorStig Bakken <ssb@php.net>
Sun, 28 Oct 2001 23:22:17 +0000 (23:22 +0000)
committerStig Bakken <ssb@php.net>
Sun, 28 Oct 2001 23:22:17 +0000 (23:22 +0000)
pear/PEAR/Packlist.php [deleted file]
pear/PEAR/Registry.php [new file with mode: 0644]
pear/scripts/pear.in

diff --git a/pear/PEAR/Packlist.php b/pear/PEAR/Packlist.php
deleted file mode 100644 (file)
index f898968..0000000
+++ /dev/null
@@ -1,254 +0,0 @@
-<?php
-//
-// +----------------------------------------------------------------------+
-// | PHP version 4.0                                                      |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2001 The PHP Group                                |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 2.02 of the PHP license,      |
-// | that is bundled with this package in the file LICENSE, and is        |
-// | available at through the world-wide-web at                           |
-// | http://www.php.net/license/2_02.txt.                                 |
-// | If you did not receive a copy of the PHP license and are unable to   |
-// | obtain it through the world-wide-web, please send a note to          |
-// | license@php.net so we can mail you a copy immediately.               |
-// +----------------------------------------------------------------------+
-// | Authors: Stig Bakken <ssb@fast.no>                                   |
-// |                                                                      |
-// +----------------------------------------------------------------------+
-//
-// $Id$
-
-require_once "PEAR/Common.php";
-
-/**
- * Administration class used to maintain the installed package database.
- *
- * THIS CLASS IS EXPERIMENTAL
- */
-class PEAR_Packlist
-{
-    /** directory where system state information goes */
-    var $statedir;
-
-    /** list of installed packages */
-    var $pkglist = array();
-
-    /** temporary directory */
-    var $tmpdir;
-
-    /** file pointer for package list file if open */
-    var $pkglist_fp;
-
-    // {{{ constructor
-
-    function PEAR_Packlist($phpdir = PEAR_INSTALL_DIR,
-                            $extdir = PEAR_EXTENSION_DIR,
-                            $docdir = '')
-    {
-        $this->PEAR();
-        $this->phpdir = $phpdir;
-        $this->extdir = $extdir;
-        $this->docdir = $docdir;
-        $this->statedir = "/var/lib/php"; // XXX FIXME Windows
-    }
-
-    // }}}
-    // {{{ destructor
-
-    function _PEAR_Packlist()
-    {
-        if ($this->tmpdir && is_dir($this->tmpdir)) {
-            system("rm -rf $this->tmpdir"); // XXX FIXME Windows
-        }
-        if (isset($this->pkglist_fp) && is_resource($this->pkglist_fp)) {
-            flock($this->pkglist_fp, LOCK_UN);
-            fclose($this->pkglist_fp);
-        }
-        $this->tmpdir = null;
-        $this->pkglist_fp = null;
-        $this->_PEAR_Common();
-    }
-
-    // }}}
-
-    // {{{ lockPackageList()
-
-    function lockPackageList()
-    {
-        $fp = $this->pkglist_fp;
-        if (!is_resource($fp)) {
-            $this->pkglist_fp = $fp = fopen($this->pkglist_file, "r");
-        }
-        return flock($fp, LOCK_EX);
-    }
-
-    // }}}
-    // {{{ unlockPackageList()
-
-    function unlockPackageList()
-    {
-        $fp = $this->pkglist_fp;
-        if (!is_resource($fp)) {
-            $this->pkglist_fp = $fp = fopen($this->pkglist_file, "r");
-            $doclose = true;
-        }
-        $ret = flock($fp, LOCK_EX);
-        if ($doclose) {
-            fclose($fp);
-        }
-        return $ret;
-    }
-
-    // }}}
-    // {{{ loadPackageList()
-
-    function loadPackageList($file)
-    {
-        $this->pkglist_file = $file;
-        $this->pkglist = array();
-        if (!file_exists($file)) {
-            if (!@touch($file)) {
-                    return $this->raiseError("touch($file): $php_errormsg");
-            }
-        }
-        $fp = $this->pkglist_fp = @fopen($file, "r");
-        if (!is_resource($fp)) {
-                return $this->raiseError("fopen($file): $php_errormsg");
-        }
-        $this->lockPackageList();
-        $versionline = trim(fgets($fp, 2048));
-        if ($versionline == ";1") {
-            while ($line = fgets($fp, 2048)) {
-                list($name, $version, $file) = explode(";", trim($line));
-                $this->pkglist[$name]["version"] = $version;
-                $this->pkglist[$name]["files"][] = $file;
-            }
-        }
-        $this->unlockPackageList();
-    }
-
-    // }}}
-    // {{{ savePackageList()
-
-    function savePackageList()
-    {
-        $fp = $this->pkglist_fp;
-        $wfp = @fopen($this->pkglist_file, "w");
-        if (!is_resource($wfp)) {
-            return $this->raiseError("could not write $this->pkglist_file");
-        }
-        if (is_resource($fp)) {
-            fclose($fp);
-        }
-        $this->pkglist_fp = $fp = $wfp;
-        fwrite($fp, ";1\n");
-        foreach ($this->pkglist as $name => $entry) {
-            $ver = $entry["version"];
-            foreach ($entry["files"] as $file) {
-                fwrite($fp, "$name;$ver;$file\n");
-            }
-        }
-        fclose($fp);
-        $this->pkglist_fp = $fp = null;
-    }
-
-    // }}}
-    // {{{ updatePackageListFrom()
-
-    function updatePackageListFrom($file)
-    {
-        /*
-    $new = $this->classesDeclaredBy($file);
-    reset($new);
-    while (list($i, $name) = each($new)) {
-        $this->pkglist['class'][$name] = $file;
-    }
-        */
-    }
-
-    // }}}
-    // {{{ classesDeclaredBy()
-
-    /**
-     * Find out which new classes are defined by a file.
-     *
-     * @param $file file name passed to "include"
-     *
-     * @return array classes that were defined
-     */
-    function classesDeclaredBy($file)
-    {
-        $before = get_declared_classes();
-        ob_start();
-        include($file);
-        ob_end_clean();
-        $after = get_declared_classes();
-        // using array_slice to renumber array
-        $diff = array_slice(array_diff($after, $before), 0);
-        return $diff;
-    }
-
-    // }}}
-
-    // {{{ declaredWhenIncluding()
-
-    /**
-     * Find out which new classes are defined by a file.
-     *
-     * @param $file file name passed to "include"
-     *
-     * @return array classes that were defined
-     */
-    function &declaredWhenIncluding($file)
-    {
-        $classes_before = get_declared_classes();
-        $funcs_before = get_defined_functions();
-//      $vars_before = $GLOBALS;
-        ob_start();
-        include($file);
-        ob_end_clean();
-        $classes_after = get_declared_classes();
-        $funcs_after = get_defined_functions();
-//      $vars_after = $GLOBALS;
-        //using array_slice to renumber array
-        return array(
-            "classes" => array_slice(array_diff($classes_after, $classes_before), 0),
-            "functions" => array_slice(array_diff($funcs_after, $funcs_before), 0),
-//          "globals" => array_slice(array_diff($vars_after, $vars_before), 0)
-        );
-    }
-
-    // }}}
-
-    // {{{ lockDir()
-
-    /**
-     * Uses advisory locking (flock) to temporarily claim $dir as its
-     * own.
-     *
-     * @param $dir the directory to lock
-     *
-     * @return bool true if successful, false if not
-     */
-    function lockDir($dir)
-    {
-        $lockfile = "$dir/.lock";
-        if (!file_exists($lockfile)) {
-            if (!touch($lockfile)) {
-            // could not create lockfile!
-            return false;
-            }
-        }
-        $fp = fopen($lockfile, "r");
-        if (!flock($fp, LOCK_EX)) {
-            // could not create lock!
-            return false;
-        }
-        return true;
-    }
-
-    // }}}
-
-}
-?>
\ No newline at end of file
diff --git a/pear/PEAR/Registry.php b/pear/PEAR/Registry.php
new file mode 100644 (file)
index 0000000..06585cc
--- /dev/null
@@ -0,0 +1,142 @@
+<?php
+//
+// +----------------------------------------------------------------------+
+// | PHP version 4.0                                                      |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2001 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Authors: Stig Bakken <ssb@fast.no>                                   |
+// |                                                                      |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+require_once "Experimental/System.php";
+
+/**
+ * Administration class used to maintain the installed package database.
+ */
+class PEAR_Registry
+{
+    // {{{ properties
+
+    var $statedir;
+
+    // }}}
+
+    // {{{ PEAR_Registry
+
+    function PEAR_Registry()
+    {
+        $this->statedir = PHP_LOCALSTATEDIR . "/pear/registry";
+    }
+
+    // }}}
+
+    // {{{ _assertStateDir()
+
+    function _assertStateDir()
+    {
+        if (!@is_dir($this->statedir)) {
+            System::mkdir("-p {$this->statedir}");
+        }
+    }
+
+    // }}}
+    // {{{ _packageFileName()
+
+    function _packageFileName($package)
+    {
+        $package = strtolower($package);
+        return "{$this->statedir}/{$package}.inf";
+    }
+
+    // }}}
+    // {{{ _openPackageFile()
+
+    function _openPackageFile($package, $mode)
+    {
+        $this->_assertStateDir();
+        $file = $this->_packageFileName($package);
+        $fp = @fopen($file, $mode);
+        if (!$fp) {
+            return null;
+        }
+        return $fp;
+    }
+
+    // }}}
+    // {{{ _closePackageFile()
+
+    function _closePackageFile($fp)
+    {
+        fclose($fp);
+    }
+
+    // }}}
+
+    // {{{ packageExists()
+
+    function packageExists($package)
+    {
+        return file_exists($this->_packageFileName($package));
+    }
+
+    // }}}
+    // {{{ addPackage()
+
+    function addPackage($package, $info)
+    {
+        if ($this->packageExists($package)) {
+            return false;
+        }
+        return $this->upgradePackage($package, $info);
+    }
+
+    // }}}
+    // {{{ packageInfo()
+
+    function packageInfo($package)
+    {
+        $fp = $this->_openPackageFile($package, "r");
+        $data = fread($fp, filesize($this->_packageFileName($package)));
+        $this->_closePackageFile($fp);
+        return unserialize($data);
+    }
+
+    // }}}
+    // {{{ deletePackage()
+
+    function deletePackage($package)
+    {
+        $file = $this->_packageFileName($package);
+        unlink($file);
+    }
+
+    // }}}
+    // {{{ upgradePackage()
+
+    function upgradePackage($package, $info)
+    {
+        $fp = $this->_openPackageFile($package, "w");
+        if ($fp === null) {
+            return false;
+        }
+        fwrite($fp, serialize($info));
+        $this->_closePackageFile($fp);
+        return true;
+    }
+
+    // }}}
+
+}
+
+?>
\ No newline at end of file
index 5cd2633224d560508e89e1fc5d82f57e6054eb0f..6b0e5bbc9a2f31e3ee7c3ca36359e05987644763 100644 (file)
@@ -20,6 +20,7 @@
 //
 require_once 'PEAR.php';
 require_once 'PEAR/Config.php';
+require_once 'PEAR/Remote.php';
 require_once 'Console/Getopt.php';
 
 error_reporting(E_ALL ^ E_NOTICE);
@@ -147,7 +148,6 @@ switch ($command) {
     // {{{ list-packages
 
     case 'list-packages': {
-        include_once 'PEAR/Remote.php';
         $remote = new PEAR_Remote($config);
         $result = $remote->call('package.listAll');
         $i = $j = 0;