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

14
pear/PEAR/Installer.php

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

16
pear/package-PEAR.xml

@ -50,17 +50,21 @@
* Fixed #25131 - OS_Guess warnings on empty lines from * Fixed #25131 - OS_Guess warnings on empty lines from
popen(&quot;/usr/bin/cpp $tmpfile&quot;, &quot;r&quot;); popen(&quot;/usr/bin/cpp $tmpfile&quot;, &quot;r&quot;);
* Fixed #25117 - MD5 checksum should be case-insensitive * 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 * 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 * 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 will now install if the package is not installed (necessary for
pear upgrade --alldeps, as installation is often necessary for new 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) * 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> </notes>
<provides type="class" name="OS_Guess" /> <provides type="class" name="OS_Guess" />
<provides type="class" name="System" /> <provides type="class" name="System" />

Loading…
Cancel
Save