Subversion Repositories Applications.gtt

Compare Revisions

Ignore whitespace Rev 186 → Rev 187

/trunk/bibliotheque/pear/PEAR/Registry.php
4,20 → 4,13
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category pear
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @author Tomas V. V. Cox <cox@idecnet.com>
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: Registry.php,v 1.159 2006/12/20 19:34:03 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
28,10 → 21,10
require_once 'PEAR.php';
require_once 'PEAR/DependencyDB.php';
 
define('PEAR_REGISTRY_ERROR_LOCK', -2);
define('PEAR_REGISTRY_ERROR_FORMAT', -3);
define('PEAR_REGISTRY_ERROR_FILE', -4);
define('PEAR_REGISTRY_ERROR_CONFLICT', -5);
define('PEAR_REGISTRY_ERROR_LOCK', -2);
define('PEAR_REGISTRY_ERROR_FORMAT', -3);
define('PEAR_REGISTRY_ERROR_FILE', -4);
define('PEAR_REGISTRY_ERROR_CONFLICT', -5);
define('PEAR_REGISTRY_ERROR_CHANNEL_FILE', -6);
 
/**
41,16 → 34,14
* @author Stig Bakken <ssb@php.net>
* @author Tomas V. V. Cox <cox@idecnet.com>
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.5.1
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
class PEAR_Registry extends PEAR
{
// {{{ properties
 
/**
* File containing all channel information.
* @var string
112,6 → 103,11
var $_peclChannel;
 
/**
* @var false|PEAR_ChannelFile
*/
var $_docChannel;
 
/**
* @var PEAR_DependencyDB
*/
var $_dependencyDB;
120,10 → 116,7
* @var PEAR_Config
*/
var $_config;
// }}}
 
// {{{ constructor
 
/**
* PEAR_Registry constructor.
*
137,43 → 130,61
*
* @access public
*/
function PEAR_Registry($pear_install_dir = PEAR_INSTALL_DIR, $pear_channel = false,
$pecl_channel = false)
function __construct($pear_install_dir = PEAR_INSTALL_DIR, $pear_channel = false,
$pecl_channel = false, $pear_metadata_dir = '')
{
parent::PEAR();
$ds = DIRECTORY_SEPARATOR;
$this->install_dir = $pear_install_dir;
$this->channelsdir = $pear_install_dir.$ds.'.channels';
$this->statedir = $pear_install_dir.$ds.'.registry';
$this->filemap = $pear_install_dir.$ds.'.filemap';
$this->lockfile = $pear_install_dir.$ds.'.lock';
parent::__construct();
$this->setInstallDir($pear_install_dir, $pear_metadata_dir);
$this->_pearChannel = $pear_channel;
$this->_peclChannel = $pecl_channel;
$this->_config = false;
$this->_config = false;
}
 
function setInstallDir($pear_install_dir = PEAR_INSTALL_DIR, $pear_metadata_dir = '')
{
$ds = DIRECTORY_SEPARATOR;
$this->install_dir = $pear_install_dir;
if (!$pear_metadata_dir) {
$pear_metadata_dir = $pear_install_dir;
}
$this->channelsdir = $pear_metadata_dir.$ds.'.channels';
$this->statedir = $pear_metadata_dir.$ds.'.registry';
$this->filemap = $pear_metadata_dir.$ds.'.filemap';
$this->lockfile = $pear_metadata_dir.$ds.'.lock';
}
 
function hasWriteAccess()
{
if (!file_exists($this->install_dir)) {
$dir = $this->install_dir;
while ($dir && $dir != '.') {
$dir = dirname($dir); // cd ..
$olddir = $dir;
$dir = dirname($dir);
if ($dir != '.' && file_exists($dir)) {
if (is_writeable($dir)) {
return true;
} else {
return false;
}
 
return false;
}
 
if ($dir == $olddir) { // this can happen in safe mode
return @is_writable($dir);
}
}
 
return false;
}
 
return is_writeable($this->install_dir);
}
 
function setConfig(&$config)
function setConfig(&$config, $resetInstallDir = true)
{
$this->_config = &$config;
if ($resetInstallDir) {
$this->setInstallDir($config->get('php_dir'), $config->get('metadata_dir'));
}
}
 
function _initializeChannelDirs()
185,6 → 196,7
if (!is_dir($this->channelsdir) ||
!file_exists($this->channelsdir . $ds . 'pear.php.net.reg') ||
!file_exists($this->channelsdir . $ds . 'pecl.php.net.reg') ||
!file_exists($this->channelsdir . $ds . 'doc.php.net.reg') ||
!file_exists($this->channelsdir . $ds . '__uri.reg')) {
if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
$pear_channel = $this->_pearChannel;
192,8 → 204,8
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setName('pear.php.net');
$pear_channel->setAlias('pear');
$pear_channel->setServer('pear.php.net');
$pear_channel->setSummary('PHP Extension and Application Repository');
200,13 → 212,17
$pear_channel->setDefaultPEARProtocols();
$pear_channel->setBaseURL('REST1.0', 'http://pear.php.net/rest/');
$pear_channel->setBaseURL('REST1.1', 'http://pear.php.net/rest/');
$pear_channel->setBaseURL('REST1.3', 'http://pear.php.net/rest/');
//$pear_channel->setBaseURL('REST1.4', 'http://pear.php.net/rest/');
} else {
$pear_channel->setName('pear.php.net');
$pear_channel->setServer('pear.php.net');
$pear_channel->setAlias('pear');
}
 
$pear_channel->validate();
$this->_addChannel($pear_channel);
}
 
if (!file_exists($this->channelsdir . $ds . 'pecl.php.net.reg')) {
$pecl_channel = $this->_peclChannel;
if (!is_a($pecl_channel, 'PEAR_ChannelFile') || !$pecl_channel->validate()) {
213,8 → 229,8
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$pecl_channel = new PEAR_ChannelFile;
$pecl_channel->setName('pecl.php.net');
$pecl_channel->setAlias('pecl');
$pecl_channel->setServer('pecl.php.net');
$pecl_channel->setSummary('PHP Extension Community Library');
223,24 → 239,53
$pecl_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
$pecl_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
} else {
$pecl_channel->setName('pecl.php.net');
$pecl_channel->setServer('pecl.php.net');
$pecl_channel->setAlias('pecl');
}
 
$pecl_channel->validate();
$this->_addChannel($pecl_channel);
}
 
if (!file_exists($this->channelsdir . $ds . 'doc.php.net.reg')) {
$doc_channel = $this->_docChannel;
if (!is_a($doc_channel, 'PEAR_ChannelFile') || !$doc_channel->validate()) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$doc_channel = new PEAR_ChannelFile;
$doc_channel->setAlias('phpdocs');
$doc_channel->setServer('doc.php.net');
$doc_channel->setSummary('PHP Documentation Team');
$doc_channel->setDefaultPEARProtocols();
$doc_channel->setBaseURL('REST1.0', 'http://doc.php.net/rest/');
$doc_channel->setBaseURL('REST1.1', 'http://doc.php.net/rest/');
$doc_channel->setBaseURL('REST1.3', 'http://doc.php.net/rest/');
} else {
$doc_channel->setServer('doc.php.net');
$doc_channel->setAlias('doc');
}
 
$doc_channel->validate();
$this->_addChannel($doc_channel);
}
 
if (!file_exists($this->channelsdir . $ds . '__uri.reg')) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$private = new PEAR_ChannelFile;
$private->setName('__uri');
$private->addFunction('xmlrpc', '1.0', '****');
$private->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
$this->_addChannel($private);
}
$this->_rebuildFileMap();
}
 
$running = false;
}
}
254,12 → 299,13
$handle = opendir($this->statedir)) {
$dest = $this->statedir . $ds;
while (false !== ($file = readdir($handle))) {
if (preg_match('/^.*[A-Z].*\.reg$/', $file)) {
if (preg_match('/^.*[A-Z].*\.reg\\z/', $file)) {
rename($dest . $file, $dest . strtolower($file));
}
}
closedir($handle);
}
 
$this->_initializeChannelDirs();
if (!file_exists($this->filemap)) {
$this->_rebuildFileMap();
274,24 → 320,22
if (!$initializing) {
$initializing = true;
if (!$this->_config) { // never used?
if (OS_WINDOWS) {
$file = 'pear.ini';
} else {
$file = '.pearrc';
}
$this->_config = &new PEAR_Config($this->statedir . DIRECTORY_SEPARATOR .
$file = OS_WINDOWS ? 'pear.ini' : '.pearrc';
$this->_config = new PEAR_Config($this->statedir . DIRECTORY_SEPARATOR .
$file);
$this->_config->setRegistry($this);
$this->_config->set('php_dir', $this->install_dir);
}
 
$this->_dependencyDB = &PEAR_DependencyDB::singleton($this->_config);
if (PEAR::isError($this->_dependencyDB)) {
// attempt to recover by removing the dep db
if (file_exists($this->_config->get('php_dir', null, 'pear.php.net') .
if (file_exists($this->_config->get('metadata_dir', null, 'pear.php.net') .
DIRECTORY_SEPARATOR . '.depdb')) {
@unlink($this->_config->get('php_dir', null, 'pear.php.net') .
@unlink($this->_config->get('metadata_dir', null, 'pear.php.net') .
DIRECTORY_SEPARATOR . '.depdb');
}
 
$this->_dependencyDB = &PEAR_DependencyDB::singleton($this->_config);
if (PEAR::isError($this->_dependencyDB)) {
echo $this->_dependencyDB->getMessage();
299,12 → 343,11
exit(1);
}
}
 
$initializing = false;
}
}
}
// }}}
// {{{ destructor
 
/**
* PEAR_Registry destructor. Makes sure no locks are forgotten.
319,10 → 362,6
}
}
 
// }}}
 
// {{{ _assertStateDir()
 
/**
* Make sure the directory where we keep registry files exists.
*
336,11 → 375,13
if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
return $this->_assertChannelStateDir($channel);
}
 
static $init = false;
if (!file_exists($this->statedir)) {
if (!$this->hasWriteAccess()) {
return false;
}
 
require_once 'System.php';
if (!System::mkdir(array('-p', $this->statedir))) {
return $this->raiseError("could not create directory '{$this->statedir}'");
350,10 → 391,12
return $this->raiseError('Cannot create directory ' . $this->statedir . ', ' .
'it already exists and is not a directory');
}
 
$ds = DIRECTORY_SEPARATOR;
if (!file_exists($this->channelsdir)) {
if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg') ||
!file_exists($this->channelsdir . $ds . 'pecl.php.net.reg') ||
!file_exists($this->channelsdir . $ds . 'doc.php.net.reg') ||
!file_exists($this->channelsdir . $ds . '__uri.reg')) {
$init = true;
}
361,6 → 404,7
return $this->raiseError('Cannot create directory ' . $this->channelsdir . ', ' .
'it already exists and is not a directory');
}
 
if ($init) {
static $running = false;
if (!$running) {
372,12 → 416,10
} else {
$this->_initializeDepDB();
}
 
return true;
}
 
// }}}
// {{{ _assertChannelStateDir()
 
/**
* Make sure the directory where we keep registry files exists for a non-standard channel.
*
396,15 → 438,18
}
return $this->_assertStateDir($channel);
}
 
$channelDir = $this->_channelDirectoryName($channel);
if (!is_dir($this->channelsdir) ||
!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
$this->_initializeChannelDirs();
}
 
if (!file_exists($channelDir)) {
if (!$this->hasWriteAccess()) {
return false;
}
 
require_once 'System.php';
if (!System::mkdir(array('-p', $channelDir))) {
return $this->raiseError("could not create directory '" . $channelDir .
414,12 → 459,10
return $this->raiseError("could not create directory '" . $channelDir .
"', already exists and is not a directory");
}
 
return true;
}
 
// }}}
// {{{ _assertChannelDir()
 
/**
* Make sure the directory where we keep registry files for channels exists
*
434,6 → 477,7
if (!$this->hasWriteAccess()) {
return false;
}
 
require_once 'System.php';
if (!System::mkdir(array('-p', $this->channelsdir))) {
return $this->raiseError("could not create directory '{$this->channelsdir}'");
441,12 → 485,13
} elseif (!is_dir($this->channelsdir)) {
return $this->raiseError("could not create directory '{$this->channelsdir}" .
"', it already exists and is not a directory");
}
 
if (!file_exists($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) {
if (!$this->hasWriteAccess()) {
return false;
}
 
require_once 'System.php';
if (!System::mkdir(array('-p', $this->channelsdir . DIRECTORY_SEPARATOR . '.alias'))) {
return $this->raiseError("could not create directory '{$this->channelsdir}/.alias'");
454,14 → 499,11
} elseif (!is_dir($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) {
return $this->raiseError("could not create directory '{$this->channelsdir}" .
"/.alias', it already exists and is not a directory");
}
 
return true;
}
 
// }}}
// {{{ _packageFileName()
 
/**
* Get the name of the file where data for a given package is stored.
*
478,12 → 520,10
return $this->_channelDirectoryName($channel) . DIRECTORY_SEPARATOR .
strtolower($package) . '.reg';
}
 
return $this->statedir . DIRECTORY_SEPARATOR . strtolower($package) . '.reg';
}
 
// }}}
// {{{ _channelFileName()
 
/**
* Get the name of the file where data for a given channel is stored.
* @param string channel name
500,9 → 540,6
strtolower($channel)) . '.reg';
}
 
// }}}
// {{{ getChannelAliasFileName()
 
/**
* @param string
* @return string
513,9 → 550,6
DIRECTORY_SEPARATOR . str_replace('/', '_', strtolower($alias)) . '.txt';
}
 
// }}}
// {{{ _getChannelFromAlias()
 
/**
* Get the name of a channel from its alias
*/
525,25 → 559,31
if ($channel == 'pear.php.net') {
return 'pear.php.net';
}
 
if ($channel == 'pecl.php.net') {
return 'pecl.php.net';
}
 
if ($channel == 'doc.php.net') {
return 'doc.php.net';
}
 
if ($channel == '__uri') {
return '__uri';
}
 
return false;
}
 
$channel = strtolower($channel);
if (file_exists($this->_getChannelAliasFileName($channel))) {
// translate an alias to an actual channel
return implode('', file($this->_getChannelAliasFileName($channel)));
} else {
return $channel;
}
}
// }}}
// {{{ _getChannelFromAlias()
 
return $channel;
}
 
/**
* Get the alias of a channel from its alias or its name
*/
553,19 → 593,25
if ($channel == 'pear.php.net') {
return 'pear';
}
 
if ($channel == 'pecl.php.net') {
return 'pecl';
}
 
if ($channel == 'doc.php.net') {
return 'phpdocs';
}
 
return false;
}
 
$channel = $this->_getChannel($channel);
if (PEAR::isError($channel)) {
return $channel;
}
 
return $channel->getAlias();
}
// }}}
// {{{ _channelDirectoryName()
}
 
/**
* Get the name of the file where data for a given package is stored.
581,84 → 627,79
{
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
return $this->statedir;
} else {
$ch = $this->_getChannelFromAlias($channel);
if (!$ch) {
$ch = $channel;
}
return $this->statedir . DIRECTORY_SEPARATOR . strtolower('.channel.' .
str_replace('/', '_', $ch));
}
 
$ch = $this->_getChannelFromAlias($channel);
if (!$ch) {
$ch = $channel;
}
 
return $this->statedir . DIRECTORY_SEPARATOR . strtolower('.channel.' .
str_replace('/', '_', $ch));
}
 
// }}}
// {{{ _openPackageFile()
 
function _openPackageFile($package, $mode, $channel = false)
{
if (!$this->_assertStateDir($channel)) {
return null;
}
 
if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {
return null;
}
 
$file = $this->_packageFileName($package, $channel);
if (!file_exists($file) && $mode == 'r' || $mode == 'rb') {
return null;
}
 
$fp = @fopen($file, $mode);
if (!$fp) {
return null;
}
 
return $fp;
}
 
// }}}
// {{{ _closePackageFile()
 
function _closePackageFile($fp)
{
fclose($fp);
}
 
// }}}
// {{{ _openChannelFile()
 
function _openChannelFile($channel, $mode)
{
if (!$this->_assertChannelDir()) {
return null;
}
 
if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {
return null;
}
 
$file = $this->_channelFileName($channel);
if (!file_exists($file) && $mode == 'r' || $mode == 'rb') {
return null;
}
 
$fp = @fopen($file, $mode);
if (!$fp) {
return null;
}
 
return $fp;
}
 
// }}}
// {{{ _closePackageFile()
 
function _closeChannelFile($fp)
{
fclose($fp);
}
 
// }}}
// {{{ _rebuildFileMap()
 
function _rebuildFileMap()
{
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
 
$channels = $this->_listAllPackages();
$files = array();
foreach ($channels as $channel => $packages) {
668,37 → 709,43
if (!is_array($filelist)) {
continue;
}
 
foreach ($filelist as $name => $attrs) {
if (isset($attrs['attribs'])) {
$attrs = $attrs['attribs'];
}
 
// it is possible for conflicting packages in different channels to
// conflict with data files/doc files
if ($name == 'dirtree') {
continue;
}
 
if (isset($attrs['role']) && !in_array($attrs['role'],
PEAR_Installer_Role::getInstallableRoles())) {
// these are not installed
continue;
}
 
if (isset($attrs['role']) && !in_array($attrs['role'],
PEAR_Installer_Role::getBaseinstallRoles())) {
$attrs['baseinstalldir'] = $package;
}
 
if (isset($attrs['baseinstalldir'])) {
$file = $attrs['baseinstalldir'].DIRECTORY_SEPARATOR.$name;
} else {
$file = $name;
}
 
$file = preg_replace(',^/+,', '', $file);
if ($channel != 'pear.php.net') {
if (!isset($files[$attrs['role']])) {
$files[$attrs['role']] = array();
}
$files[$attrs['role']][$file] = array(strtolower($channel),
strtolower($package));
} else {
if (!is_array($files)) {
$file = array();
}
if (!isset($files[$attrs['role']])) {
$files[$attrs['role']] = array();
}
707,14 → 754,18
}
}
}
 
 
$this->_assertStateDir();
if (!$this->hasWriteAccess()) {
return false;
}
 
$fp = @fopen($this->filemap, 'wb');
if (!$fp) {
return false;
}
 
$this->filemap_cache = $files;
fwrite($fp, serialize($files));
fclose($fp);
721,36 → 772,30
return true;
}
 
// }}}
// {{{ _readFileMap()
 
function _readFileMap()
{
if (!file_exists($this->filemap)) {
return array();
}
 
$fp = @fopen($this->filemap, 'r');
if (!$fp) {
return $this->raiseError('PEAR_Registry: could not open filemap "' . $this->filemap . '"', PEAR_REGISTRY_ERROR_FILE, null, null, $php_errormsg);
}
 
clearstatcache();
$rt = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
$fsize = filesize($this->filemap);
fclose($fp);
$data = file_get_contents($this->filemap);
set_magic_quotes_runtime($rt);
$tmp = unserialize($data);
if (!$tmp && $fsize > 7) {
return $this->raiseError('PEAR_Registry: invalid filemap data', PEAR_REGISTRY_ERROR_FORMAT, null, null, $data);
}
 
$this->filemap_cache = $tmp;
return true;
}
 
// }}}
// {{{ _lock()
 
/**
* Lock the registry.
*
765,52 → 810,60
*/
function _lock($mode = LOCK_EX)
{
if (!eregi('Windows 9', php_uname())) {
if ($mode != LOCK_UN && is_resource($this->lock_fp)) {
// XXX does not check type of lock (LOCK_SH/LOCK_EX)
return true;
if (stristr(php_uname(), 'Windows 9')) {
return true;
}
 
if ($mode != LOCK_UN && is_resource($this->lock_fp)) {
// XXX does not check type of lock (LOCK_SH/LOCK_EX)
return true;
}
 
if (!$this->_assertStateDir()) {
if ($mode == LOCK_EX) {
return $this->raiseError('Registry directory is not writeable by the current user');
}
if (!$this->_assertStateDir()) {
if ($mode == LOCK_EX) {
return $this->raiseError('Registry directory is not writeable by the current user');
} else {
return true;
}
 
return true;
}
 
$open_mode = 'w';
// XXX People reported problems with LOCK_SH and 'w'
if ($mode === LOCK_SH || $mode === LOCK_UN) {
if (!file_exists($this->lockfile)) {
touch($this->lockfile);
}
$open_mode = 'w';
// XXX People reported problems with LOCK_SH and 'w'
if ($mode === LOCK_SH || $mode === LOCK_UN) {
if (!file_exists($this->lockfile)) {
touch($this->lockfile);
}
$open_mode = 'r';
}
$open_mode = 'r';
}
 
if (!is_resource($this->lock_fp)) {
$this->lock_fp = @fopen($this->lockfile, $open_mode);
if (!is_resource($this->lock_fp)) {
$this->lock_fp = @fopen($this->lockfile, $open_mode);
}
 
if (!is_resource($this->lock_fp)) {
$this->lock_fp = null;
return $this->raiseError("could not create lock file" .
(isset($php_errormsg) ? ": " . $php_errormsg : ""));
}
 
if (!(int)flock($this->lock_fp, $mode)) {
switch ($mode) {
case LOCK_SH: $str = 'shared'; break;
case LOCK_EX: $str = 'exclusive'; break;
case LOCK_UN: $str = 'unlock'; break;
default: $str = 'unknown'; break;
}
 
if (!is_resource($this->lock_fp)) {
return $this->raiseError("could not create lock file" .
(isset($php_errormsg) ? ": " . $php_errormsg : ""));
}
if (!(int)flock($this->lock_fp, $mode)) {
switch ($mode) {
case LOCK_SH: $str = 'shared'; break;
case LOCK_EX: $str = 'exclusive'; break;
case LOCK_UN: $str = 'unlock'; break;
default: $str = 'unknown'; break;
}
return $this->raiseError("could not acquire $str lock ($this->lockfile)",
PEAR_REGISTRY_ERROR_LOCK);
}
//is resource at this point, close it on error.
fclose($this->lock_fp);
$this->lock_fp = null;
return $this->raiseError("could not acquire $str lock ($this->lockfile)",
PEAR_REGISTRY_ERROR_LOCK);
}
 
return true;
}
 
// }}}
// {{{ _unlock()
 
function _unlock()
{
$ret = $this->_lock(LOCK_UN);
817,23 → 870,19
if (is_resource($this->lock_fp)) {
fclose($this->lock_fp);
}
 
$this->lock_fp = null;
return $ret;
}
 
// }}}
// {{{ _packageExists()
 
function _packageExists($package, $channel = false)
{
return file_exists($this->_packageFileName($package, $channel));
}
 
// }}}
// {{{ _channelExists()
 
/**
* Determine whether a channel exists in the registry
*
* @param string Channel name
* @param bool if true, then aliases will be ignored
* @return boolean
844,15 → 893,42
if (!$a && $channel == 'pear.php.net') {
return true;
}
 
if (!$a && $channel == 'pecl.php.net') {
return true;
}
 
if (!$a && $channel == 'doc.php.net') {
return true;
}
 
return $a;
}
 
// }}}
// {{{ _addChannel()
/**
* Determine whether a mirror exists within the deafult channel in the registry
*
* @param string Channel name
* @param string Mirror name
*
* @return boolean
*/
function _mirrorExists($channel, $mirror)
{
$data = $this->_channelInfo($channel);
if (!isset($data['servers']['mirror'])) {
return false;
}
 
foreach ($data['servers']['mirror'] as $m) {
if ($m['attribs']['host'] == $mirror) {
return true;
}
}
 
return false;
}
 
/**
* @param PEAR_ChannelFile Channel object
* @param donotuse
864,17 → 940,21
if (!is_a($channel, 'PEAR_ChannelFile')) {
return false;
}
 
if (!$channel->validate()) {
return false;
}
 
if (file_exists($this->_channelFileName($channel->getName()))) {
if (!$update) {
return false;
}
 
$checker = $this->_getChannel($channel->getName());
if (PEAR::isError($checker)) {
return $checker;
}
 
if ($channel->getAlias() != $checker->getAlias()) {
if (file_exists($this->_getChannelAliasFileName($checker->getAlias()))) {
@unlink($this->_getChannelAliasFileName($checker->getAlias()));
881,40 → 961,49
}
}
} else {
if ($update && !in_array($channel->getName(), array('pear.php.net', 'pecl.php.net'))) {
if ($update && !in_array($channel->getName(), array('pear.php.net', 'pecl.php.net', 'doc.php.net'))) {
return false;
}
}
 
$ret = $this->_assertChannelDir();
if (PEAR::isError($ret)) {
return $ret;
}
 
$ret = $this->_assertChannelStateDir($channel->getName());
if (PEAR::isError($ret)) {
return $ret;
}
 
if ($channel->getAlias() != $channel->getName()) {
if (file_exists($this->_getChannelAliasFileName($channel->getAlias())) &&
$this->_getChannelFromAlias($channel->getAlias()) != $channel->getName()) {
$channel->setAlias($channel->getName());
}
 
if (!$this->hasWriteAccess()) {
return false;
}
 
$fp = @fopen($this->_getChannelAliasFileName($channel->getAlias()), 'w');
if (!$fp) {
return false;
}
 
fwrite($fp, $channel->getName());
fclose($fp);
}
 
if (!$this->hasWriteAccess()) {
return false;
}
 
$fp = @fopen($this->_channelFileName($channel->getName()), 'wb');
if (!$fp) {
return false;
}
 
$info = $channel->toArray();
if ($lastmodified) {
$info['_lastmodified'] = $lastmodified;
921,14 → 1010,12
} else {
$info['_lastmodified'] = date('r');
}
 
fwrite($fp, serialize($info));
fclose($fp);
return true;
}
 
// }}}
// {{{ _deleteChannel()
 
/**
* Deletion fails if there are any packages installed from the channel
* @param string|PEAR_ChannelFile channel name
937,39 → 1024,51
function _deleteChannel($channel)
{
if (!is_string($channel)) {
if (is_a($channel, 'PEAR_ChannelFile')) {
if (!$channel->validate()) {
return false;
}
$channel = $channel->getName();
} else {
if (!is_a($channel, 'PEAR_ChannelFile')) {
return false;
}
 
if (!$channel->validate()) {
return false;
}
$channel = $channel->getName();
}
 
if ($this->_getChannelFromAlias($channel) == '__uri') {
return false;
}
 
if ($this->_getChannelFromAlias($channel) == 'pecl.php.net') {
return false;
}
 
if ($this->_getChannelFromAlias($channel) == 'doc.php.net') {
return false;
}
 
if (!$this->_channelExists($channel)) {
return false;
}
 
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
return false;
}
 
$channel = $this->_getChannelFromAlias($channel);
if ($channel == 'pear.php.net') {
return false;
}
 
$test = $this->_listChannelPackages($channel);
if (count($test)) {
return false;
}
 
$test = @rmdir($this->_channelDirectoryName($channel));
if (!$test) {
return false;
}
 
$file = $this->_getChannelAliasFileName($this->_getAlias($channel));
if (file_exists($file)) {
$test = @unlink($file);
977,17 → 1076,16
return false;
}
}
 
$file = $this->_channelFileName($channel);
$ret = true;
if (file_exists($file)) {
$ret = @unlink($file);
}
 
return $ret;
}
 
// }}}
// {{{ _isChannelAlias()
 
/**
* Determine whether a channel exists in the registry
* @param string Channel Alias
998,9 → 1096,6
return file_exists($this->_getChannelAliasFileName($alias));
}
 
// }}}
// {{{ _packageInfo()
 
/**
* @param string|null
* @param string|null
1022,8 → 1117,10
$ret[$channel][] = $this->_packageInfo($package, null, $channel);
}
}
 
return $ret;
}
 
$ps = $this->_listPackages($channel);
if (!count($ps)) {
return array();
1032,33 → 1129,32
$ps, array_fill(0, count($ps), null),
array_fill(0, count($ps), $channel));
}
 
$fp = $this->_openPackageFile($package, 'r', $channel);
if ($fp === null) {
return null;
}
$rt = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
 
clearstatcache();
$this->_closePackageFile($fp);
$data = file_get_contents($this->_packageFileName($package, $channel));
set_magic_quotes_runtime($rt);
$data = unserialize($data);
if ($key === null) {
return $data;
}
 
// compatibility for package.xml version 2.0
if (isset($data['old'][$key])) {
return $data['old'][$key];
}
 
if (isset($data[$key])) {
return $data[$key];
}
 
return null;
}
 
// }}}
// {{{ _channelInfo()
 
/**
* @param string Channel name
* @param bool whether to strictly retrieve info of channels, not just aliases
1069,73 → 1165,83
if (!$this->_channelExists($channel, $noaliases)) {
return null;
}
 
$fp = $this->_openChannelFile($channel, 'r');
if ($fp === null) {
return null;
}
$rt = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
 
clearstatcache();
$this->_closeChannelFile($fp);
$data = file_get_contents($this->_channelFileName($channel));
set_magic_quotes_runtime($rt);
$data = unserialize($data);
return $data;
}
 
// }}}
// {{{ _listChannels()
 
function _listChannels()
{
$channellist = array();
if (!file_exists($this->channelsdir) || !is_dir($this->channelsdir)) {
return array('pear.php.net', 'pecl.php.net', '__uri');
return array('pear.php.net', 'pecl.php.net', 'doc.php.net', '__uri');
}
 
$dp = opendir($this->channelsdir);
while ($ent = readdir($dp)) {
if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
continue;
}
 
if ($ent == '__uri.reg') {
$channellist[] = '__uri';
continue;
}
 
$channellist[] = str_replace('_', '/', substr($ent, 0, -4));
}
 
closedir($dp);
if (!in_array('pear.php.net', $channellist)) {
$channellist[] = 'pear.php.net';
}
 
if (!in_array('pecl.php.net', $channellist)) {
$channellist[] = 'pecl.php.net';
}
 
if (!in_array('doc.php.net', $channellist)) {
$channellist[] = 'doc.php.net';
}
 
 
if (!in_array('__uri', $channellist)) {
$channellist[] = '__uri';
}
 
natsort($channellist);
return $channellist;
}
 
// }}}
// {{{ _listPackages()
 
function _listPackages($channel = false)
{
if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
return $this->_listChannelPackages($channel);
}
 
if (!file_exists($this->statedir) || !is_dir($this->statedir)) {
return array();
}
 
$pkglist = array();
$dp = opendir($this->statedir);
if (!$dp) {
return $pkglist;
}
 
while ($ent = readdir($dp)) {
if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
continue;
}
 
$pkglist[] = substr($ent, 0, -4);
}
closedir($dp);
1142,9 → 1248,6
return $pkglist;
}
 
// }}}
// {{{ _listChannelPackages()
 
function _listChannelPackages($channel)
{
$pkglist = array();
1152,10 → 1255,12
!is_dir($this->_channelDirectoryName($channel))) {
return array();
}
 
$dp = opendir($this->_channelDirectoryName($channel));
if (!$dp) {
return $pkglist;
}
 
while ($ent = readdir($dp)) {
if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
continue;
1162,12 → 1267,11
}
$pkglist[] = substr($ent, 0, -4);
}
 
closedir($dp);
return $pkglist;
}
 
// }}}
function _listAllPackages()
{
$ret = array();
1174,6 → 1278,7
foreach ($this->_listChannels() as $channel) {
$ret[$channel] = $this->_listPackages($channel);
}
 
return $ret;
}
 
1189,10 → 1294,12
if ($this->_packageExists($package)) {
return false;
}
 
$fp = $this->_openPackageFile($package, 'wb');
if ($fp === null) {
return false;
}
 
$info['_lastmodified'] = time();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
1199,6 → 1306,7
if (isset($info['filelist'])) {
$this->_rebuildFileMap();
}
 
return true;
}
 
1209,6 → 1317,10
*/
function _addPackage2($info)
{
if (!is_a($info, 'PEAR_PackageFile_v1') && !is_a($info, 'PEAR_PackageFile_v2')) {
return false;
}
 
if (!$info->validate()) {
if (class_exists('PEAR_Common')) {
$ui = PEAR_Frontend::singleton();
1220,6 → 1332,7
}
return false;
}
 
$channel = $info->getChannel();
$package = $info->getPackage();
$save = $info;
1226,17 → 1339,21
if ($this->_packageExists($package, $channel)) {
return false;
}
 
if (!$this->_channelExists($channel, true)) {
return false;
}
 
$info = $info->toArray(true);
if (!$info) {
return false;
}
 
$fp = $this->_openPackageFile($package, 'wb', $channel);
if ($fp === null) {
return false;
}
 
$info['_lastmodified'] = time();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
1256,14 → 1373,17
if (empty($oldinfo)) {
return false;
}
 
$fp = $this->_openPackageFile($package, 'w');
if ($fp === null) {
return false;
}
 
if (is_object($info)) {
$info = $info->toArray();
}
$info['_lastmodified'] = time();
 
$newinfo = $info;
if ($merge) {
$info = array_merge($oldinfo, $info);
1270,11 → 1390,13
} else {
$diff = $info;
}
 
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
if (isset($newinfo['filelist'])) {
$this->_rebuildFileMap();
}
 
return true;
}
 
1288,10 → 1410,12
if (!$this->_packageExists($info->getPackage(), $info->getChannel())) {
return false;
}
 
$fp = $this->_openPackageFile($info->getPackage(), 'w', $info->getChannel());
if ($fp === null) {
return false;
}
 
$save = $info;
$info = $save->getArray(true);
$info['_lastmodified'] = time();
1313,15 → 1437,18
if ($info === null) {
return $info;
}
 
$a = $this->_config;
if (!$a) {
$this->_config = &new PEAR_Config;
$this->_config = new PEAR_Config;
$this->_config->set('php_dir', $this->statedir);
}
 
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$pkg = &new PEAR_PackageFile($this->_config);
 
$pkg = new PEAR_PackageFile($this->_config);
$pf = &$pkg->fromArray($info);
return $pf;
}
1341,33 → 1468,41
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$ch = &PEAR_ChannelFile::fromArrayWithErrors($chinfo);
}
}
 
if ($ch) {
if ($ch->validate()) {
return $ch;
}
 
foreach ($ch->getErrors(true) as $err) {
$message = $err['message'] . "\n";
}
 
$ch = PEAR::raiseError($message);
return $ch;
}
 
if ($this->_getChannelFromAlias($channel) == 'pear.php.net') {
// the registry is not properly set up, so use defaults
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setName('pear.php.net');
$pear_channel->setServer('pear.php.net');
$pear_channel->setAlias('pear');
$pear_channel->setSummary('PHP Extension and Application Repository');
$pear_channel->setDefaultPEARProtocols();
$pear_channel->setBaseURL('REST1.0', 'http://pear.php.net/rest/');
$pear_channel->setBaseURL('REST1.1', 'http://pear.php.net/rest/');
$pear_channel->setBaseURL('REST1.3', 'http://pear.php.net/rest/');
return $pear_channel;
}
 
if ($this->_getChannelFromAlias($channel) == 'pecl.php.net') {
// the registry is not properly set up, so use defaults
if (!class_exists('PEAR_ChannelFile')) {
1374,7 → 1509,7
require_once 'PEAR/ChannelFile.php';
}
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setName('pecl.php.net');
$pear_channel->setServer('pecl.php.net');
$pear_channel->setAlias('pecl');
$pear_channel->setSummary('PHP Extension Community Library');
$pear_channel->setDefaultPEARProtocols();
1383,22 → 1518,42
$pear_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
return $pear_channel;
}
 
if ($this->_getChannelFromAlias($channel) == 'doc.php.net') {
// the registry is not properly set up, so use defaults
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$doc_channel = new PEAR_ChannelFile;
$doc_channel->setServer('doc.php.net');
$doc_channel->setAlias('phpdocs');
$doc_channel->setSummary('PHP Documentation Team');
$doc_channel->setDefaultPEARProtocols();
$doc_channel->setBaseURL('REST1.0', 'http://doc.php.net/rest/');
$doc_channel->setBaseURL('REST1.1', 'http://doc.php.net/rest/');
$doc_channel->setBaseURL('REST1.3', 'http://doc.php.net/rest/');
return $doc_channel;
}
 
 
if ($this->_getChannelFromAlias($channel) == '__uri') {
// the registry is not properly set up, so use defaults
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$private = new PEAR_ChannelFile;
$private->setName('__uri');
$private->addFunction('xmlrpc', '1.0', '****');
$private->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
return $private;
}
 
return $ch;
}
 
// {{{ packageExists()
 
/**
* @param string Package name
* @param string Channel name
1435,6 → 1590,23
 
// }}}
 
/**
* @param string channel name mirror is in
* @param string mirror name
*
* @return bool
*/
function mirrorExists($channel, $mirror)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
 
$ret = $this->_mirrorExists($channel, $mirror);
$this->_unlock();
return $ret;
}
 
// {{{ isAlias()
 
/**
1639,11 → 1811,13
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
 
$ret = $this->_deleteChannel($channel);
$this->_unlock();
if ($ret && is_a($this->_config, 'PEAR_Config')) {
$this->_config->setChannels($this->listChannels());
}
 
return $ret;
}
 
1657,20 → 1831,20
*/
function addChannel($channel, $lastmodified = false, $update = false)
{
if (!is_a($channel, 'PEAR_ChannelFile')) {
if (!is_a($channel, 'PEAR_ChannelFile') || !$channel->validate()) {
return false;
}
if (!$channel->validate()) {
return false;
}
 
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
 
$ret = $this->_addChannel($channel, $update, $lastmodified);
$this->_unlock();
if (!$update && $ret && is_a($this->_config, 'PEAR_Config')) {
$this->_config->setChannels($this->listChannels());
}
 
return $ret;
}
 
1682,12 → 1856,9
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
 
$file = $this->_packageFileName($package, $channel);
if (file_exists($file)) {
$ret = @unlink($file);
} else {
$ret = false;
}
$ret = file_exists($file) ? @unlink($file) : false;
$this->_rebuildFileMap();
$this->_unlock();
$p = array('channel' => $channel, 'package' => $package);
1726,15 → 1897,19
 
function updatePackage2($info)
{
 
if (!is_object($info)) {
return $this->updatePackage($info['package'], $info, $merge);
}
 
if (!$info->validate(PEAR_VALIDATE_DOWNLOADING)) {
return false;
}
 
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
 
$ret = $this->_updatePackage2($info);
$this->_unlock();
if ($ret) {
1741,6 → 1916,7
$this->_dependencyDB->uninstallPackage($info);
$this->_dependencyDB->installPackage($info);
}
 
return $ret;
}
 
1751,16 → 1927,16
* @param bool whether to strictly return raw channels (no aliases)
* @return PEAR_ChannelFile|PEAR_Error
*/
function &getChannel($channel, $noaliases = false)
function getChannel($channel, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = &$this->_getChannel($channel, $noaliases);
$ret = $this->_getChannel($channel, $noaliases);
$this->_unlock();
if (!$ret) {
return PEAR::raiseError('Unknown channel: ' . $channel);
}
$this->_unlock();
return $ret;
}
 
2149,7 → 2325,7
return PEAR::raiseError('parsePackageName(): "' . $param['version'] .
'" is neither a valid version nor a valid state in "' .
$saveparam . '"', 'version/state', null, null, $param);
}
}
}
}
return $param;
2210,5 → 2386,3
return $ret;
}
}
 
?>