cvs: pear-core /PEAR Registry.php

From: Date: Mon, 27 Mar 2006 04:24:45 +0000
Subject: cvs: pear-core /PEAR Registry.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-cvs+get-39350@lists.php.net to get a copy of this message
cellog Mon Mar 27 04:24:45 2006 UTC Modified files: /pear-core/PEAR Registry.php Log: remove as many @ as possible from PEAR_Registry

http://cvs.php.net/viewcvs.cgi/pear-core/PEAR/Registry.php?r1=1.153&r2=1.154&diff_format=u Index: pear-core/PEAR/Registry.php diff -u pear-core/PEAR/Registry.php:1.153 pear-core/PEAR/Registry.php:1.154 --- pear-core/PEAR/Registry.php:1.153 Sun Mar 26 21:38:37 2006 +++ pear-core/PEAR/Registry.php Mon Mar 27 04:24:45 2006 @@ -17,7 +17,7 @@ * @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.153 2006/03/26 21:38:37 cellog Exp $ + * @version CVS: $Id: Registry.php,v 1.154 2006/03/27 04:24:45 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 0.1 */ @@ -154,12 +154,12 @@ function hasWriteAccess() { - if (!@file_exists($this->install_dir)) { + if (!file_exists($this->install_dir)) { $dir = $this->install_dir; while ($dir && $dir != '.') { $dir = dirname($dir); // cd .. - if ($dir != '.' && @file_exists($dir)) { - if (@is_writeable($dir)) { + if ($dir != '.' && file_exists($dir)) { + if (is_writeable($dir)) { return true; } else { return false; @@ -168,7 +168,7 @@ } return false; } - return @is_writeable($this->install_dir); + return is_writeable($this->install_dir); } function setConfig(&$config) @@ -250,7 +250,8 @@ $ds = DIRECTORY_SEPARATOR; // XXX Compatibility code should be removed in the future // rename all registry files if any to lowercase - if (!OS_WINDOWS && $handle = @opendir($this->statedir)) { + if (!OS_WINDOWS && file_exists($this->statedir) && is_dir($this->statedir) && + $handle = opendir($this->statedir)) { $dest = $this->statedir . $ds; while (false !== ($file = readdir($handle))) { if (preg_match('/^.*[A-Z].*\.reg$/', $file)) { @@ -286,8 +287,11 @@ $this->_dependencyDB = &PEAR_DependencyDB::singleton($this->_config); if (PEAR::isError($this->_dependencyDB)) { // attempt to recover by removing the dep db - @unlink($this->_config->get('php_dir', null, 'pear.php.net') . - DIRECTORY_SEPARATOR . '.depdb'); + if (file_exists($this->_config->get('php_dir', null, 'pear.php.net') . + DIRECTORY_SEPARATOR . '.depdb')) { + @unlink($this->_config->get('php_dir', null, 'pear.php.net') . + DIRECTORY_SEPARATOR . '.depdb'); + } $this->_dependencyDB = &PEAR_DependencyDB::singleton($this->_config); if (PEAR::isError($this->_dependencyDB)) { echo $this->_dependencyDB->getMessage(); @@ -332,7 +336,7 @@ return $this->_assertChannelStateDir($channel); } static $init = false; - if (!@is_dir($this->statedir)) { + if (!file_exists($this->statedir)) { if (!$this->hasWriteAccess()) { return false; } @@ -341,13 +345,20 @@ return $this->raiseError("could not create directory '{$this->statedir}'"); } $init = true; + } elseif (!is_dir($this->statedir)) { + return $this->raiseError('Cannot create directory ' . $this->statedir . ', ' . + 'it already exists and is not a directory'); } $ds = DIRECTORY_SEPARATOR; - 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 . '__uri.reg')) { - $init = true; + 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 . '__uri.reg')) { + $init = true; + } + } elseif (!is_dir($this->channelsdir)) { + return $this->raiseError('Cannot create directory ' . $this->channelsdir . ', ' . + 'it already exists and is not a directory'); } if ($init) { static $running = false; @@ -389,7 +400,7 @@ !file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) { $this->_initializeChannelDirs(); } - if (!@is_dir($channelDir)) { + if (!file_exists($channelDir)) { if (!$this->hasWriteAccess()) { return false; } @@ -398,6 +409,9 @@ return $this->raiseError("could not create directory '" . $channelDir . "'"); } + } elseif (!is_dir($channelDir)) { + return $this->raiseError("could not create directory '" . $channelDir . + "', already exists and is not a directory"); } return true; } @@ -415,7 +429,7 @@ */ function _assertChannelDir() { - if (!@is_dir($this->channelsdir)) { + if (!file_exists($this->channelsdir)) { if (!$this->hasWriteAccess()) { return false; } @@ -423,8 +437,12 @@ if (!System::mkdir(array('-p', $this->channelsdir))) { return $this->raiseError("could not create directory '{$this->channelsdir}'"); } + } elseif (!is_dir($this->channelsdir)) { + return $this->raiseError("could not create directory '{$this->channelsdir}" . + "', it already exists and is not a directory"); + } - if (!@is_dir($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) { + if (!file_exists($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) { if (!$this->hasWriteAccess()) { return false; } @@ -432,6 +450,10 @@ if (!System::mkdir(array('-p', $this->channelsdir . DIRECTORY_SEPARATOR . '.alias'))) { return $this->raiseError("could not create directory '{$this->channelsdir}/.alias'"); } + } 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; } @@ -469,7 +491,7 @@ function _channelFileName($channel, $noaliases = false) { if (!$noaliases) { - if (@file_exists($this->_getChannelAliasFileName($channel))) { + if (file_exists($this->_getChannelAliasFileName($channel))) { $channel = implode('', file($this->_getChannelAliasFileName($channel))); } } @@ -580,6 +602,9 @@ 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; @@ -607,6 +632,9 @@ return null; } $file = $this->_channelFileName($channel); + if (!file_exists($file) && $mode == 'r' || $mode == 'rb') { + return null; + } $fp = @fopen($file, $mode); if (!$fp) { return null; @@ -691,6 +719,9 @@ 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); @@ -742,7 +773,7 @@ $open_mode = 'w'; // XXX People reported problems with LOCK_SH and 'w' if ($mode === LOCK_SH || $mode === LOCK_UN) { - if (@!is_file($this->lockfile)) { + if (!file_exists($this->lockfile)) { touch($this->lockfile); } $open_mode = 'r'; @@ -838,7 +869,9 @@ return $checker; } if ($channel->getAlias() != $checker->getAlias()) { - @unlink($this->_getChannelAliasFileName($checker->getAlias())); + if (file_exists($this->_getChannelAliasFileName($checker->getAlias()))) { + @unlink($this->_getChannelAliasFileName($checker->getAlias())); + } } } else { if ($update && !in_array($channel->getName(), array('pear.php.net', 'pecl.php.net'))) { @@ -931,14 +964,17 @@ return false; } $file = $this->_getChannelAliasFileName($this->_getAlias($channel)); - if (@file_exists($file)) { + if (file_exists($file)) { $test = @unlink($file); if (!$test) { return false; } } $file = $this->_channelFileName($channel); - $ret = @unlink($file); + $ret = true; + if (file_exists($file)) { + $ret = @unlink($file); + } return $ret; } @@ -1046,10 +1082,10 @@ function _listChannels() { $channellist = array(); - $dp = @opendir($this->channelsdir); - if (!$dp || !@is_dir($this->channelsdir)) { + if (!file_exists($this->channelsdir) || !is_dir($this->channelsdir)) { return array('pear.php.net', 'pecl.php.net', '__uri'); } + $dp = opendir($this->channelsdir); while ($ent = readdir($dp)) { if ($ent{0} == '.' || substr($ent, -4) != '.reg') { continue; @@ -1081,8 +1117,11 @@ 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); + $dp = opendir($this->statedir); if (!$dp) { return $pkglist; } @@ -1102,7 +1141,11 @@ function _listChannelPackages($channel) { $pkglist = array(); - $dp = @opendir($this->_channelDirectoryName($channel)); + if (!file_exists($this->_channelDirectoryName($channel)) || + !is_dir($this->_channelDirectoryName($channel))) { + return array(); + } + $dp = opendir($this->_channelDirectoryName($channel)); if (!$dp) { return $pkglist; } @@ -1633,7 +1676,11 @@ return $e; } $file = $this->_packageFileName($package, $channel); - $ret = @unlink($file); + if (file_exists($file)) { + $ret = @unlink($file); + } else { + $ret = false; + } $this->_rebuildFileMap(); $this->_unlock(); $p = array('channel' => $channel, 'package' => $package); @@ -1941,7 +1988,7 @@ $param['channel'] = '__uri'; } } else { - $components = @parse_url($param); + $components = @parse_url((string) $param); if (isset($components['scheme'])) { if ($components['scheme'] == 'http') { // uri package @@ -2124,7 +2171,9 @@ } $ret = 'channel://' . $upass . $parsed['channel'] . '/' . $parsed['package']; if (isset($parsed['version']) || isset($parsed['state'])) { - $ret .= '-' . @$parsed['version'] . @$parsed['state']; + $ver = isset($parsed['version']) ? $parsed['version'] : ''; + $ver .= isset($parsed['state']) ? $parsed['state'] : ''; + $ret .= '-' . $ver; } if (isset($parsed['extension'])) { $ret .= '.' . $parsed['extension'];
« previous php.pear.cvs (#39350) next »