2000-07-24 08:05:51 +00:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | PHP version 4.0 |
|
|
|
|
// +----------------------------------------------------------------------+
|
2001-01-10 01:01:59 +00:00
|
|
|
// | Copyright (c) 1997-2001 The PHP Group |
|
2000-07-24 08:05:51 +00:00
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | 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> |
|
|
|
|
// | |
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
//
|
|
|
|
|
2001-04-22 01:09:14 +00:00
|
|
|
require_once "PEAR/Common.php";
|
2000-07-24 08:05:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Administration class used to install PEAR packages and maintain the
|
2001-04-17 01:17:59 +00:00
|
|
|
* installed package database.
|
2000-07-24 08:05:51 +00:00
|
|
|
*
|
|
|
|
* @since PHP 4.0.2
|
|
|
|
* @author Stig Bakken <ssb@fast.no>
|
|
|
|
*/
|
2001-04-22 01:09:14 +00:00
|
|
|
class PEAR_Installer extends PEAR_Common
|
2001-01-08 02:45:30 +00:00
|
|
|
{
|
2000-07-24 08:05:51 +00:00
|
|
|
// {{{ properties
|
|
|
|
|
|
|
|
/** name of the package directory, for example Foo-1.0 */
|
|
|
|
var $pkgdir;
|
|
|
|
|
|
|
|
/** directory where PHP code files go */
|
2001-04-17 01:17:59 +00:00
|
|
|
var $phpdir;
|
2000-07-24 08:05:51 +00:00
|
|
|
|
|
|
|
/** directory where PHP extension files go */
|
2001-04-17 01:17:59 +00:00
|
|
|
var $extdir;
|
2000-07-24 08:05:51 +00:00
|
|
|
|
|
|
|
/** directory where documentation goes */
|
2001-04-17 01:17:59 +00:00
|
|
|
var $docdir;
|
|
|
|
|
|
|
|
/** directory where system state information goes */
|
|
|
|
var $statedir;
|
2000-07-24 08:05:51 +00:00
|
|
|
|
|
|
|
/** directory where the package wants to put files, relative
|
|
|
|
* to one of the three previous dirs
|
|
|
|
*/
|
|
|
|
var $destdir = '';
|
|
|
|
|
2001-05-15 14:15:09 +00:00
|
|
|
/** debug level (integer) */
|
|
|
|
var $debug = 1;
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-04-17 01:17:59 +00:00
|
|
|
/** list of installed packages */
|
|
|
|
var $pkglist = array();
|
2000-07-24 08:05:51 +00:00
|
|
|
|
|
|
|
/** temporary directory */
|
|
|
|
var $tmpdir;
|
|
|
|
|
2001-04-17 01:17:59 +00:00
|
|
|
/** file pointer for package list file if open */
|
|
|
|
var $pkglist_fp;
|
|
|
|
|
2000-07-24 08:05:51 +00:00
|
|
|
// }}}
|
|
|
|
|
|
|
|
// {{{ constructor
|
|
|
|
|
2001-04-17 01:17:59 +00:00
|
|
|
function PEAR_Installer($phpdir = PEAR_INSTALL_DIR,
|
|
|
|
$extdir = PEAR_EXTENSION_DIR,
|
|
|
|
$docdir = '')
|
|
|
|
{
|
2001-05-15 14:03:04 +00:00
|
|
|
$this->PEAR();
|
2001-04-17 01:17:59 +00:00
|
|
|
$this->phpdir = $phpdir;
|
|
|
|
$this->extdir = $extdir;
|
|
|
|
$this->docdir = $docdir;
|
|
|
|
$this->statedir = "/var/lib/php"; // XXX FIXME Windows
|
2001-05-15 14:03:04 +00:00
|
|
|
$this->loadPackageList("$this->statedir/packages.lst");
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ destructor
|
|
|
|
|
2001-05-15 14:03:04 +00:00
|
|
|
function _PEAR_Installer()
|
|
|
|
{
|
|
|
|
if ($this->tmpdir && is_dir($this->tmpdir)) {
|
|
|
|
system("rm -rf $this->tmpdir"); // XXX FIXME Windows
|
|
|
|
}
|
|
|
|
if ($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();
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
2001-01-08 02:45:30 +00:00
|
|
|
// {{{ mkDirHier()
|
|
|
|
|
|
|
|
function mkDirHier($dir)
|
|
|
|
{
|
|
|
|
$dirstack = array();
|
2001-05-22 16:25:04 +00:00
|
|
|
while (!@is_dir($dir) && $dir != DIRECTORY_SEPARATOR) {
|
2001-01-08 02:45:30 +00:00
|
|
|
array_unshift($dirstack, $dir);
|
|
|
|
$dir = dirname($dir);
|
|
|
|
}
|
|
|
|
while ($newdir = array_shift($dirstack)) {
|
|
|
|
if (mkdir($newdir, 0777)) {
|
|
|
|
$this->log(1, "created dir $newdir");
|
|
|
|
} else {
|
|
|
|
return $this->raiseError("mkdir($newdir) failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ log()
|
|
|
|
|
|
|
|
function log($level, $msg)
|
|
|
|
{
|
|
|
|
if ($this->debug >= $level) {
|
|
|
|
print "$msg\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
2001-04-17 01:17:59 +00:00
|
|
|
// {{{ lockPackageList()
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-05-15 14:03:04 +00:00
|
|
|
function lockPackageList()
|
|
|
|
{
|
|
|
|
$fp = $this->pkglist_fp;
|
|
|
|
if (!is_resource($fp)) {
|
|
|
|
$this->pkglist_fp = $fp = fopen($this->pkglist_file, "r");
|
|
|
|
}
|
|
|
|
return flock($fp, LOCK_EX);
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2001-04-17 01:17:59 +00:00
|
|
|
// {{{ unlockPackageList()
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-05-15 14:03:04 +00:00
|
|
|
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;
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2001-04-17 01:17:59 +00:00
|
|
|
// {{{ loadPackageList()
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-05-15 14:03:04 +00:00
|
|
|
function loadPackageList($file)
|
|
|
|
{
|
|
|
|
$this->pkglist_file = $file;
|
2001-04-17 02:33:45 +00:00
|
|
|
$this->pkglist = array();
|
2001-05-15 14:03:04 +00:00
|
|
|
if (!file_exists($file)) {
|
|
|
|
if (!@touch($file)) {
|
|
|
|
return $this->raiseError("touch($file): $php_errormsg");
|
2001-04-17 02:33:45 +00:00
|
|
|
}
|
2001-05-15 14:03:04 +00:00
|
|
|
}
|
|
|
|
$fp = $this->pkglist_fp = @fopen($file, "r");
|
2001-04-17 02:33:45 +00:00
|
|
|
if (!is_resource($fp)) {
|
|
|
|
return $this->raiseError("fopen($file): $php_errormsg");
|
|
|
|
}
|
2001-05-15 14:03:04 +00:00
|
|
|
$this->lockPackageList();
|
2001-04-17 02:33:45 +00:00
|
|
|
$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();
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2001-04-17 01:17:59 +00:00
|
|
|
// {{{ savePackageList()
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-05-15 14:03:04 +00:00
|
|
|
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;
|
2001-04-17 02:33:45 +00:00
|
|
|
fwrite($fp, ";1\n");
|
|
|
|
foreach ($this->pkglist as $name => $entry) {
|
|
|
|
$ver = $entry["version"];
|
|
|
|
foreach ($entry["files"] as $file) {
|
2001-05-15 14:03:04 +00:00
|
|
|
fwrite($fp, "$name;$ver;$file\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($fp);
|
|
|
|
$this->pkglist_fp = $fp = null;
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2001-04-17 01:17:59 +00:00
|
|
|
// {{{ updatePackageListFrom()
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-05-15 14:03:04 +00:00
|
|
|
function updatePackageListFrom($file)
|
|
|
|
{
|
2001-01-08 02:45:30 +00:00
|
|
|
/*
|
2001-05-15 14:03:04 +00:00
|
|
|
$new = $this->classesDeclaredBy($file);
|
|
|
|
reset($new);
|
|
|
|
while (list($i, $name) = each($new)) {
|
|
|
|
$this->pkglist['class'][$name] = $file;
|
|
|
|
}
|
2001-01-08 02:45:30 +00:00
|
|
|
*/
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
// {{{ install()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Installs the files within the package file specified.
|
|
|
|
*
|
|
|
|
* @param $pkgfile path to the package file
|
|
|
|
*
|
|
|
|
* @return bool true if successful, false if not
|
|
|
|
*/
|
2001-05-15 14:03:04 +00:00
|
|
|
function install($pkgfile)
|
|
|
|
{
|
2001-01-08 02:45:30 +00:00
|
|
|
if (preg_match('#^(http|ftp)://#', $pkgfile)) {
|
|
|
|
$need_download = true;
|
|
|
|
} elseif (!file_exists($pkgfile)) {
|
2001-05-15 14:03:04 +00:00
|
|
|
return $this->raiseError("$pkgfile: no such file");
|
|
|
|
}
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-01-08 02:45:30 +00:00
|
|
|
if ($need_download) {
|
|
|
|
$file = basename($pkgfile);
|
2001-04-22 01:09:14 +00:00
|
|
|
// XXX FIXME use ??? on Windows, use $TMPDIR on unix
|
2001-01-08 02:45:30 +00:00
|
|
|
$downloaddir = "/tmp/pearinstall";
|
|
|
|
$this->mkDirHier($downloaddir);
|
2001-04-17 01:17:59 +00:00
|
|
|
$downloadfile = $downloaddir.DIRECTORY_SEPARATOR.$file;
|
2001-01-08 02:54:35 +00:00
|
|
|
$this->log(1, "downloading $pkgfile...");
|
2001-01-08 02:45:30 +00:00
|
|
|
$fp = @fopen($pkgfile, "r");
|
|
|
|
if (!$fp) {
|
|
|
|
return $this->raiseError("$pkgfile: failed to download ($php_errormsg)");
|
|
|
|
}
|
|
|
|
$wp = @fopen($downloadfile, "w");
|
|
|
|
if (!$wp) {
|
|
|
|
return $this->raiseError("$downloadfile: write failed ($php_errormsg)");
|
|
|
|
}
|
2001-04-22 01:09:14 +00:00
|
|
|
$this->addTempFile($downloadfile);
|
2001-01-08 02:54:35 +00:00
|
|
|
$bytes = 0;
|
2001-01-08 02:45:30 +00:00
|
|
|
while ($data = @fread($fp, 16384)) {
|
2001-01-08 02:54:35 +00:00
|
|
|
$bytes += strlen($data);
|
2001-01-08 02:45:30 +00:00
|
|
|
if (!@fwrite($wp, $data)) {
|
|
|
|
return $this->raiseError("$downloadfile: write failed ($php_errormsg)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$pkgfile = $downloadfile;
|
|
|
|
fclose($fp);
|
|
|
|
fclose($wp);
|
2001-01-08 02:54:35 +00:00
|
|
|
$this->log(1, "...done, $bytes bytes");
|
2001-01-08 02:45:30 +00:00
|
|
|
}
|
2001-04-22 01:09:14 +00:00
|
|
|
// XXX FIXME depends on external gzip+tar
|
2001-05-15 14:03:04 +00:00
|
|
|
$fp = popen("gzip -dc $pkgfile | tar -tf -", "r");
|
|
|
|
if (!$fp) {
|
|
|
|
return $this->raiseError("Unable to examine $pkgfile (gzip or tar failed)");
|
|
|
|
}
|
|
|
|
while ($line = fgets($fp, 4096)) {
|
|
|
|
$line = rtrim($line);
|
|
|
|
if (preg_match('!^[^/]+/package.xml$!', $line)) {
|
|
|
|
if ($descfile) {
|
|
|
|
return $this->raiseError("Invalid package: multiple package.xml files at depth one!");
|
|
|
|
}
|
|
|
|
$descfile = $line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose($fp);
|
|
|
|
|
|
|
|
if (!$descfile) {
|
|
|
|
return $this->raiseError("Invalid package: no package.xml file found!");
|
|
|
|
}
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-04-17 01:17:59 +00:00
|
|
|
// XXX FIXME Windows
|
2001-05-15 14:03:04 +00:00
|
|
|
$this->tmpdir = tempnam("/tmp", "pear");
|
2001-01-08 02:45:30 +00:00
|
|
|
unlink($this->tmpdir);
|
2001-05-15 14:03:04 +00:00
|
|
|
if (!mkdir($this->tmpdir, 0755)) {
|
|
|
|
return $this->raiseError("Unable to create temporary directory $this->tmpdir.");
|
|
|
|
}
|
2001-04-22 01:09:14 +00:00
|
|
|
$this->addTempFile($this->tmpdir);
|
2001-05-15 14:03:04 +00:00
|
|
|
$pwd = getcwd();
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-04-22 01:09:14 +00:00
|
|
|
// XXX FIXME Windows should check for drive
|
2001-05-15 14:03:04 +00:00
|
|
|
if (substr($pkgfile, 0, 1) == DIRECTORY_SEPARATOR) {
|
|
|
|
$pkgfilepath = $pkgfile;
|
|
|
|
} else {
|
|
|
|
$pkgfilepath = $pwd.DIRECTORY_SEPARATOR.$pkgfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!chdir($this->tmpdir)) {
|
|
|
|
return $this->raiseError("Unable to chdir to $this->tmpdir.");
|
|
|
|
}
|
|
|
|
|
|
|
|
system("gzip -dc $pkgfilepath | tar -xf -");
|
|
|
|
|
|
|
|
if (!file_exists($descfile)) {
|
|
|
|
return $this->raiseError("Huh? No package.xml file after extracting the archive.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->pkgdir = dirname($descfile);
|
|
|
|
|
|
|
|
$fp = fopen($descfile, "r");
|
|
|
|
$xp = xml_parser_create();
|
|
|
|
if (!$xp) {
|
|
|
|
return $this->raiseError("Unable to create XML parser.");
|
|
|
|
}
|
|
|
|
xml_set_object($xp, &$this);
|
|
|
|
xml_set_element_handler($xp, "startHandler", "endHandler");
|
|
|
|
xml_set_character_data_handler($xp, "charHandler");
|
|
|
|
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);
|
|
|
|
|
|
|
|
$this->element_stack = array();
|
|
|
|
$this->pkginfo = array();
|
|
|
|
$this->current_element = false;
|
|
|
|
$this->destdir = '';
|
|
|
|
|
|
|
|
$data = fread($fp, filesize($descfile));
|
2001-04-17 02:33:45 +00:00
|
|
|
if (!xml_parse($xp, $data, 1)) {
|
|
|
|
$msg = sprintf("XML error: %s at line %d",
|
|
|
|
xml_error_string(xml_get_error_code($xp)),
|
|
|
|
xml_get_current_line_number($xp));
|
|
|
|
xml_parser_free($xp);
|
|
|
|
return $this->raiseError($msg);
|
2001-05-15 14:03:04 +00:00
|
|
|
}
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-05-15 14:03:04 +00:00
|
|
|
xml_parser_free($xp);
|
|
|
|
return true;
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2001-01-08 02:45:30 +00:00
|
|
|
// {{{ startHandler()
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-05-15 14:03:04 +00:00
|
|
|
function startHandler($xp, $name, $attribs)
|
|
|
|
{
|
|
|
|
array_push($this->element_stack, $name);
|
|
|
|
$this->current_element = $name;
|
|
|
|
$this->current_attributes = $attribs;
|
|
|
|
switch ($name) {
|
|
|
|
case "Package":
|
2001-04-17 02:33:45 +00:00
|
|
|
/*
|
2001-05-15 14:03:04 +00:00
|
|
|
if (strtolower($attribs["Type"]) != "binary") {
|
|
|
|
return $this->raiseError("Invalid package: only binary packages supported yet.");
|
|
|
|
}
|
|
|
|
$this->pkginfo['pkgtype'] = strtolower($attribs["Type"]);
|
2001-04-17 02:33:45 +00:00
|
|
|
*/
|
2001-05-15 14:03:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2001-01-08 02:45:30 +00:00
|
|
|
// {{{ endHandler()
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-05-15 14:03:04 +00:00
|
|
|
function endHandler($xp, $name)
|
|
|
|
{
|
|
|
|
array_pop($this->element_stack);
|
|
|
|
$this->current_element = $this->element_stack[sizeof($this->element_stack)-1];
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2001-01-08 02:45:30 +00:00
|
|
|
// {{{ charHandler()
|
2000-07-24 08:05:51 +00:00
|
|
|
|
2001-05-15 14:03:04 +00:00
|
|
|
function charHandler($xp, $data)
|
|
|
|
{
|
2001-04-17 02:33:45 +00:00
|
|
|
$next = $this->element_stack[sizeof($this->element_stack)-1];
|
2001-05-15 14:03:04 +00:00
|
|
|
switch ($this->current_element) {
|
2001-04-17 02:33:45 +00:00
|
|
|
case "Name":
|
|
|
|
if ($next == "Package") {
|
|
|
|
$this->pkginfo["name"] = $data;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "Version":
|
|
|
|
$this->pkginfo["version"] = $data;
|
|
|
|
break;
|
2001-05-15 14:03:04 +00:00
|
|
|
case "Dir":
|
|
|
|
if (!$this->phpdir) {
|
2001-05-22 16:25:04 +00:00
|
|
|
return $this->raiseError("No script destination directory found\n",
|
|
|
|
null, PEAR_ERROR_DIE);
|
2001-05-15 14:03:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-01-08 02:45:30 +00:00
|
|
|
$type = $this->current_attributes["Type"];
|
2001-05-15 14:03:04 +00:00
|
|
|
$dir = trim($data);
|
|
|
|
$d = "$this->phpdir/$this->destdir/$dir";
|
|
|
|
if (substr($dir, 0, 1) == "/") {
|
|
|
|
$this->destdir = substr($dir, 1);
|
|
|
|
} else {
|
2001-05-15 14:15:09 +00:00
|
|
|
$this->destdir = $dir;
|
|
|
|
}
|
2001-05-15 14:03:04 +00:00
|
|
|
break;
|
2001-05-22 16:25:04 +00:00
|
|
|
|
2001-05-15 14:03:04 +00:00
|
|
|
case "File":
|
|
|
|
if (!$this->phpdir) {
|
2001-05-22 16:25:04 +00:00
|
|
|
return $this->raiseError("No script destination directory found\n",
|
|
|
|
null, PEAR_ERROR_DIE);
|
2001-05-15 14:03:04 +00:00
|
|
|
break;
|
2001-01-08 02:45:30 +00:00
|
|
|
}
|
|
|
|
$type = strtolower($this->current_attributes["Role"]);
|
2001-05-15 14:03:04 +00:00
|
|
|
$file = trim($data);
|
2001-04-17 01:17:59 +00:00
|
|
|
$updatepkglist = false;
|
2001-01-08 02:45:30 +00:00
|
|
|
switch ($type) {
|
|
|
|
case "test":
|
|
|
|
$d = ""; // don't install test files for now
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ($this->destdir) {
|
2001-04-17 01:17:59 +00:00
|
|
|
$d = "$this->phpdir/$this->destdir";
|
2001-01-08 02:45:30 +00:00
|
|
|
} else {
|
2001-04-17 01:17:59 +00:00
|
|
|
$d = $this->phpdir;
|
2001-01-08 02:45:30 +00:00
|
|
|
}
|
2001-04-17 01:17:59 +00:00
|
|
|
$updatepkglist = true;
|
2001-01-08 02:45:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!$d) {
|
|
|
|
break;
|
|
|
|
}
|
2001-05-22 16:25:04 +00:00
|
|
|
if (!@is_dir($d)) {
|
2001-01-08 02:45:30 +00:00
|
|
|
$this->mkDirHier($d);
|
|
|
|
}
|
|
|
|
$bfile = basename($file);
|
2001-05-15 14:03:04 +00:00
|
|
|
if (!copy("$this->pkgdir/$file", "$d/$bfile")) {
|
|
|
|
$this->log(0, "failed to copy $this->pkgdir/$file to $d");
|
|
|
|
break;
|
|
|
|
}
|
2001-04-17 01:17:59 +00:00
|
|
|
if ($updatepkglist) {
|
|
|
|
$this->updatePackageListFrom("$d/$file");
|
2001-01-08 02:45:30 +00:00
|
|
|
}
|
|
|
|
$this->log(1, "installed $d/$bfile");
|
2001-05-15 14:03:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
// {{{ classesDeclaredBy()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find out which new classes are defined by a file.
|
|
|
|
*
|
|
|
|
* @param $file file name passed to "include"
|
|
|
|
*
|
|
|
|
* @return array classes that were defined
|
|
|
|
*/
|
2001-05-15 14:03:04 +00:00
|
|
|
function classesDeclaredBy($file)
|
|
|
|
{
|
|
|
|
$before = get_declared_classes();
|
2001-01-08 02:45:30 +00:00
|
|
|
ob_start();
|
2001-05-15 14:03:04 +00:00
|
|
|
include($file);
|
2001-01-08 02:45:30 +00:00
|
|
|
ob_end_clean();
|
2001-05-15 14:03:04 +00:00
|
|
|
$after = get_declared_classes();
|
|
|
|
// using array_slice to renumber array
|
|
|
|
$diff = array_slice(array_diff($after, $before), 0);
|
|
|
|
return $diff;
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
2001-04-17 01:17:59 +00:00
|
|
|
// }}}
|
|
|
|
|
|
|
|
// {{{ declaredWhenIncluding()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find out which new classes are defined by a file.
|
|
|
|
*
|
|
|
|
* @param $file file name passed to "include"
|
|
|
|
*
|
|
|
|
* @return array classes that were defined
|
|
|
|
*/
|
2001-05-15 14:03:04 +00:00
|
|
|
function &declaredWhenIncluding($file)
|
|
|
|
{
|
|
|
|
$classes_before = get_declared_classes();
|
2001-04-17 01:17:59 +00:00
|
|
|
$funcs_before = get_defined_functions();
|
2001-05-15 14:03:04 +00:00
|
|
|
// $vars_before = $GLOBALS;
|
2001-04-17 01:17:59 +00:00
|
|
|
ob_start();
|
2001-05-15 14:03:04 +00:00
|
|
|
include($file);
|
2001-04-17 01:17:59 +00:00
|
|
|
ob_end_clean();
|
2001-05-15 14:03:04 +00:00
|
|
|
$classes_after = get_declared_classes();
|
2001-04-17 01:17:59 +00:00
|
|
|
$funcs_after = get_defined_functions();
|
2001-05-15 14:03:04 +00:00
|
|
|
// $vars_after = $GLOBALS;
|
|
|
|
//using array_slice to renumber array
|
2001-04-17 01:17:59 +00:00
|
|
|
return array(
|
|
|
|
"classes" => array_slice(array_diff($classes_after, $classes_before), 0),
|
|
|
|
"functions" => array_slice(array_diff($funcs_after, $funcs_before), 0),
|
2001-05-15 14:03:04 +00:00
|
|
|
// "globals" => array_slice(array_diff($vars_after, $vars_before), 0)
|
2001-04-17 01:17:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2000-07-24 08:05:51 +00:00
|
|
|
|
|
|
|
// {{{ 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
|
|
|
|
*/
|
2001-05-15 14:03:04 +00:00
|
|
|
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;
|
2000-07-24 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|