Browse Source

fix optional dependencies in Dependency.php, remove ugly hack in Installer, add note about Cox's cool addition to pear install, remove noise of who did what from package.xml, fix #25008

PEAR_1_4DEV
Greg Beaver 23 years ago
parent
commit
dce4268282
  1. 40
      pear/PEAR/Dependency.php
  2. 14
      pear/PEAR/Installer.php
  3. 16
      pear/package-PEAR.xml

40
pear/PEAR/Dependency.php

@ -26,6 +26,7 @@ define('PEAR_DEPENDENCY_CONFLICT', -2);
define('PEAR_DEPENDENCY_UPGRADE_MINOR', -3);
define('PEAR_DEPENDENCY_UPGRADE_MAJOR', -4);
define('PEAR_DEPENDENCY_BAD_DEPENDENCY', -5);
define('PEAR_DEPENDENCY_MISSING_OPTIONAL', -6);
/**
* Dependency check for PEAR packages
@ -54,13 +55,16 @@ class PEAR_Dependency
* This method maps the XML dependency definition to the
* corresponding one from PEAR_Dependency
*
* <pre>
* $opts => Array
* (
* [type] => pkg
* [rel] => ge
* [version] => 3.4
* [name] => HTML_Common
* [optional] => false
* )
* </pre>
*
* @param string Error message
* @param array Options
@ -71,13 +75,15 @@ class PEAR_Dependency
$rel = isset($opts['rel']) ? $opts['rel'] : 'has';
$req = isset($opts['version']) ? $opts['version'] : null;
$name = isset($opts['name']) ? $opts['name'] : null;
$opt = (isset($opts['optional']) && $opts['optional'] == 'yes') ?
$opts['optional'] : null;
$errmsg = '';
switch ($opts['type']) {
case 'pkg':
return $this->checkPackage($errmsg, $name, $req, $rel);
return $this->checkPackage($errmsg, $name, $req, $rel, $opt);
break;
case 'ext':
return $this->checkExtension($errmsg, $name, $req, $rel);
return $this->checkExtension($errmsg, $name, $req, $rel, $opt);
break;
case 'php':
return $this->checkPHP($errmsg, $req, $rel);
@ -105,10 +111,12 @@ class PEAR_Dependency
* @param string $name Name of the package to test
* @param string $version The package version required
* @param string $relation How to compare versions with eachother
* @param bool $opt Whether the relationship is optional
*
* @return mixed bool false if no error or the error string
*/
function checkPackage(&$errmsg, $name, $req = null, $relation = 'has')
function checkPackage(&$errmsg, $name, $req = null, $relation = 'has',
$opt = false)
{
if (substr($relation, 0, 2) == 'v.') {
$relation = substr($relation, 2);
@ -116,6 +124,10 @@ class PEAR_Dependency
switch ($relation) {
case 'has':
if (!$this->registry->packageExists($name)) {
if ($opt) {
$errmsg = "package `$name' is recommended to utilize some features.";
return PEAR_DEPENDENCY_MISSING_OPTIONAL;
}
$errmsg = "requires package `$name'";
return PEAR_DEPENDENCY_MISSING;
}
@ -136,10 +148,14 @@ class PEAR_Dependency
if (!$this->registry->packageExists($name)
|| !version_compare("$version", "$req", $relation))
{
$code = $this->codeFromRelation($relation, $version, $req);
if ($opt) {
$errmsg = "package `$name' version $req is recommended to utilize some features.";
return PEAR_DEPENDENCY_MISSING_OPTIONAL;
}
$errmsg = "requires package `$name' " .
$this->signOperator($relation) . " $req";
$code = $this->codeFromRelation($relation, $version, $req);
return PEAR_DEPENDENCY_MISSING;
return $code;
}
return false;
}
@ -187,13 +203,19 @@ class PEAR_Dependency
* @param string $name Name of the extension to test
* @param string $req_ext_ver Required extension version to compare with
* @param string $relation How to compare versions with eachother
* @param bool $opt Whether the relationship is optional
*
* @return mixed bool false if no error or the error string
*/
function checkExtension(&$errmsg, $name, $req = null, $relation = 'has')
function checkExtension(&$errmsg, $name, $req = null, $relation = 'has',
$opt = false)
{
// XXX (ssb): could we avoid loading the extension here?
if (!PEAR::loadExtension($name)) {
if ($opt) {
$errmsg = "'$name' PHP extension is recommended to utilize some features";
return PEAR_DEPENDENCY_MISSING_OPTIONAL;
}
$errmsg = "'$name' PHP extension is not installed";
return PEAR_DEPENDENCY_MISSING;
}
@ -207,9 +229,13 @@ class PEAR_Dependency
// Force params to be strings, otherwise the comparation will fail (ex. 0.9==0.90)
settype($req, "string");
if (!version_compare("$ext_ver", "$req", $operator)) {
$retval = "'$name' PHP extension version " .
$errmsg = "'$name' PHP extension version " .
$this->signOperator($operator) . " $req is required";
$code = $this->codeFromRelation($relation, $ext_ver, $req);
if ($opt) {
$errmsg = "'$name' PHP extension version $req is recommended to utilize some features";
return PEAR_DEPENDENCY_MISSING_OPTIONAL;
}
}
}
return $code;

14
pear/PEAR/Installer.php

@ -222,6 +222,10 @@ class PEAR_Installer extends PEAR_Common
$this->log(3, "+ mkdir $dest_dir");
}
if (empty($atts['replacements'])) {
if (!file_exists($orig_file)) {
return $this->raiseError("file does not exist",
PEAR_INSTALLER_FAILED);
}
if (!@copy($orig_file, $dest_file)) {
return $this->raiseError("failed to write $dest_file",
PEAR_INSTALLER_FAILED);
@ -231,6 +235,10 @@ class PEAR_Installer extends PEAR_Common
$md5sum = md5_file($dest_file);
}
} else {
if (!file_exists($orig_file)) {
return $this->raiseError("file does not exist",
PEAR_INSTALLER_FAILED);
}
$fp = fopen($orig_file, "r");
$contents = fread($fp, filesize($orig_file));
fclose($fp);
@ -906,6 +914,9 @@ class PEAR_Installer extends PEAR_Common
if (PEAR::isError($res)) {
if (empty($options['ignore-errors'])) {
$this->rollbackFileTransaction();
if ($res->getMessage() == "file does not exist") {
$this->raiseError("file $file in package.xml does not exist");
}
return $this->raiseError($res);
} else {
$this->log(0, "Warning: " . $res->getMessage());
@ -1041,10 +1052,11 @@ class PEAR_Installer extends PEAR_Common
$code = $depchecker->callCheckMethod($error, $dep);
if ($code) {
if (isset($dep['optional']) && $dep['optional'] == 'yes') {
/* die ugly hack die
// Ugly hack to adjust the error messages
$error = str_replace('requires ', '', $error);
$error = ucfirst($error);
$error = $error . ' is recommended to utilize some features.';
$error = $error . ' is recommended to utilize some features.';*/
$optional_deps[] = array($dep, $code, $error);
} else {
$failed_deps[] = array($dep, $code, $error);

16
pear/package-PEAR.xml

@ -50,17 +50,21 @@
* Fixed #25131 - OS_Guess warnings on empty lines from
popen(&quot;/usr/bin/cpp $tmpfile&quot;, &quot;r&quot;);
* Fixed #25117 - MD5 checksum should be case-insensitive
* Fixed static calls to PEAR error-handling methods in classes (Greg)
* Fixed static calls to PEAR error-handling methods in classes
* Added ability to use a static method callback for error-handling, and removed
use of inadvisable @ in setErrorHandling (Greg)
* Added dependency on XML_RPC, and optional dependency on xmlrpc extension (Greg)
* Added --alldeps and --onlyreqdeps options to pear install/pear upgrade (Greg)
use of inadvisable @ in setErrorHandling
* Added dependency on XML_RPC, and optional dependency on xmlrpc extension
* Added --alldeps and --onlyreqdeps options to pear install/pear upgrade
* Sorting of installation/uninstallation so package order on the command-line is
insignificant (fixes upgrade-all if every package is installed) (Greg)
insignificant (fixes upgrade-all if every package is installed)
* pear upgrade will now install if the package is not installed (necessary for
pear upgrade --alldeps, as installation is often necessary for new
dependencies) (Greg)
dependencies)
* fixed pear.bat if PHP is installed in a path like C:\Program Files\php (Greg)
* Add ability to specify pear install DB-1.2, or pear install DB-stable, or
pear install DB-1.2.tar to download as uncompressed tar
* Fix #25008 - unhelpful error message
* Fixed optional dependencies in Dependency.php
</notes>
<provides type="class" name="OS_Guess" />
<provides type="class" name="System" />

Loading…
Cancel
Save