define('PEAR_INSTALLER_OK', 1);
define('PEAR_INSTALLER_FAILED', 0);
define('PEAR_INSTALLER_SKIPPED', -1);
+define('PEAR_INSTALLER_ERROR_NO_PREF_STATE', 2);
/**
* Administration class used to install PEAR packages and maintain the
}
} elseif ($a['type'] == 'package-info') {
if (isset($this->pkginfo[$a['to']]) && is_string($this->pkginfo[$a['to']])) {
- $to = $this->pkginfo[$a['to']];
+ $to = $this->pkginfo[$a['to']];
} else {
$this->log(0, "invalid package-info replacement: $a[to]");
continue;
@unlink($dest_file);
return $this->raiseError("bad md5sum for file $final_dest_file",
PEAR_INSTALLER_FAILED);
- } else {
- $this->log(0, "warning : bad md5sum for file $final_dest_file");
+ } else {
+ $this->log(0, "warning : bad md5sum for file $final_dest_file");
+ }
}
}
- }
if (!OS_WINDOWS) {
if ($atts['role'] == 'script') {
$mode = 0777 & ~(int)octdec($this->config->get('umask'));
}
// }}}
-
// {{{ _prependPath($path, $prepend)
function _prependPath($path, $prepend)
* @param string version/state
* @param string original value passed to command-line
* @param string preferred state (snapshot/devel/alpha/beta/stable)
+ * @return null|PEAR_Error|string
* @access private
*/
function _downloadFile($pkgfile, &$config, $options, &$errors, $version,
return $this->raiseError('No releases of preferred state "'
. $state . '" exist for package ' . $origpkgfile .
'. Use ' . $origpkgfile . '-state to install another' .
- ' state (like ' . $origpkgfile .'-beta)');
+ ' state (like ' . $origpkgfile .'-beta)',
+ PEAR_INSTALLER_ERROR_NO_PREF_STATE);
}
} else {
return $pkgfile;
}
} else {
- return $this->raiseError($file);
- }
+ return $this->raiseError($file);
+ }
}
$pkgfile = $file;
}
if (!is_file($pkgfile)) {
$origpkgfile = $pkgfile;
$pkgfile = $this->extractDownloadFileName($pkgfile, $version);
+ $version_is_state = false;
if ($version === null) {
// use preferred state if no version number was specified
$version = $state;
+ $version_is_state = true;
}
if ($this->validPackageName($pkgfile) && !isset($options['upgrade'])) {
if ($this->registry->packageExists($pkgfile)) {
continue;
}
}
- $pkgfile = $this->_downloadFile($pkgfile, $config, $options, $errors,
- $version, $origpkgfile, $state);
- if (PEAR::isError($pkgfile)) {
- return $pkgfile;
+ if ($version_is_state) {
+ $savepkgfile = $pkgfile;
+ PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
+ $pkgfile = $this->_downloadFile($pkgfile, $config, $options,
+ $errors, $version, $origpkgfile,
+ $state);
+ PEAR::popErrorHandling();
+ if (PEAR::isError($pkgfile) &&
+ $pkgfile->getCode() != PEAR_INSTALLER_ERROR_NO_PREF_STATE) {
+ return $pkgfile;
+ } elseif (PEAR::isError($pkgfile)) {
+ $pkgfile = $savepkgfile;
+ $states = $this->betterStates($state, false);
+ $init = true;
+ // try from stable down to preferred_state
+ while(($init || (PEAR::isError($pkgfile) &&
+ $pkgfile->getCode() == PEAR_INSTALLER_ERROR_NO_PREF_STATE))
+ && count($states)) {
+ $pkgfile = $savepkgfile;
+ $init = false;
+ $nextstate = array_pop($states);
+ PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
+ $pkgfile = $this->_downloadFile($pkgfile, $config, $options,
+ $errors, $nextstate, $origpkgfile,
+ $state);
+ PEAR::popErrorHandling();
+ }
+ if (PEAR::isError($pkgfile)) {
+ return $pkgfile;
+ }
+ }
+ } else {
+ $pkgfile = $this->_downloadFile($pkgfile, $config, $options,
+ $errors, $version, $origpkgfile,
+ $state);
+ if (PEAR::isError($pkgfile)) {
+ return $pkgfile;
+ }
}
}
$tempinfo = $this->infoFromAny($pkgfile);
* - alldeps : install all dependencies
* - onlyreqdeps : install only required dependencies
*
- * @return array package info if successful, null if not
+ * @return array|PEAR_Error package info if successful
*/
function install($pkgfile, $options = array())
return $this->raiseError("$pkgname not installed");
}*/
if ($this->registry->packageExists($pkgname)) {
- $v1 = $this->registry->packageInfo($pkgname, 'version');
- $v2 = $pkginfo['version'];
- $cmp = version_compare("$v1", "$v2", 'gt');
- if (empty($options['force']) && !version_compare("$v2", "$v1", 'gt')) {
- return $this->raiseError("upgrade to a newer version ($v2 is not newer than $v1)");
- }
- if (empty($options['register-only'])) {
- // when upgrading, remove old release's files first:
- if (PEAR::isError($err = $this->_deletePackageFiles($pkgname))) {
- return $this->raiseError($err);
+ $v1 = $this->registry->packageInfo($pkgname, 'version');
+ $v2 = $pkginfo['version'];
+ $cmp = version_compare("$v1", "$v2", 'gt');
+ if (empty($options['force']) && !version_compare("$v2", "$v1", 'gt')) {
+ return $this->raiseError("upgrade to a newer version ($v2 is not newer than $v1)");
+ }
+ if (empty($options['register-only'])) {
+ // when upgrading, remove old release's files first:
+ if (PEAR::isError($err = $this->_deletePackageFiles($pkgname))) {
+ return $this->raiseError($err);
+ }
}
}
}
- }
// Copy files to dest dir ---------------------------------------
return $this->raiseError("commit failed", PEAR_INSTALLER_FAILED);
}
+ $ret = false;
// Register that the package is installed -----------------------
if (empty($options['upgrade'])) {
// if 'force' is used, replace the info in registry
}
}
if (!$ret) {
- return null;
+ return $this->raiseError("Adding package $pkgname to registry failed");
}
return $pkginfo;
}