cvs: pear-core /PEAR Installer.php
| From: | Helgi �ormar �orbj�rnsson | Date: | Thu, 10 Jul 2008 19:48:38 +0000 |
| Subject: | cvs: pear-core /PEAR Installer.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-7618@lists.php.net to get a copy of this message | ||
dufuz Thu Jul 10 19:48:38 2008 UTC
Modified files:
/pear-core/PEAR Installer.php
Log:
Couple of more cosmetics
http://cvs.php.net/viewvc.cgi/pear-core/PEAR/Installer.php?r1=1.255&r2=1.256&diff_format=u Index: pear-core/PEAR/Installer.php diff -u pear-core/PEAR/Installer.php:1.255 pear-core/PEAR/Installer.php:1.256 --- pear-core/PEAR/Installer.php:1.255 Tue Jul 8 21:08:44 2008 +++ pear-core/PEAR/Installer.php Thu Jul 10 19:48:38 2008 @@ -18,7 +18,7 @@ * @author Greg Beaver <cellog@php.net> * @copyright 1997-2008 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Installer.php,v 1.255 2008/07/08 21:08:44 dufuz Exp $ + * @version CVS: $Id: Installer.php,v 1.256 2008/07/10 19:48:38 dufuz Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 0.1 */ @@ -165,9 +165,11 @@ if (!$channel) { $channel = 'pear.php.net'; } + if (!strlen($package)) { return $this->raiseError("No package to uninstall given"); } + if (strtolower($package) == 'pear' && $channel == 'pear.php.net') { // to avoid race conditions, include all possible needed files require_once 'PEAR/Task/Common.php'; @@ -179,25 +181,31 @@ require_once 'PEAR/PackageFile/Generator/v1.php'; require_once 'PEAR/PackageFile/Generator/v2.php'; } + $filelist = $this->_registry->packageInfo($package, 'filelist', $channel); if ($filelist == null) { return $this->raiseError("$channel/$package not installed"); } + $ret = array(); foreach ($filelist as $file => $props) { if (empty($props['installed_as'])) { continue; } + $path = $props['installed_as']; if ($backup) { $this->addFileOperation('backup', array($path)); $ret[] = $path; } + $this->addFileOperation('delete', array($path)); } + if ($backup) { return $ret; } + return true; } @@ -218,17 +226,20 @@ if (!isset($this->_registry)) { $this->_registry = &$this->config->getRegistry(); } + if (isset($atts['platform'])) { if (empty($os)) { $os = new OS_Guess(); } + if (strlen($atts['platform']) && $atts['platform']{0} == '!') { - $negate = true; + $negate = true; $platform = substr($atts['platform'], 1); } else { - $negate = false; + $negate = false; $platform = $atts['platform']; } + if ((bool) $os->matchSignature($platform) === $negate) { $this->log(3, "skipped $file (meant for $atts[platform], we are ".$os->getSignature().")"); return PEAR_INSTALLER_SKIPPED; @@ -260,13 +271,16 @@ default: return $this->raiseError("Invalid role `$atts[role]' for file $file"); } + $save_destdir = $dest_dir; if (!empty($atts['baseinstalldir'])) { $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; } + if (dirname($file) != '.' && empty($atts['install-as'])) { $dest_dir .= DIRECTORY_SEPARATOR . dirname($file); } + if (empty($atts['install-as'])) { $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file); } else { @@ -283,15 +297,15 @@ array($dest_file, $orig_file)); $final_dest_file = $installed_as = $dest_file; if (isset($this->_options['packagingroot'])) { - $installedas_dest_dir = dirname($final_dest_file); + $installedas_dest_dir = dirname($final_dest_file); $installedas_dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file); - $final_dest_file = $this->_prependPath($final_dest_file, - $this->_options['packagingroot']); + $final_dest_file = $this->_prependPath($final_dest_file, $this->_options['packagingroot']); } else { - $installedas_dest_dir = dirname($final_dest_file); + $installedas_dest_dir = dirname($final_dest_file); $installedas_dest_file = $installedas_dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file); } - $dest_dir = dirname($final_dest_file); + + $dest_dir = dirname($final_dest_file); $dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file); if (preg_match('~/\.\.(/|\\z)|^\.\./~', str_replace('\\', '/', $dest_file))) { return $this->raiseError("SECURITY ERROR: file $file (installed to $dest_file) contains parent directory reference ..", PEAR_INSTALLER_FAILED); @@ -306,6 +320,7 @@ } $this->log(3, "+ mkdir $dest_dir"); } + // pretty much nothing happens if we are only registering the install if (empty($this->_options['register-only'])) { if (empty($atts['replacements'])) { @@ -313,10 +328,12 @@ return $this->raiseError("file $orig_file does not exist", PEAR_INSTALLER_FAILED); } + if (!@copy($orig_file, $dest_file)) { return $this->raiseError("failed to write $dest_file: $php_errormsg", PEAR_INSTALLER_FAILED); } + $this->log(3, "+ cp $orig_file $dest_file"); if (isset($atts['md5sum'])) { $md5sum = md5_file($dest_file); @@ -327,13 +344,16 @@ return $this->raiseError("file does not exist", PEAR_INSTALLER_FAILED); } + $contents = file_get_contents($orig_file); if ($contents === false) { $contents = ''; } + if (isset($atts['md5sum'])) { $md5sum = md5($contents); } + $subst_from = $subst_to = array(); foreach ($atts['replacements'] as $a) { $to = ''; @@ -378,22 +398,27 @@ $subst_to[] = $to; } } + $this->log(3, "doing ".sizeof($subst_from)." substitution(s) for $final_dest_file"); if (sizeof($subst_from)) { $contents = str_replace($subst_from, $subst_to, $contents); } + $wp = @fopen($dest_file, "wb"); if (!is_resource($wp)) { return $this->raiseError("failed to create $dest_file: $php_errormsg", PEAR_INSTALLER_FAILED); } + if (@fwrite($wp, $contents) === false) { return $this->raiseError("failed writing to $dest_file: $php_errormsg", PEAR_INSTALLER_FAILED); } + fclose($wp); // }}} } + // {{{ check the md5 if (isset($md5sum)) { if (strtolower($md5sum) === strtolower($atts['md5sum'])) { @@ -404,13 +429,14 @@ if (file_exists($dest_file)) { unlink($dest_file); } + if (!isset($options['ignore-errors'])) { return $this->raiseError("bad md5sum for file $final_dest_file", PEAR_INSTALLER_FAILED); - } else { - if (!isset($options['soft'])) { - $this->log(0, "warning : bad md5sum for file $final_dest_file"); - } + } + + if (!isset($options['soft'])) { + $this->log(0, "warning : bad md5sum for file $final_dest_file"); } } else { if (!isset($options['soft'])) { @@ -428,6 +454,7 @@ } else { $mode = 0666 & ~(int)octdec($this->config->get('umask')); } + if ($atts['role'] != 'src') { $this->addFileOperation("chmod", array($mode, $dest_file)); if (!@chmod($dest_file, $mode)) { @@ -438,6 +465,7 @@ } } // }}} + if ($atts['role'] == 'src') { rename($dest_file, $final_dest_file); $this->log(2, "renamed source file $dest_file to $final_dest_file"); @@ -446,12 +474,14 @@ $atts['role'] == 'ext')); } } + // Store the full path where the file was installed for easy unistall if ($atts['role'] != 'script') { $loc = $this->config->get($atts['role'] . '_dir'); } else { $loc = $this->config->get('bin_dir'); } + if ($atts['role'] != 'src') { $this->addFileOperation("installed_as", array($file, $installed_as, $loc, @@ -487,29 +517,34 @@ return $this->raiseError('Invalid role `' . $atts['attribs']['role'] . "' for file $file"); } + $role = &PEAR_Installer_Role::factory($pkg, $atts['attribs']['role'], $this->config); - $err = $role->setup($this, $pkg, $atts['attribs'], $file); + $err = $role->setup($this, $pkg, $atts['attribs'], $file); if (PEAR::isError($err)) { return $err; } + if (!$role->isInstallable()) { return; } + $info = $role->processInstallation($pkg, $atts['attribs'], $file, $tmp_path); if (PEAR::isError($info)) { return $info; - } else { - list($save_destdir, $dest_dir, $dest_file, $orig_file) = $info; } + + list($save_destdir, $dest_dir, $dest_file, $orig_file) = $info; if (preg_match('~/\.\.(/|\\z)|^\.\./~', str_replace('\\', '/', $dest_file))) { return $this->raiseError("SECURITY ERROR: file $file (installed to $dest_file) contains parent directory reference ..", PEAR_INSTALLER_FAILED); } + $final_dest_file = $installed_as = $dest_file; if (isset($this->_options['packagingroot'])) { $final_dest_file = $this->_prependPath($final_dest_file, $this->_options['packagingroot']); } - $dest_dir = dirname($final_dest_file); + + $dest_dir = dirname($final_dest_file); $dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file); // }}} @@ -522,6 +557,7 @@ $this->log(3, "+ mkdir $dest_dir"); } } + $attribs = $atts['attribs']; unset($atts['attribs']); // pretty much nothing happens if we are only registering the install @@ -531,10 +567,12 @@ return $this->raiseError("file $orig_file does not exist", PEAR_INSTALLER_FAILED); } + if (!@copy($orig_file, $dest_file)) { return $this->raiseError("failed to write $dest_file: $php_errormsg", PEAR_INSTALLER_FAILED); } + $this->log(3, "+ cp $orig_file $dest_file"); if (isset($attribs['md5sum'])) { $md5sum = md5_file($dest_file); @@ -544,13 +582,16 @@ return $this->raiseError("file $orig_file does not exist", PEAR_INSTALLER_FAILED); } + $contents = file_get_contents($orig_file); if ($contents === false) { $contents = ''; } + if (isset($attribs['md5sum'])) { $md5sum = md5($contents); } + foreach ($atts as $tag => $raw) { $tag = str_replace(array($pkg->getTasksNs() . ':', '-'), array('', '_'), $tag); @@ -562,6 +603,7 @@ if ($res === false) { continue; // skip this file } + if (PEAR::isError($res)) { return $res; } @@ -572,13 +614,16 @@ return $this->raiseError("failed to create $dest_file: $php_errormsg", PEAR_INSTALLER_FAILED); } + if (fwrite($wp, $contents) === false) { return $this->raiseError("failed writing to $dest_file: $php_errormsg", PEAR_INSTALLER_FAILED); } + fclose($wp); } } + // {{{ check the md5 if (isset($md5sum)) { if (strtolower($md5sum) === strtolower($attribs['md5sum'])) { @@ -589,13 +634,14 @@ if (file_exists($dest_file)) { unlink($dest_file); } + if (!isset($options['ignore-errors'])) { return $this->raiseError("bad md5sum for file $final_dest_file", PEAR_INSTALLER_FAILED); - } else { - if (!isset($options['soft'])) { - $this->log(0, "warning : bad md5sum for file $final_dest_file"); - } + } + + if (!isset($options['soft'])) { + $this->log(0, "warning : bad md5sum for file $final_dest_file"); } } else { if (!isset($options['soft'])) { @@ -606,6 +652,7 @@ } else { $real_atts['attribs']['md5sum'] = md5_file($dest_file); } + // }}} // {{{ set file permissions if (!OS_WINDOWS) { @@ -615,6 +662,7 @@ } else { $mode = 0666 & ~(int)octdec($this->config->get('umask')); } + if ($attribs['role'] != 'src') { $this->addFileOperation("chmod", array($mode, $dest_file)); if (!@chmod($dest_file, $mode)) { @@ -625,6 +673,7 @@ } } // }}} + if ($attribs['role'] == 'src') { rename($dest_file, $final_dest_file); $this->log(2, "renamed source file $dest_file to $final_dest_file"); @@ -632,10 +681,11 @@ $this->addFileOperation("rename", array($dest_file, $final_dest_file, $role->isExtension())); } } + // Store the full path where the file was installed for easy uninstall if ($attribs['role'] != 'src') { $loc = $this->config->get($role->getLocationConfig(), null, $channel); - $this->addFileOperation("installed_as", array($file, $installed_as, + $this->addFileOperation('installed_as', array($file, $installed_as, $loc, dirname(substr($installed_as, strlen($loc))))); } @@ -677,6 +727,7 @@ return $this->raiseError('Internal Error: $data in addFileOperation' . ' must be an array, was ' . gettype($data)); } + if ($type == 'chmod') { $octmode = decoct($data[0]); $this->log(3, "adding to transaction: $type $octmode $data[1]"); @@ -713,6 +764,7 @@ if (!file_exists($data[0])) { $errors[] = "cannot rename file $data[0], doesn't exist"; } + // check that dest dir. is writable if (!is_writable(dirname($data[1]))) { $errors[] = "permission denied ($type): $data[1]"; @@ -755,6 +807,7 @@ $this->log(1, $error); } } + if (!isset($this->_options['ignore-errors'])) { return false; } @@ -773,6 +826,7 @@ $this->file_operations[$i] = false; break; } + if (!@copy($data[0], $data[0] . '.bak')) { $this->log(1, 'Could not copy ' . $data[0] . ' to ' . $data[0] . '.bak ' . $php_errormsg); @@ -787,11 +841,7 @@ } break; case 'rename': - if (file_exists($data[1])) { - $test = @unlink($data[1]); - } else { - $test = null; - } + $test = file_exists($data[1]) ? @unlink($data[1]) : null; if (!$test && file_exists($data[1])) { if ($data[2]) { $extra = ', this extension must be installed manually. Rename to "' . @@ -799,14 +849,17 @@ } else { $extra = ''; } + if (!isset($this->_options['soft'])) { $this->log(1, 'Could not delete ' . $data[1] . ', cannot rename ' . $data[0] . $extra); } + if (!isset($this->_options['ignore-errors'])) { return false; } } + // permissions issues with rename - copy() is far superior $perms = @fileperms($data[0]); if (!@copy($data[0], $data[1])) { @@ -814,6 +867,7 @@ ' ' . $php_errormsg); return false; } + // copy over permissions, otherwise they are lost @chmod($data[1], $perms); @unlink($data[0]); @@ -825,6 +879,7 @@ decoct($data[0]) . ' ' . $php_errormsg); return false; } + $octmode = decoct($data[0]); $this->log(3, "+ chmod $octmode $data[1]"); break; @@ -850,6 +905,7 @@ break 2; // this directory is not empty and can't be // deleted } + closedir($testme); if (!@rmdir($data[0])) { $this->log(1, 'Could not rmdir ' . $data[0] . ' ' . @@ -966,8 +1022,8 @@ { // trickiness: initialize here parent::PEAR_Downloader($this->ui, $options, $config); - $ret = parent::download($packages); - $errors = $this->getErrorMsgs(); + $ret = parent::download($packages); + $errors = $this->getErrorMsgs(); $installpackages = $this->getDownloadedPackages(); trigger_error("PEAR Warning: PEAR_Installer::download() is deprecated " . "in favor of PEAR_Downloader class", E_USER_WARNING); @@ -993,6 +1049,7 @@ $this->log(3, '+ tmp dir created at ' . $tmpdir); // }}} } + // Parse xml file ----------------------------------------------- $pkg = new PEAR_PackageFile($this->config, $this->debug, $tmpdir); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); @@ -1008,9 +1065,9 @@ } } return $this->raiseError('Installation failed: invalid package file'); - } else { - $descfile = $p->getPackageFile(); } + + $descfile = $p->getPackageFile(); return $p; } @@ -1072,15 +1129,16 @@ $this->_options = $options; $this->_registry = &$this->config->getRegistry(); if (is_object($pkgfile)) { - $dlpkg = &$pkgfile; - $pkg = $pkgfile->getPackageFile(); - $pkgfile = $pkg->getArchiveFile(); + $dlpkg = &$pkgfile; + $pkg = $pkgfile->getPackageFile(); + $pkgfile = $pkg->getArchiveFile(); $descfile = $pkg->getPackageFile(); - $tmpdir = dirname($descfile); + $tmpdir = dirname($descfile); } else { $descfile = $pkgfile; - $tmpdir = ''; - if (PEAR::isError($pkg = &$this->_parsePackageXml($descfile, $tmpdir))) { + $tmpdir = ''; + $pkg = &$this->_parsePackageXml($descfile, $tmpdir); + if (PEAR::isError($pkg)) { return $pkg; } } @@ -1098,6 +1156,7 @@ $regdir = $this->_prependPath( $this->config->get('php_dir', null, 'pear.php.net'), $this->_options['packagingroot']); + $packrootphp_dir = $this->_prependPath( $this->config->get('php_dir', null, $channel), $this->_options['packagingroot']); @@ -1370,9 +1429,9 @@ } // }}} - $ret = false; + $ret = false; $installphase = 'install'; - $oldversion = false; + $oldversion = false; // {{{ Register that the package is installed ----------------------- if (empty($options['upgrade'])) { // if 'force' is used, replace the info in registry @@ -1565,16 +1624,15 @@ { if (isset($options['installroot'])) { $this->config->setInstallRoot($options['installroot']); - $this->installroot = ''; } else { $this->config->setInstallRoot(''); - $this->installroot = ''; } + $this->installroot = ''; $this->_registry = &$this->config->getRegistry(); if (is_object($package)) { $channel = $package->getChannel(); - $pkg = $package; + $pkg = $package; $package = $pkg->getPackage(); } else { $pkg = false;
http://cvs.php.net/viewvc.cgi/pear-core/PEAR/Installer.php?r1=1.255&r2=1.256&diff_format=u Index: pear-core/PEAR/Installer.php diff -u pear-core/PEAR/Installer.php:1.255 pear-core/PEAR/Installer.php:1.256 --- pear-core/PEAR/Installer.php:1.255 Tue Jul 8 21:08:44 2008 +++ pear-core/PEAR/Installer.php Thu Jul 10 19:48:38 2008 @@ -18,7 +18,7 @@ * @author Greg Beaver <cellog@php.net> * @copyright 1997-2008 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Installer.php,v 1.255 2008/07/08 21:08:44 dufuz Exp $ + * @version CVS: $Id: Installer.php,v 1.256 2008/07/10 19:48:38 dufuz Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 0.1 */ @@ -165,9 +165,11 @@ if (!$channel) { $channel = 'pear.php.net'; } + if (!strlen($package)) { return $this->raiseError("No package to uninstall given"); } + if (strtolower($package) == 'pear' && $channel == 'pear.php.net') { // to avoid race conditions, include all possible needed files require_once 'PEAR/Task/Common.php'; @@ -179,25 +181,31 @@ require_once 'PEAR/PackageFile/Generator/v1.php'; require_once 'PEAR/PackageFile/Generator/v2.php'; } + $filelist = $this->_registry->packageInfo($package, 'filelist', $channel); if ($filelist == null) { return $this->raiseError("$channel/$package not installed"); } + $ret = array(); foreach ($filelist as $file => $props) { if (empty($props['installed_as'])) { continue; } + $path = $props['installed_as']; if ($backup) { $this->addFileOperation('backup', array($path)); $ret[] = $path; } + $this->addFileOperation('delete', array($path)); } + if ($backup) { return $ret; } + return true; } @@ -218,17 +226,20 @@ if (!isset($this->_registry)) { $this->_registry = &$this->config->getRegistry(); } + if (isset($atts['platform'])) { if (empty($os)) { $os = new OS_Guess(); } + if (strlen($atts['platform']) && $atts['platform']{0} == '!') { - $negate = true; + $negate = true; $platform = substr($atts['platform'], 1); } else { - $negate = false; + $negate = false; $platform = $atts['platform']; } + if ((bool) $os->matchSignature($platform) === $negate) { $this->log(3, "skipped $file (meant for $atts[platform], we are ".$os->getSignature().")"); return PEAR_INSTALLER_SKIPPED; @@ -260,13 +271,16 @@ default: return $this->raiseError("Invalid role `$atts[role]' for file $file"); } + $save_destdir = $dest_dir; if (!empty($atts['baseinstalldir'])) { $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; } + if (dirname($file) != '.' && empty($atts['install-as'])) { $dest_dir .= DIRECTORY_SEPARATOR . dirname($file); } + if (empty($atts['install-as'])) { $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file); } else { @@ -283,15 +297,15 @@ array($dest_file, $orig_file)); $final_dest_file = $installed_as = $dest_file; if (isset($this->_options['packagingroot'])) { - $installedas_dest_dir = dirname($final_dest_file); + $installedas_dest_dir = dirname($final_dest_file); $installedas_dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file); - $final_dest_file = $this->_prependPath($final_dest_file, - $this->_options['packagingroot']); + $final_dest_file = $this->_prependPath($final_dest_file, $this->_options['packagingroot']); } else { - $installedas_dest_dir = dirname($final_dest_file); + $installedas_dest_dir = dirname($final_dest_file); $installedas_dest_file = $installedas_dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file); } - $dest_dir = dirname($final_dest_file); + + $dest_dir = dirname($final_dest_file); $dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file); if (preg_match('~/\.\.(/|\\z)|^\.\./~', str_replace('\\', '/', $dest_file))) { return $this->raiseError("SECURITY ERROR: file $file (installed to $dest_file) contains parent directory reference ..", PEAR_INSTALLER_FAILED); @@ -306,6 +320,7 @@ } $this->log(3, "+ mkdir $dest_dir"); } + // pretty much nothing happens if we are only registering the install if (empty($this->_options['register-only'])) { if (empty($atts['replacements'])) { @@ -313,10 +328,12 @@ return $this->raiseError("file $orig_file does not exist", PEAR_INSTALLER_FAILED); } + if (!@copy($orig_file, $dest_file)) { return $this->raiseError("failed to write $dest_file: $php_errormsg", PEAR_INSTALLER_FAILED); } + $this->log(3, "+ cp $orig_file $dest_file"); if (isset($atts['md5sum'])) { $md5sum = md5_file($dest_file); @@ -327,13 +344,16 @@ return $this->raiseError("file does not exist", PEAR_INSTALLER_FAILED); } + $contents = file_get_contents($orig_file); if ($contents === false) { $contents = ''; } + if (isset($atts['md5sum'])) { $md5sum = md5($contents); } + $subst_from = $subst_to = array(); foreach ($atts['replacements'] as $a) { $to = ''; @@ -378,22 +398,27 @@ $subst_to[] = $to; } } + $this->log(3, "doing ".sizeof($subst_from)." substitution(s) for $final_dest_file"); if (sizeof($subst_from)) { $contents = str_replace($subst_from, $subst_to, $contents); } + $wp = @fopen($dest_file, "wb"); if (!is_resource($wp)) { return $this->raiseError("failed to create $dest_file: $php_errormsg", PEAR_INSTALLER_FAILED); } + if (@fwrite($wp, $contents) === false) { return $this->raiseError("failed writing to $dest_file: $php_errormsg", PEAR_INSTALLER_FAILED); } + fclose($wp); // }}} } + // {{{ check the md5 if (isset($md5sum)) { if (strtolower($md5sum) === strtolower($atts['md5sum'])) { @@ -404,13 +429,14 @@ if (file_exists($dest_file)) { unlink($dest_file); } + if (!isset($options['ignore-errors'])) { return $this->raiseError("bad md5sum for file $final_dest_file", PEAR_INSTALLER_FAILED); - } else { - if (!isset($options['soft'])) { - $this->log(0, "warning : bad md5sum for file $final_dest_file"); - } + } + + if (!isset($options['soft'])) { + $this->log(0, "warning : bad md5sum for file $final_dest_file"); } } else { if (!isset($options['soft'])) { @@ -428,6 +454,7 @@ } else { $mode = 0666 & ~(int)octdec($this->config->get('umask')); } + if ($atts['role'] != 'src') { $this->addFileOperation("chmod", array($mode, $dest_file)); if (!@chmod($dest_file, $mode)) { @@ -438,6 +465,7 @@ } } // }}} + if ($atts['role'] == 'src') { rename($dest_file, $final_dest_file); $this->log(2, "renamed source file $dest_file to $final_dest_file"); @@ -446,12 +474,14 @@ $atts['role'] == 'ext')); } } + // Store the full path where the file was installed for easy unistall if ($atts['role'] != 'script') { $loc = $this->config->get($atts['role'] . '_dir'); } else { $loc = $this->config->get('bin_dir'); } + if ($atts['role'] != 'src') { $this->addFileOperation("installed_as", array($file, $installed_as, $loc, @@ -487,29 +517,34 @@ return $this->raiseError('Invalid role `' . $atts['attribs']['role'] . "' for file $file"); } + $role = &PEAR_Installer_Role::factory($pkg, $atts['attribs']['role'], $this->config); - $err = $role->setup($this, $pkg, $atts['attribs'], $file); + $err = $role->setup($this, $pkg, $atts['attribs'], $file); if (PEAR::isError($err)) { return $err; } + if (!$role->isInstallable()) { return; } + $info = $role->processInstallation($pkg, $atts['attribs'], $file, $tmp_path); if (PEAR::isError($info)) { return $info; - } else { - list($save_destdir, $dest_dir, $dest_file, $orig_file) = $info; } + + list($save_destdir, $dest_dir, $dest_file, $orig_file) = $info; if (preg_match('~/\.\.(/|\\z)|^\.\./~', str_replace('\\', '/', $dest_file))) { return $this->raiseError("SECURITY ERROR: file $file (installed to $dest_file) contains parent directory reference ..", PEAR_INSTALLER_FAILED); } + $final_dest_file = $installed_as = $dest_file; if (isset($this->_options['packagingroot'])) { $final_dest_file = $this->_prependPath($final_dest_file, $this->_options['packagingroot']); } - $dest_dir = dirname($final_dest_file); + + $dest_dir = dirname($final_dest_file); $dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file); // }}} @@ -522,6 +557,7 @@ $this->log(3, "+ mkdir $dest_dir"); } } + $attribs = $atts['attribs']; unset($atts['attribs']); // pretty much nothing happens if we are only registering the install @@ -531,10 +567,12 @@ return $this->raiseError("file $orig_file does not exist", PEAR_INSTALLER_FAILED); } + if (!@copy($orig_file, $dest_file)) { return $this->raiseError("failed to write $dest_file: $php_errormsg", PEAR_INSTALLER_FAILED); } + $this->log(3, "+ cp $orig_file $dest_file"); if (isset($attribs['md5sum'])) { $md5sum = md5_file($dest_file); @@ -544,13 +582,16 @@ return $this->raiseError("file $orig_file does not exist", PEAR_INSTALLER_FAILED); } + $contents = file_get_contents($orig_file); if ($contents === false) { $contents = ''; } + if (isset($attribs['md5sum'])) { $md5sum = md5($contents); } + foreach ($atts as $tag => $raw) { $tag = str_replace(array($pkg->getTasksNs() . ':', '-'), array('', '_'), $tag); @@ -562,6 +603,7 @@ if ($res === false) { continue; // skip this file } + if (PEAR::isError($res)) { return $res; } @@ -572,13 +614,16 @@ return $this->raiseError("failed to create $dest_file: $php_errormsg", PEAR_INSTALLER_FAILED); } + if (fwrite($wp, $contents) === false) { return $this->raiseError("failed writing to $dest_file: $php_errormsg", PEAR_INSTALLER_FAILED); } + fclose($wp); } } + // {{{ check the md5 if (isset($md5sum)) { if (strtolower($md5sum) === strtolower($attribs['md5sum'])) { @@ -589,13 +634,14 @@ if (file_exists($dest_file)) { unlink($dest_file); } + if (!isset($options['ignore-errors'])) { return $this->raiseError("bad md5sum for file $final_dest_file", PEAR_INSTALLER_FAILED); - } else { - if (!isset($options['soft'])) { - $this->log(0, "warning : bad md5sum for file $final_dest_file"); - } + } + + if (!isset($options['soft'])) { + $this->log(0, "warning : bad md5sum for file $final_dest_file"); } } else { if (!isset($options['soft'])) { @@ -606,6 +652,7 @@ } else { $real_atts['attribs']['md5sum'] = md5_file($dest_file); } + // }}} // {{{ set file permissions if (!OS_WINDOWS) { @@ -615,6 +662,7 @@ } else { $mode = 0666 & ~(int)octdec($this->config->get('umask')); } + if ($attribs['role'] != 'src') { $this->addFileOperation("chmod", array($mode, $dest_file)); if (!@chmod($dest_file, $mode)) { @@ -625,6 +673,7 @@ } } // }}} + if ($attribs['role'] == 'src') { rename($dest_file, $final_dest_file); $this->log(2, "renamed source file $dest_file to $final_dest_file"); @@ -632,10 +681,11 @@ $this->addFileOperation("rename", array($dest_file, $final_dest_file, $role->isExtension())); } } + // Store the full path where the file was installed for easy uninstall if ($attribs['role'] != 'src') { $loc = $this->config->get($role->getLocationConfig(), null, $channel); - $this->addFileOperation("installed_as", array($file, $installed_as, + $this->addFileOperation('installed_as', array($file, $installed_as, $loc, dirname(substr($installed_as, strlen($loc))))); } @@ -677,6 +727,7 @@ return $this->raiseError('Internal Error: $data in addFileOperation' . ' must be an array, was ' . gettype($data)); } + if ($type == 'chmod') { $octmode = decoct($data[0]); $this->log(3, "adding to transaction: $type $octmode $data[1]"); @@ -713,6 +764,7 @@ if (!file_exists($data[0])) { $errors[] = "cannot rename file $data[0], doesn't exist"; } + // check that dest dir. is writable if (!is_writable(dirname($data[1]))) { $errors[] = "permission denied ($type): $data[1]"; @@ -755,6 +807,7 @@ $this->log(1, $error); } } + if (!isset($this->_options['ignore-errors'])) { return false; } @@ -773,6 +826,7 @@ $this->file_operations[$i] = false; break; } + if (!@copy($data[0], $data[0] . '.bak')) { $this->log(1, 'Could not copy ' . $data[0] . ' to ' . $data[0] . '.bak ' . $php_errormsg); @@ -787,11 +841,7 @@ } break; case 'rename': - if (file_exists($data[1])) { - $test = @unlink($data[1]); - } else { - $test = null; - } + $test = file_exists($data[1]) ? @unlink($data[1]) : null; if (!$test && file_exists($data[1])) { if ($data[2]) { $extra = ', this extension must be installed manually. Rename to "' . @@ -799,14 +849,17 @@ } else { $extra = ''; } + if (!isset($this->_options['soft'])) { $this->log(1, 'Could not delete ' . $data[1] . ', cannot rename ' . $data[0] . $extra); } + if (!isset($this->_options['ignore-errors'])) { return false; } } + // permissions issues with rename - copy() is far superior $perms = @fileperms($data[0]); if (!@copy($data[0], $data[1])) { @@ -814,6 +867,7 @@ ' ' . $php_errormsg); return false; } + // copy over permissions, otherwise they are lost @chmod($data[1], $perms); @unlink($data[0]); @@ -825,6 +879,7 @@ decoct($data[0]) . ' ' . $php_errormsg); return false; } + $octmode = decoct($data[0]); $this->log(3, "+ chmod $octmode $data[1]"); break; @@ -850,6 +905,7 @@ break 2; // this directory is not empty and can't be // deleted } + closedir($testme); if (!@rmdir($data[0])) { $this->log(1, 'Could not rmdir ' . $data[0] . ' ' . @@ -966,8 +1022,8 @@ { // trickiness: initialize here parent::PEAR_Downloader($this->ui, $options, $config); - $ret = parent::download($packages); - $errors = $this->getErrorMsgs(); + $ret = parent::download($packages); + $errors = $this->getErrorMsgs(); $installpackages = $this->getDownloadedPackages(); trigger_error("PEAR Warning: PEAR_Installer::download() is deprecated " . "in favor of PEAR_Downloader class", E_USER_WARNING); @@ -993,6 +1049,7 @@ $this->log(3, '+ tmp dir created at ' . $tmpdir); // }}} } + // Parse xml file ----------------------------------------------- $pkg = new PEAR_PackageFile($this->config, $this->debug, $tmpdir); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); @@ -1008,9 +1065,9 @@ } } return $this->raiseError('Installation failed: invalid package file'); - } else { - $descfile = $p->getPackageFile(); } + + $descfile = $p->getPackageFile(); return $p; } @@ -1072,15 +1129,16 @@ $this->_options = $options; $this->_registry = &$this->config->getRegistry(); if (is_object($pkgfile)) { - $dlpkg = &$pkgfile; - $pkg = $pkgfile->getPackageFile(); - $pkgfile = $pkg->getArchiveFile(); + $dlpkg = &$pkgfile; + $pkg = $pkgfile->getPackageFile(); + $pkgfile = $pkg->getArchiveFile(); $descfile = $pkg->getPackageFile(); - $tmpdir = dirname($descfile); + $tmpdir = dirname($descfile); } else { $descfile = $pkgfile; - $tmpdir = ''; - if (PEAR::isError($pkg = &$this->_parsePackageXml($descfile, $tmpdir))) { + $tmpdir = ''; + $pkg = &$this->_parsePackageXml($descfile, $tmpdir); + if (PEAR::isError($pkg)) { return $pkg; } } @@ -1098,6 +1156,7 @@ $regdir = $this->_prependPath( $this->config->get('php_dir', null, 'pear.php.net'), $this->_options['packagingroot']); + $packrootphp_dir = $this->_prependPath( $this->config->get('php_dir', null, $channel), $this->_options['packagingroot']); @@ -1370,9 +1429,9 @@ } // }}} - $ret = false; + $ret = false; $installphase = 'install'; - $oldversion = false; + $oldversion = false; // {{{ Register that the package is installed ----------------------- if (empty($options['upgrade'])) { // if 'force' is used, replace the info in registry @@ -1565,16 +1624,15 @@ { if (isset($options['installroot'])) { $this->config->setInstallRoot($options['installroot']); - $this->installroot = ''; } else { $this->config->setInstallRoot(''); - $this->installroot = ''; } + $this->installroot = ''; $this->_registry = &$this->config->getRegistry(); if (is_object($package)) { $channel = $package->getChannel(); - $pkg = $package; + $pkg = $package; $package = $pkg->getPackage(); } else { $pkg = false;