219 if (!isset($this->_registry)) {
220 $this->_registry = &$this->config->getRegistry();
223 if (isset($atts[
'platform'])) {
228 if (strlen($atts[
'platform']) && $atts[
'platform'][0] ==
'!') {
230 $platform = substr($atts[
'platform'], 1);
233 $platform = $atts[
'platform'];
236 if ((
bool) $os->matchSignature($platform) === $negate) {
237 $this->
log(3,
"skipped $file (meant for $atts[platform], we are ".$os->getSignature().
")");
243 $channel = $this->pkginfo->getChannel();
245 switch ($atts[
'role']) {
248 $this->source_files++;
253 $dest_dir = $this->config->get($atts[
'role'] .
'_dir',
null, $channel) .
254 DIRECTORY_SEPARATOR . $this->pkginfo->getPackage();
255 unset($atts[
'baseinstalldir']);
259 $dest_dir = $this->config->get($atts[
'role'] .
'_dir',
null, $channel);
262 $dest_dir = $this->config->get(
'bin_dir',
null, $channel);
265 return $this->raiseError(
"Invalid role `$atts[role]' for file $file");
268 $save_destdir = $dest_dir;
269 if (!empty($atts[
'baseinstalldir'])) {
270 $dest_dir .= DIRECTORY_SEPARATOR . $atts[
'baseinstalldir'];
273 if (dirname($file) !=
'.' && empty($atts[
'install-as'])) {
274 $dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
277 if (empty($atts[
'install-as'])) {
278 $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
280 $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts[
'install-as'];
282 $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file;
285 $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
286 list($dest_file, $orig_file) = preg_replace(array(
'!\\\\+!',
'!/!',
"!$ds2+!"),
287 array(DIRECTORY_SEPARATOR,
289 DIRECTORY_SEPARATOR),
290 array($dest_file, $orig_file));
291 $final_dest_file = $installed_as = $dest_file;
292 if (isset($this->_options[
'packagingroot'])) {
293 $installedas_dest_dir = dirname($final_dest_file);
294 $installedas_dest_file = $dest_dir . DIRECTORY_SEPARATOR .
'.tmp' . basename($final_dest_file);
295 $final_dest_file = $this->
_prependPath($final_dest_file, $this->_options[
'packagingroot']);
297 $installedas_dest_dir = dirname($final_dest_file);
298 $installedas_dest_file = $installedas_dest_dir . DIRECTORY_SEPARATOR .
'.tmp' . basename($final_dest_file);
301 $dest_dir = dirname($final_dest_file);
302 $dest_file = $dest_dir . DIRECTORY_SEPARATOR .
'.tmp' . basename($final_dest_file);
303 if (preg_match(
'~/\.\.(/|\\z)|^\.\./~', str_replace(
'\\',
'/', $dest_file))) {
304 return $this->raiseError(
"SECURITY ERROR: file $file (installed to $dest_file) contains parent directory reference ..",
PEAR_INSTALLER_FAILED);
308 if (empty($this->_options[
'register-only']) &&
309 (!file_exists($dest_dir) || !is_dir($dest_dir))) {
311 return $this->raiseError(
"failed to mkdir $dest_dir",
314 $this->
log(3,
"+ mkdir $dest_dir");
318 if (empty($this->_options[
'register-only'])) {
319 if (empty($atts[
'replacements'])) {
320 if (!file_exists($orig_file)) {
321 return $this->raiseError(
"file $orig_file does not exist",
325 if (!@copy($orig_file, $dest_file)) {
326 return $this->raiseError(
327 "failed to write $dest_file: " . error_get_last()[
"message"],
331 $this->
log(3,
"+ cp $orig_file $dest_file");
332 if (isset($atts[
'md5sum'])) {
333 $md5sum = md5_file($dest_file);
337 if (!file_exists($orig_file)) {
338 return $this->raiseError(
"file does not exist",
342 $contents = file_get_contents($orig_file);
343 if ($contents ===
false) {
347 if (isset($atts[
'md5sum'])) {
348 $md5sum = md5($contents);
351 $subst_from = $subst_to = array();
352 foreach ($atts[
'replacements'] as $a) {
354 if ($a[
'type'] ==
'php-const') {
355 if (preg_match(
'/^[a-z0-9_]+\\z/i', $a[
'to'])) {
356 eval(
"\$to = $a[to];");
359 $this->
log(0,
"invalid php-const replacement: $a[to]");
363 } elseif ($a[
'type'] ==
'pear-config') {
364 if ($a[
'to'] ==
'master_server') {
365 $chan = $this->_registry->getChannel($channel);
367 $to = $chan->getServer();
369 $to = $this->config->get($a[
'to'],
null, $channel);
372 $to = $this->config->get($a[
'to'],
null, $channel);
376 $this->
log(0,
"invalid pear-config replacement: $a[to]");
380 } elseif ($a[
'type'] ==
'package-info') {
381 if ($t = $this->pkginfo->packageInfo($a[
'to'])) {
385 $this->
log(0,
"invalid package-info replacement: $a[to]");
391 $subst_from[] = $a[
'from'];
396 $this->
log(3,
"doing ".
sizeof($subst_from).
" substitution(s) for $final_dest_file");
397 if (
sizeof($subst_from)) {
398 $contents = str_replace($subst_from, $subst_to, $contents);
401 $wp = @fopen($dest_file,
"wb");
402 if (!is_resource($wp)) {
403 return $this->raiseError(
404 "failed to create $dest_file: " . error_get_last()[
"message"],
408 if (@fwrite($wp, $contents) ===
false) {
409 return $this->raiseError(
410 "failed writing to $dest_file: " . error_get_last()[
"message"],
419 if (isset($md5sum)) {
420 if (strtolower($md5sum) === strtolower($atts[
'md5sum'])) {
421 $this->
log(2,
"md5sum ok: $final_dest_file");
425 if (file_exists($dest_file)) {
429 if (!isset(
$options[
'ignore-errors'])) {
430 return $this->raiseError(
"bad md5sum for file $final_dest_file",
435 $this->
log(0,
"warning : bad md5sum for file $final_dest_file");
439 $this->
log(0,
"warning : bad md5sum for file $final_dest_file");
447 if ($atts[
'role'] ==
'script') {
448 $mode = 0777 & ~(int)octdec($this->config->get(
'umask'));
449 $this->
log(3,
"+ chmod +x $dest_file");
451 $mode = 0666 & ~(int)octdec($this->config->get(
'umask'));
454 if ($atts[
'role'] !=
'src') {
456 if (!@chmod($dest_file, $mode)) {
458 $this->
log(0,
"failed to change mode of $dest_file: " .
459 error_get_last()[
"message"]);
466 if ($atts[
'role'] ==
'src') {
467 rename($dest_file, $final_dest_file);
468 $this->
log(2,
"renamed source file $dest_file to $final_dest_file");
471 $atts[
'role'] ==
'ext'));
476 if ($atts[
'role'] !=
'script') {
477 $loc = $this->config->get($atts[
'role'] .
'_dir');
479 $loc = $this->config->get(
'bin_dir');
482 if ($atts[
'role'] !=
'src') {
485 dirname(substr($installedas_dest_file, strlen($loc)))));
506 if (!isset($this->_registry)) {
507 $this->_registry = &$this->config->getRegistry();
510 $channel = $pkg->getChannel();
512 if (!in_array($atts[
'attribs'][
'role'],
514 return $this->raiseError(
'Invalid role `' . $atts[
'attribs'][
'role'] .
519 $err = $role->setup($this, $pkg, $atts[
'attribs'], $file);
524 if (!$role->isInstallable()) {
528 $info = $role->processInstallation($pkg, $atts[
'attribs'], $file, $tmp_path);
533 list($save_destdir, $dest_dir, $dest_file, $orig_file) = $info;
534 if (preg_match(
'~/\.\.(/|\\z)|^\.\./~', str_replace(
'\\',
'/', $dest_file))) {
535 return $this->raiseError(
"SECURITY ERROR: file $file (installed to $dest_file) contains parent directory reference ..",
PEAR_INSTALLER_FAILED);
538 $final_dest_file = $installed_as = $dest_file;
539 if (isset($this->_options[
'packagingroot'])) {
540 $final_dest_file = $this->
_prependPath($final_dest_file,
541 $this->_options[
'packagingroot']);
544 $dest_dir = dirname($final_dest_file);
545 $dest_file = $dest_dir . DIRECTORY_SEPARATOR .
'.tmp' . basename($final_dest_file);
548 if (empty($this->_options[
'register-only'])) {
549 if (!file_exists($dest_dir) || !is_dir($dest_dir)) {
551 return $this->raiseError(
"failed to mkdir $dest_dir",
554 $this->
log(3,
"+ mkdir $dest_dir");
558 $attribs = $atts[
'attribs'];
559 unset($atts[
'attribs']);
561 if (empty($this->_options[
'register-only'])) {
563 if (!file_exists($orig_file)) {
564 return $this->raiseError(
"file $orig_file does not exist",
568 if (!@copy($orig_file, $dest_file)) {
569 return $this->raiseError(
570 "failed to write $dest_file: " . error_get_last()[
"message"],
574 $this->
log(3,
"+ cp $orig_file $dest_file");
575 if (isset($attribs[
'md5sum'])) {
576 $md5sum = md5_file($dest_file);
579 if (!file_exists($orig_file)) {
580 return $this->raiseError(
"file $orig_file does not exist",
584 $contents = file_get_contents($orig_file);
585 if ($contents ===
false) {
589 if (isset($attribs[
'md5sum'])) {
590 $md5sum = md5($contents);
593 foreach ($atts as $tag =>
$raw) {
594 $tag = str_replace(array($pkg->getTasksNs() .
':',
'-'), array(
'',
'_'), $tag);
595 $task =
"PEAR_Task_$tag";
597 if (!$task->isScript()) {
598 $task->init(
$raw, $attribs, $pkg->getLastInstalledVersion());
599 $res = $task->startSession($pkg, $contents, $final_dest_file);
600 if ($res ===
false) {
611 $wp = @fopen($dest_file,
"wb");
612 if (!is_resource($wp)) {
613 return $this->raiseError(
614 "failed to create $dest_file: " . error_get_last()[
"message"],
618 if (fwrite($wp, $contents) ===
false) {
619 return $this->raiseError(
620 "failed writing to $dest_file: " . error_get_last()[
"message"],
629 if (isset($md5sum)) {
631 if (strtolower($md5sum) === strtolower($attribs[
'md5sum'])) {
632 $this->
log(2,
"md5sum ok: $final_dest_file");
634 if (isset($contents)) {
636 $real_atts[
'attribs'][
'md5sum'] = md5($contents);
641 if (file_exists($dest_file)) {
645 if (!isset(
$options[
'ignore-errors'])) {
646 return $this->raiseError(
"bad md5sum for file $final_dest_file",
651 $this->
log(0,
"warning : bad md5sum for file $final_dest_file");
655 $this->
log(0,
"warning : bad md5sum for file $final_dest_file");
660 $real_atts[
'attribs'][
'md5sum'] = md5_file($dest_file);
666 if ($role->isExecutable()) {
667 $mode = 0777 & ~(int)octdec($this->config->get(
'umask'));
668 $this->
log(3,
"+ chmod +x $dest_file");
670 $mode = 0666 & ~(int)octdec($this->config->get(
'umask'));
673 if ($attribs[
'role'] !=
'src') {
675 if (!@chmod($dest_file, $mode)) {
677 $this->
log(0,
"failed to change mode of $dest_file: " .
678 error_get_last()[
"message"]);
685 if ($attribs[
'role'] ==
'src') {
686 rename($dest_file, $final_dest_file);
687 $this->
log(2,
"renamed source file $dest_file to $final_dest_file");
689 $this->
addFileOperation(
"rename", array($dest_file, $final_dest_file, $role->isExtension()));
694 if ($attribs[
'role'] !=
'src') {
695 $loc = $this->config->get($role->getLocationConfig(),
null, $channel);
698 dirname(substr($installed_as, strlen($loc)))));
766 foreach ($this->file_operations as $key => $tr) {
767 list($type, $data) = $tr;
770 if (!file_exists($data[0])) {
771 $errors[] =
"cannot rename file $data[0], doesn't exist";
775 if (!is_writable(dirname($data[1]))) {
776 $errors[] =
"permission denied ($type): $data[1]";
781 if (!is_writable($data[1])) {
782 $errors[] =
"permission denied ($type): $data[1] " . decoct($data[0]);
786 if (!file_exists($data[0])) {
787 $this->
log(2,
"warning: file $data[0] doesn't exist, can't be deleted");
790 if (file_exists($data[0])) {
791 if (!is_writable(dirname($data[0]))) {
792 $errors[] =
"permission denied ($type): $data[0]";
796 if (!is_dir($data[0]) &&
797 (!is_writable($data[0]) || !($fp = @fopen($data[0],
'a')))) {
798 $errors[] =
"permission denied ($type): $data[0]";
809 'package' => strtolower($this->pkginfo->getName()),
810 'channel' => strtolower($this->pkginfo->getChannel()),
812 $result = $this->_registry->checkFileMap($data[0], $info,
'1.1');
814 $res = array_diff(
$result, $info);
817 $this->file_operations[$key] =
false;
818 $pkginfoName = $this->pkginfo->getName();
819 $newChannel = $new->getChannel();
820 $newPackage = $new->getName();
821 $this->
log(3,
"file $data[0] was scheduled for removal from $pkginfoName but is owned by $newChannel/$newPackage, removal has been cancelled.");
831 $n = count($this->file_operations);
832 $this->
log(2,
"about to commit $n file operations for " . $this->pkginfo->getName());
836 foreach ($errors as $error) {
837 if (!isset($this->_options[
'soft'])) {
838 $this->
log(1, $error);
842 if (!isset($this->_options[
'ignore-errors'])) {
847 $this->_dirtree = array();
849 foreach ($this->file_operations as $i => $tr) {
855 list($type, $data) = $tr;
858 if (!file_exists($data[0])) {
859 $this->file_operations[$i] =
false;
863 if (!@copy($data[0], $data[0] .
'.bak')) {
864 $this->
log(1,
'Could not copy ' . $data[0] .
' to ' . $data[0] .
865 '.bak ' . error_get_last()[
"message"]);
868 $this->
log(3,
"+ backup $data[0] to $data[0].bak");
871 if (file_exists($data[0] .
'.bak') && is_writable($data[0] .
'.bak')) {
872 unlink($data[0] .
'.bak');
873 $this->
log(3,
"+ rm backup of $data[0] ($data[0].bak)");
877 $test = file_exists($data[1]) ? @unlink($data[1]) :
null;
878 if (!$test && file_exists($data[1])) {
880 $extra =
', this extension must be installed manually. Rename to "' .
881 basename($data[1]) .
'"';
886 if (!isset($this->_options[
'soft'])) {
887 $this->
log(1,
'Could not delete ' . $data[1] .
', cannot rename ' .
891 if (!isset($this->_options[
'ignore-errors'])) {
897 $perms = @fileperms($data[0]);
898 if (!@copy($data[0], $data[1])) {
899 $this->
log(1,
'Could not rename ' . $data[0] .
' to ' . $data[1] .
900 ' ' . error_get_last()[
"message"]);
905 @chmod($data[1], $perms);
907 $this->
log(3,
"+ mv $data[0] $data[1]");
910 if (!@chmod($data[1], $data[0])) {
911 $this->
log(1,
'Could not chmod ' . $data[1] .
' to ' .
912 decoct($data[0]) .
' ' . error_get_last()[
"message"]);
916 $octmode = decoct($data[0]);
917 $this->
log(3,
"+ chmod $octmode $data[1]");
920 if (file_exists($data[0])) {
921 if (!@unlink($data[0])) {
922 $this->
log(1,
'Could not delete ' . $data[0] .
' ' .
923 error_get_last()[
"message"]);
926 $this->
log(3,
"+ rm $data[0]");
930 if (file_exists($data[0])) {
932 $testme = opendir($data[0]);
933 while (
false !== ($entry = readdir($testme))) {
934 if ($entry ==
'.' || $entry ==
'..') {
943 if (!@rmdir($data[0])) {
944 $this->
log(1,
'Could not rmdir ' . $data[0] .
' ' .
945 error_get_last()[
"message"]);
948 $this->
log(3,
"+ rmdir $data[0]");
953 $this->pkginfo->setInstalledAs($data[0], $data[1]);
954 if (!isset($this->_dirtree[dirname($data[1])])) {
955 $this->_dirtree[dirname($data[1])] =
true;
956 $this->pkginfo->setDirtree(dirname($data[1]));
958 while(!empty($data[3]) && dirname($data[3]) != $data[3] &&
959 $data[3] !=
'/' && $data[3] !=
'\\') {
960 $this->pkginfo->setDirtree($pp =
962 $this->_dirtree[$pp] =
true;
963 $data[3] = dirname($data[3]);
970 $this->
log(2,
"successfully committed $n file operations");
971 $this->file_operations = array();
1111 $this->_registry = &$this->config->getRegistry();
1112 if (is_object($pkgfile)) {
1114 $pkg = $pkgfile->getPackageFile();
1115 $pkgfile = $pkg->getArchiveFile();
1116 $descfile = $pkg->getPackageFile();
1118 $descfile = $pkgfile;
1126 if (realpath($descfile) != realpath($pkgfile)) {
1128 $tmpdir = $this->config->get(
'temp_dir',
null,
'pear.php.net');
1132 if (!$tar->extract(
$tmpdir)) {
1133 return $this->raiseError(
"unable to unpack $pkgfile");
1137 $pkgname = $pkg->getName();
1138 $channel = $pkg->getChannel();
1140 if (isset(
$options[
'installroot'])) {
1141 $this->config->setInstallRoot(
$options[
'installroot']);
1142 $this->_registry = &$this->config->getRegistry();
1144 $this->installroot =
'';
1145 $php_dir = $this->config->get(
'php_dir',
null, $channel);
1147 $this->config->setInstallRoot(
false);
1148 $this->_registry = &$this->config->getRegistry();
1149 if (isset($this->_options[
'packagingroot'])) {
1151 $this->config->get(
'php_dir',
null,
'pear.php.net'),
1152 $this->_options[
'packagingroot']);
1154 $metadata_dir = $this->config->get(
'metadata_dir',
null,
'pear.php.net');
1155 if ($metadata_dir) {
1158 $this->_options[
'packagingroot']);
1161 $this->config->get(
'php_dir',
null, $channel),
1162 $this->_options[
'packagingroot']);
1164 $installregistry =
new PEAR_Registry($regdir,
false,
false, $metadata_dir);
1165 if (!$installregistry->channelExists($channel,
true)) {
1167 $chanobj = $this->_registry->getChannel($channel,
true);
1168 $installregistry->addChannel($chanobj);
1170 $php_dir = $packrootphp_dir;
1173 $php_dir = $this->config->get(
'php_dir',
null, $channel);
1175 $this->installroot =
'';
1180 (file_exists($this->config->get(
'php_dir')) &&
1181 is_dir($this->config->get(
'php_dir')))) {
1182 $testp = $channel ==
'pear.php.net' ? $pkgname : array($channel, $pkgname);
1183 $instfilelist = $pkg->getInstallationFileList(
true);
1185 return $instfilelist;
1189 $installregistry->flushFileMap();
1190 $test = $installregistry->checkFileMap($instfilelist, $testp,
'1.1');
1195 if (
sizeof($test)) {
1198 foreach ($pkgs as $param) {
1199 if ($pkg->isSubpackageOf($param)) {
1207 $parentreg = $installregistry->packageInfo($param->getPackage(),
null, $param->getChannel());
1209 foreach ($tmp as $file => $info) {
1210 if (is_array($info)) {
1211 if (strtolower($info[1]) == strtolower($param->getPackage()) &&
1212 strtolower($info[0]) == strtolower($param->getChannel())
1214 if (isset($parentreg[
'filelist'][$file])) {
1215 unset($parentreg[
'filelist'][$file]);
1217 $pos = strpos($file,
'/');
1218 $basedir = substr($file, 0, $pos);
1219 $file2 = substr($file, $pos + 1);
1220 if (isset($parentreg[
'filelist'][$file2][
'baseinstalldir'])
1221 && $parentreg[
'filelist'][$file2][
'baseinstalldir'] === $basedir
1223 unset($parentreg[
'filelist'][$file2]);
1227 unset($test[$file]);
1230 if (strtolower($param->getChannel()) !=
'pear.php.net') {
1234 if (strtolower($info) == strtolower($param->getPackage())) {
1235 if (isset($parentreg[
'filelist'][$file])) {
1236 unset($parentreg[
'filelist'][$file]);
1238 $pos = strpos($file,
'/');
1239 $basedir = substr($file, 0, $pos);
1240 $file2 = substr($file, $pos + 1);
1241 if (isset($parentreg[
'filelist'][$file2][
'baseinstalldir'])
1242 && $parentreg[
'filelist'][$file2][
'baseinstalldir'] === $basedir
1244 unset($parentreg[
'filelist'][$file2]);
1248 unset($test[$file]);
1254 $parentpkg = &$pfk->fromArray($parentreg);
1255 $installregistry->updatePackage2($parentpkg);
1258 if ($param->getChannel() ==
'pecl.php.net' && isset(
$options[
'upgrade'])) {
1260 foreach ($tmp as $file => $info) {
1261 if (is_string($info)) {
1263 if (strtolower($info) == strtolower($param->getPackage())) {
1265 unset($test[$file]);
1272 $msg =
"$channel/$pkgname: conflicting files found:\n";
1273 $longest = max(array_map(
"strlen", array_keys($test)));
1274 $fmt =
"%{$longest}s (%s)\n";
1275 foreach ($test as $file => $info) {
1276 if (!is_array($info)) {
1277 $info = array(
'pear.php.net', $info);
1279 $info = $info[0] .
'/' . $info[1];
1280 $msg .= sprintf($fmt, $file, $info);
1283 if (!isset(
$options[
'ignore-errors'])) {
1284 return $this->raiseError($msg);
1288 $this->
log(0,
"WARNING: $msg");
1297 $usechannel = $channel;
1298 if ($channel ==
'pecl.php.net') {
1299 $test = $installregistry->packageExists($pkgname, $channel);
1301 $test = $installregistry->packageExists($pkgname,
'pear.php.net');
1302 $usechannel =
'pear.php.net';
1305 $test = $installregistry->packageExists($pkgname, $channel);
1310 if (empty(
$options[
'force']) && $test) {
1311 return $this->raiseError(
"$channel/$pkgname is already installed");
1316 $v1 = $installregistry->packageInfo($pkgname,
'version', $usechannel);
1317 $v2 = $pkg->getVersion();
1318 $cmp = version_compare(
"$v1",
"$v2",
'gt');
1319 if (empty(
$options[
'force']) && !version_compare(
"$v2",
"$v1",
'gt')) {
1320 return $this->raiseError(
"upgrade to a newer version ($v2 is not newer than $v1)");
1326 if ($test && empty(
$options[
'register-only'])) {
1330 if (!isset(
$options[
'ignore-errors'])) {
1331 return $this->raiseError($err);
1335 $this->
log(0,
'WARNING: ' . $err->getMessage());
1345 $this->pkginfo = &$pkg;
1347 $this->source_files = 0;
1349 $savechannel = $this->config->get(
'default_channel');
1350 if (empty(
$options[
'register-only']) && !is_dir($php_dir)) {
1352 return $this->raiseError(
"no installation destination directory '$php_dir'\n");
1356 if (substr($pkgfile, -4) !=
'.xml') {
1357 $tmpdir .= DIRECTORY_SEPARATOR . $pkgname .
'-' . $pkg->getVersion();
1360 $this->
configSet(
'default_channel', $channel);
1363 $ver = $pkg->getPackagexmlVersion();
1364 if (version_compare($ver,
'2.0',
'>=')) {
1365 $filelist = $pkg->getInstallationFilelist();
1367 $filelist = $pkg->getFileList();
1374 $p = &$installregistry->getPackage($pkgname, $channel);
1375 $dirtree = (empty(
$options[
'register-only']) && $p) ? $p->getDirTree() :
false;
1377 $pkg->resetFilelist();
1378 $pkg->setLastInstalledVersion($installregistry->packageInfo($pkg->getPackage(),
1379 'version', $pkg->getChannel()));
1380 foreach ($filelist as $file => $atts) {
1382 if ($pkg->getPackagexmlVersion() ==
'1.0') {
1390 if (empty(
$options[
'ignore-errors'])) {
1392 if ($res->getMessage() ==
"file does not exist") {
1393 $this->raiseError(
"file $file in package.xml does not exist");
1396 return $this->raiseError($res);
1400 $this->
log(0,
"Warning: " . $res->getMessage());
1404 $real = isset($atts[
'attribs']) ? $atts[
'attribs'] : $atts;
1407 $pkg->installedFile($file, $atts);
1413 if ($this->source_files > 0 && empty(
$options[
'nobuild'])) {
1414 $configureoptions = empty(
$options[
'configureoptions']) ?
'' :
$options[
'configureoptions'];
1422 if (isset($backedup)) {
1428 $this->
configSet(
'default_channel', $savechannel);
1434 $installphase =
'install';
1435 $oldversion =
false;
1439 $usechannel = $channel;
1440 if ($channel ==
'pecl.php.net') {
1441 $test = $installregistry->packageExists($pkgname, $channel);
1443 $test = $installregistry->packageExists($pkgname,
'pear.php.net');
1444 $usechannel =
'pear.php.net';
1447 $test = $installregistry->packageExists($pkgname, $channel);
1450 if (!empty(
$options[
'force']) && $test) {
1451 $oldversion = $installregistry->packageInfo($pkgname,
'version', $usechannel);
1452 $installregistry->deletePackage($pkgname, $usechannel);
1454 $ret = $installregistry->addPackage2($pkg);
1459 uksort($dirtree, array($this,
'_sortDirs'));
1460 foreach($dirtree as $dir => $notused) {
1466 $usechannel = $channel;
1467 if ($channel ==
'pecl.php.net') {
1468 $test = $installregistry->packageExists($pkgname, $channel);
1470 $test = $installregistry->packageExists($pkgname,
'pear.php.net');
1471 $usechannel =
'pear.php.net';
1474 $test = $installregistry->packageExists($pkgname, $channel);
1479 $ret = $installregistry->addPackage2($pkg);
1481 if ($usechannel != $channel) {
1482 $installregistry->deletePackage($pkgname, $usechannel);
1483 $ret = $installregistry->addPackage2($pkg);
1485 $ret = $installregistry->updatePackage2($pkg);
1487 $installphase =
'upgrade';
1492 $this->
configSet(
'default_channel', $savechannel);
1493 return $this->raiseError(
"Adding package $channel/$pkgname to registry failed");
1497 $this->
configSet(
'default_channel', $savechannel);
1498 if (class_exists(
'PEAR_Task_Common')) {
1504 return $pkg->toArray(
true);
1517 require_once
'PEAR/Builder.php';
1518 $this->
log(1,
"$this->source_files source files, building");
1521 $built = $bob->build($filelist, array(&$this,
'_buildCallback'));
1524 $this->
configSet(
'default_channel', $savechannel);
1528 $this->
log(1,
"\nBuild process completed successfully");
1529 foreach ($built as $ext) {
1530 $bn = basename($ext[
'file']);
1531 list($_ext_name, $_ext_suff) = explode(
'.', $bn);
1532 if ($_ext_suff ==
'so' || $_ext_suff ==
'dll') {
1533 if (extension_loaded($_ext_name)) {
1534 return $this->raiseError(
"Extension '$_ext_name' already loaded. " .
1535 'Please unload it in your php.ini file ' .
1536 'prior to install or upgrade');
1543 $dest = $ext[
'dest'];
1544 $packagingroot =
'';
1545 if (isset($this->_options[
'packagingroot'])) {
1546 $packagingroot = $this->_options[
'packagingroot'];
1550 $extra = $copyto != $dest ?
" as '$copyto'" :
'';
1551 $this->
log(1,
"Installing '$dest'$extra");
1553 $copydir = dirname($copyto);
1555 if (empty($this->_options[
'register-only'])) {
1556 if (!file_exists($copydir) || !is_dir($copydir)) {
1558 return $this->raiseError(
"failed to mkdir $copydir",
1562 $this->
log(3,
"+ mkdir $copydir");
1565 if (!@copy($ext[
'file'], $copyto)) {
1566 return $this->raiseError(
1567 "failed to write $copyto (" . error_get_last()[
"message"] .
")",
1571 $this->
log(3,
"+ cp $ext[file] $copyto");
1574 $mode = 0666 & ~(int)octdec($this->config->get(
'umask'));
1576 if (!@chmod($copyto, $mode)) {
1577 $this->
log(0,
"failed to change mode of $copyto (" .
1578 error_get_last()[
"message"] .
")");
1587 'installed_as' => $dest,
1588 'php_api' => $ext[
'php_api'],
1589 'zend_mod_api' => $ext[
'zend_mod_api'],
1590 'zend_ext_api' => $ext[
'zend_ext_api'],
1593 if ($filelist->getPackageXmlVersion() ==
'1.0') {
1594 $filelist->installedFile($bn, $data);
1596 $filelist->installedFile($bn, array(
'attribs' => $data));
1623 $installRoot = isset(
$options[
'installroot']) ?
$options[
'installroot'] :
'';
1624 $this->config->setInstallRoot($installRoot);
1626 $this->installroot =
'';
1627 $this->_registry = &$this->config->getRegistry();
1628 if (is_object($package)) {
1629 $channel = $package->getChannel();
1631 $package = $pkg->getPackage();
1634 $info = $this->_registry->parsePackageName($package,
1635 $this->config->get(
'default_channel'));
1636 $channel = $info[
'channel'];
1637 $package = $info[
'package'];
1640 $savechannel = $this->config->get(
'default_channel');
1641 $this->
configSet(
'default_channel', $channel);
1642 if (!is_object($pkg)) {
1643 $pkg = $this->_registry->getPackage($package, $channel);
1647 $this->
configSet(
'default_channel', $savechannel);
1648 return $this->raiseError($this->_registry->parsedPackageNameToString(
1650 'channel' => $channel,
1651 'package' => $package
1652 ),
true) .
' not installed');
1655 if ($pkg->getInstalledBinary()) {
1657 return $this->_registry->deletePackage($package, $channel);
1660 $filelist = $pkg->getFilelist();
1662 if (!class_exists(
'PEAR_Dependency2')) {
1663 require_once
'PEAR/Dependency2.php';
1667 array(
'channel' => $channel,
'package' => $package),
1669 $e = $depchecker->validatePackageUninstall($this);
1672 if (!isset(
$options[
'ignore-errors'])) {
1673 return $this->raiseError($e);
1677 $this->
log(0,
'WARNING: ' . $e->getMessage());
1679 } elseif (is_array($e)) {
1681 $this->
log(0, $e[0]);
1685 $this->pkginfo = &$pkg;
1687 if (empty(
$options[
'register-only'])) {
1692 PEAR::popErrorHandling();
1694 $this->
configSet(
'default_channel', $savechannel);
1695 if (!isset(
$options[
'ignore-errors'])) {
1696 return $this->raiseError($err);
1700 $this->
log(0,
'WARNING: ' . $err->getMessage());
1703 PEAR::popErrorHandling();
1708 if (!isset(
$options[
'ignore-errors'])) {
1709 return $this->raiseError(
"uninstall failed");
1713 $this->
log(0,
'WARNING: uninstall failed');
1717 $dirtree = $pkg->getDirTree();
1718 if ($dirtree ===
false) {
1719 $this->
configSet(
'default_channel', $savechannel);
1720 return $this->_registry->deletePackage($package, $channel);
1724 uksort($dirtree, array($this,
'_sortDirs'));
1725 foreach($dirtree as $dir => $notused) {
1731 if (!isset(
$options[
'ignore-errors'])) {
1732 return $this->raiseError(
"uninstall failed");
1736 $this->
log(0,
'WARNING: uninstall failed');
1743 $this->
configSet(
'default_channel', $savechannel);
1745 return $this->_registry->deletePackage($package, $channel);