{
parent::PEAR();
$ds = DIRECTORY_SEPARATOR;
- $this->statedir = $pear_install_dir.$ds.".registry";
- $this->filemap = $pear_install_dir.$ds.".filemap";
- $this->lockfile = $pear_install_dir.$ds.".lock";
+ $this->statedir = $pear_install_dir.$ds.'.registry';
+ $this->filemap = $pear_install_dir.$ds.'.filemap';
+ $this->lockfile = $pear_install_dir.$ds.'.lock';
if (!file_exists($this->filemap)) {
$this->_rebuildFileMap();
}
$packages = $this->listPackages();
$files = array();
foreach ($packages as $package) {
- $version = $this->packageInfo($package, "version");
- $filelist = $this->packageInfo($package, "filelist");
+ $version = $this->packageInfo($package, 'version');
+ $filelist = $this->packageInfo($package, 'filelist');
if (!is_array($filelist)) {
continue;
}
}
}
$this->_assertStateDir();
- $fp = @fopen($this->filemap, "w");
+ $fp = @fopen($this->filemap, 'w');
if (!$fp) {
return false;
}
// }}}
// {{{ _lock()
+ /**
+ * Lock the registry.
+ *
+ * @param integer lock mode, one of LOCK_EX, LOCK_SH or LOCK_UN.
+ * See flock manual for more information.
+ *
+ * @return bool TRUE on success, FALSE if locking failed, or a
+ * PEAR error if some other error occurs (such as the
+ * lock file not being writable).
+ *
+ * @access private
+ */
function _lock($mode = LOCK_EX)
{
if ($mode != LOCK_UN && is_resource($this->lock_fp)) {
// XXX does not check type of lock (LOCK_SH/LOCK_EX)
return true;
}
- $php_dir = dirname($this->lockfile);
- if (!@is_dir($php_dir) && !System::mkDir("-p $php_dir")) {
- return false;
- }
- $this->lock_fp = @fopen($this->lockfile, "w");
+ $this->lock_fp = @fopen($this->lockfile, 'w');
if (!is_resource($this->lock_fp)) {
- return null;
+ return $this->raiseError("could not create lock file: $php_errormsg");
}
return (int)flock($this->lock_fp, $mode);
}
function _packageInfo($package = null, $key = null)
{
if ($package === null) {
- return array_map(array($this, "_packageInfo"),
+ return array_map(array($this, '_packageInfo'),
$this->_listPackages());
}
- $fp = $this->_openPackageFile($package, "r");
+ $fp = $this->_openPackageFile($package, 'r');
if ($fp === null) {
return null;
}
return $pkglist;
}
while ($ent = readdir($dp)) {
- if ($ent{0} == "." || substr($ent, -4) != ".reg") {
+ if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
continue;
}
$pkglist[] = substr($ent, 0, -4);
function packageExists($package)
{
if (!$this->_lock(LOCK_SH)) {
- return $this->raiseError("could not acquire shared lock", PEAR_REGISTRY_ERROR_LOCK);
+ return $this->raiseError("could not acquire shared lock ($this->lockfile)", PEAR_REGISTRY_ERROR_LOCK, null, null, "lockfile=$this->lockfile");
}
$ret = $this->_packageExists($package);
$this->_unlock();
function packageInfo($package = null, $key = null)
{
if (!$this->_lock(LOCK_SH)) {
- return $this->raiseError("could not acquire shared lock", PEAR_REGISTRY_ERROR_LOCK);
+ return $this->raiseError("could not acquire shared lock ($this->lockfile)", PEAR_REGISTRY_ERROR_LOCK, null, null, "lockfile=$this->lockfile");
}
$ret = $this->_packageInfo($package, $key);
$this->_unlock();
function listPackages()
{
if (!$this->_lock(LOCK_SH)) {
- return $this->raiseError("could not acquire shared lock", PEAR_REGISTRY_ERROR_LOCK);
+ return $this->raiseError("could not acquire shared lock ($this->lockfile)", PEAR_REGISTRY_ERROR_LOCK, null, null, "lockfile=$this->lockfile");
}
$ret = $this->_listPackages();
$this->_unlock();
return false;
}
if (!$this->_lock(LOCK_EX)) {
- return $this->raiseError("could not acquire exclusive lock", PEAR_REGISTRY_ERROR_LOCK);
+ return $this->raiseError("could not acquire exclusive lock ($this->lockfile)", PEAR_REGISTRY_ERROR_LOCK, null, null, "lockfile=$this->lockfile");
}
- $fp = $this->_openPackageFile($package, "w");
+ $fp = $this->_openPackageFile($package, 'w');
if ($fp === null) {
$this->_unlock();
return false;
function deletePackage($package)
{
if (!$this->_lock(LOCK_EX)) {
- return $this->raiseError("could not acquire exclusive lock", PEAR_REGISTRY_ERROR_LOCK);
+ return $this->raiseError("could not acquire exclusive lock ($this->lockfile)", PEAR_REGISTRY_ERROR_LOCK, null, null, "lockfile=$this->lockfile");
}
$file = $this->_packageFileName($package);
$ret = @unlink($file);
return false;
}
if (!$this->_lock(LOCK_EX)) {
- return $this->raiseError("could not acquire exclusive lock", PEAR_REGISTRY_ERROR_LOCK);
+ return $this->raiseError("could not acquire exclusive lock ($this->lockfile)", PEAR_REGISTRY_ERROR_LOCK, null, null, "lockfile=$this->lockfile");
}
if (!file_exists($this->filemap)) {
$this->_rebuildFileMap();
}
- $fp = $this->_openPackageFile($package, "w");
+ $fp = $this->_openPackageFile($package, 'w');
if ($fp === null) {
$this->_unlock();
return false;