cvs: pearweb /public_html go-pear
| From: | Pierre-Alain Joye | Date: | Sun, 06 Jun 2004 22:48:19 +0000 |
| Subject: | cvs: pearweb /public_html go-pear | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-20295@lists.php.net to get a copy of this message | ||
pajoye Sun Jun 6 18:48:19 2004 EDT
Modified files:
/pearweb/public_html go-pear
Log:
- Some fixes in tmp folder detections
- Consistent usage of tmp_dir
- CS
- Fix #1494 (go-pear.bat can't handle TEMP dir set as drive root)
- Fix 1156 (wrond detection of old pear cmd on win32) (danielc)
- Fix some path issues on both windows and linux
- Safe path solving using realpath
- Cleanup the evil path separator things
- Silent warnings in rm_rf
- remove the check for spaces in install path. Spaces are supported
now
http://cvs.php.net/diff.php/pearweb/public_html/go-pear?r1=1.62&r2=1.63&ty=u Index: pearweb/public_html/go-pear diff -u pearweb/public_html/go-pear:1.62 pearweb/public_html/go-pear:1.63 --- pearweb/public_html/go-pear:1.62 Sun May 23 16:21:18 2004 +++ pearweb/public_html/go-pear Sun Jun 6 18:48:19 2004 @@ -17,7 +17,7 @@ # | Christian Dickmann <dickmann@php.net> | # | Pierre-Alain Joye <pajoye@pearfr.org> | # +----------------------------------------------------------------------+ -# $Id: go-pear,v 1.62 2004/05/23 20:21:18 pajoye Exp $ +# $Id: go-pear,v 1.63 2004/06/06 22:48:19 pajoye Exp $ # # Automatically download all the files needed to run the "pear" command # (the PEAR package installer). Requires PHP 4.1.0 or newer. @@ -86,7 +86,7 @@ ini_set('magic_quotes_runtime', false); error_reporting( E_ALL & ~E_NOTICE); define('WINDOWS', (substr(PHP_OS, 0, 3) == 'WIN')); -define('GO_PEAR_VER', '0.3.0'); +define('GO_PEAR_VER', '0.4.0'); define('WIN32GUI', !WEBINSTALLER && WINDOWS && $sapi_name=='cli' && which('cscript')); @@ -151,7 +151,6 @@ $installer_packages[] = 'Net_UserAgent_Detect'; $installer_packages[] = 'PEAR_Frontend_Web'; } -$version_n = explode(".",phpversion()); $pfc_packages = array( 'DB', @@ -160,7 +159,7 @@ 'Mail', 'XML_Parser', 'PHPUnit' - ); +); $config_desc = array( 'prefix' => 'Installation prefix', @@ -212,20 +211,19 @@ } if (!isset($_SESSION['go-pear']) || isset($_GET['restart'])) { - $sep = WINDOWS ? "\\" : '/'; $_SESSION['go-pear'] = array( 'http_proxy' => $http_proxy, 'config' => array( 'prefix' => dirname(__FILE__), 'bin_dir' => $bin_dir, 'php_bin' => $php_bin, - 'php_dir' => '$prefix'.$sep.'PEAR', + 'php_dir' => '$prefix/PEAR', 'doc_dir' => $doc_dir, 'data_dir' => $data_dir, 'test_dir' => $test_dir, - 'cache_dir' => '$php_dir'.$sep.'cache', + 'cache_dir' => '$php_dir/cache', 'cache_ttl' => 300, - 'webfrontend_file' => '$prefix'.$sep.'index.php', + 'webfrontend_file' => '$prefix/index.php', ), 'install_pfc' => true, 'DHTML' => true, @@ -246,9 +244,7 @@ foreach($_POST['config'] as $key => $value) { $_POST['config'][$key] = strip_magic_quotes($value); if($key!='cache_ttl'){ - if( ereg(' ', $_POST['config'][$key]) ) { - $www_errors[$key] = 'Spaces are not allowed in pathes. Please choose another path.'; - } elseif ( empty($_POST['config'][$key]) ) { + if ( empty($_POST['config'][$key]) ) { if (WEBINSTALLER && $key!='php_bin' ) { $www_errors[$key] = 'Please fill this path, you can use $prefix, $php_dir or a full path.'; } @@ -397,34 +393,6 @@ mkdir_p($ptmp, 0700); $ok = @chdir($ptmp); -// If for some reason the user has no rights to access to -// the standard tempdir, we assume that he has the right -// to access his prefix and choose $prefix/tmp as tempdir -if (!$ok) { - print "System's Tempdir failed, trying to use \$prefix/tmp ..."; - $res = mkdir_p($prefix.'/tmp'); - if (!$res) { - bail('mkdir '.$prefix.'/tmp'.' ... failed'); - } - $ptmp = tempnam($prefix.'/tmp', 'gope'); - - rm_rf($ptmp); - mkdir_p($ptmp, 0700); - $ok = @chdir($ptmp); - - if (!$ok) { // This should not happen, really ;) - bail('chdir '.$ptmp.' ... failed'); - } - - print "ok\n"; - - // Adjust TEMPDIR envvars - if (!isset($_ENV)) { - $_ENV = array(); - }; - $_ENV['TMPDIR'] = $_ENV['TEMP'] = $prefix.'/tmp'; -} - while (!WEBINSTALLER) { print " Below is a suggested file layout for your new PEAR installation. To @@ -433,12 +401,11 @@ accept these locations. "; - if( WINDOWS && $php_bin=='' ){ - } foreach ($config_vars as $n => $var) { printf("%2d. $descfmt : %s\n", $n, $config_desc[$var], $$var); } + print "\n$first-$last, 'all' or Enter to continue: "; $tmp = trim(fgets($tty, 1024)); if ( empty($tmp) ) { @@ -515,9 +482,11 @@ foreach ($config_vars as $var) { $dir = $$var; + if (!preg_match('/_dir$/', $var)) { continue; - }; + } + if (!@is_dir($dir)) { if (!mkdir_p($dir)) { $root = WINDOWS ? 'administrator' : 'root'; @@ -784,17 +753,17 @@ } $pear_cmd = $bin_dir . DIRECTORY_SEPARATOR . 'pear'; - $pear_cmd .= WINDOWS?'.bat':''; + $pear_cmd = WINDOWS ? strtolower($pear_cmd).'.bat' : $pear_cmd; // check that the installed pear and the one in tha path are the same (if any) $pear_old = which('pear', $bin_dir); if ($pear_old && $pear_old != $pear_cmd) { // check if it is a link or symlink - $islink = WINDOWS ? is_link($pear_old) : false; + $islink = WINDOWS ? false : is_link($pear_old) ; if ($islink && readlink($pear_old) != $pear_cmd) { print "\n** WARNING! The link $pear_old does not point to the " . "installed $pear_cmd\n"; - } elseif (is_writable($pear_old)) { + } elseif (is_writable($pear_old) && !is_dir($pear_old)) { rename($pear_old, "{$pear_old}_old"); print "\n** WARNING! Backed up old pear to {$pear_old}_old\n"; } else { @@ -992,7 +961,7 @@ file_exists($ret = "$tmp.com") || file_exists($ret = "$tmp.bat") || file_exists($ret = "$tmp.cmd")) { - return $ret; + return strtolower($ret); } } } else { @@ -1059,7 +1028,7 @@ function rm_rf($path) { - if (@is_dir($path)) { + if (@is_dir($path) && is_writable($path)) { $dp = opendir($path); while ($ent = readdir($dp)) { if ($ent == '.' || $ent == '..') { @@ -1068,8 +1037,11 @@ $file = $path . DIRECTORY_SEPARATOR . $ent; if (@is_dir($file)) { rm_rf($file); - } else { + } elseif (is_writable($file)) { unlink($file); + } else { + echo $file . "is not writable and cannot be removed. +Please fix the permission or select a new path.\n"; } } closedir($dp); @@ -1087,6 +1059,7 @@ function tmp_dir() { global $ptmp; + $_temp = false; if (WINDOWS){ if ( my_env('TEMP') ) { $_temp = my_env('TEMP'); @@ -1117,12 +1090,44 @@ } } $ptmp = $_temp; - return $_temp; + } else { + $_temp = my_env('TMPDIR'); + if (!$_temp) { + if (is_writable('/tmp')) { + $_temp = '/tmp'; + } + } } - if (my_env('TMPDIR')) { - return my_env('TMPDIR'); + + // If for some reason the user has no rights to access to + // the standard tempdir, we assume that he has the right + // to access his prefix and choose $prefix/tmp as tempdir + if (!$_temp) { + print "System's Tempdir failed, trying to use \$prefix/tmp ..."; + $res = mkdir_p($prefix.'/tmp'); + if (!$res) { + bail('mkdir '.$prefix.'/tmp'.' ... failed'); + } + + $_temp = tempnam($prefix.'/tmp', 'gope'); + + rm_rf($_temp); + mkdir_p($_temp, 0700); + $ok = @chdir($ptmp); + + if (!$ok) { // This should not happen, really ;) + bail('chdir '.$ptmp.' ... failed'); + } + + print "ok\n"; + + // Adjust TEMPDIR envvars + if (!isset($_ENV)) { + $_ENV = array(); + }; + $_ENV['TMPDIR'] = $_ENV['TEMP'] = $prefix.'/tmp'; } - return '/tmp'; + $ptmp = $_temp; } // }}} @@ -2014,7 +2019,7 @@ * - Replace WSH with calls to w32 as soon as callbacks work * @Author Pierrre-Alain Joye */ -function win32BrowseForFolder ( $label ) +function win32BrowseForFolder($label) { global $ptmp; static $wshSaved=false; @@ -2074,7 +2079,8 @@ * This addon set PEAR environment variables * @Author Pierrre-Alain Joye */ -function win32CreateRegEnv(){ +function win32CreateRegEnv() +{ global $prefix, $bin_dir, $php_dir, $php_bin, $doc_dir, $data_dir, $test_dir; $nl = "\r\n"; $reg ='REGEDIT4'.$nl. @@ -2086,7 +2092,7 @@ '"PHP_PEAR_DATA_DIR"="'.addslashes($data_dir).'"'.$nl. '"PHP_PEAR_PHP_BIN"="'.addslashes($php_bin).'"'.$nl. '"PHP_PEAR_TEST_DIR"="'.addslashes($test_dir).'"'.$nl; - //$path = dirname(__FILE__).DIRECTORY_SEPARATOR; + $fh = fopen($prefix.DIRECTORY_SEPARATOR.'PEAR_ENV.reg','wb'); if($fh){ fwrite($fh, $reg ,strlen($reg)); @@ -2318,4 +2324,4 @@ } return true; } -?> +?> \ No newline at end of file
http://cvs.php.net/diff.php/pearweb/public_html/go-pear?r1=1.62&r2=1.63&ty=u Index: pearweb/public_html/go-pear diff -u pearweb/public_html/go-pear:1.62 pearweb/public_html/go-pear:1.63 --- pearweb/public_html/go-pear:1.62 Sun May 23 16:21:18 2004 +++ pearweb/public_html/go-pear Sun Jun 6 18:48:19 2004 @@ -17,7 +17,7 @@ # | Christian Dickmann <dickmann@php.net> | # | Pierre-Alain Joye <pajoye@pearfr.org> | # +----------------------------------------------------------------------+ -# $Id: go-pear,v 1.62 2004/05/23 20:21:18 pajoye Exp $ +# $Id: go-pear,v 1.63 2004/06/06 22:48:19 pajoye Exp $ # # Automatically download all the files needed to run the "pear" command # (the PEAR package installer). Requires PHP 4.1.0 or newer. @@ -86,7 +86,7 @@ ini_set('magic_quotes_runtime', false); error_reporting( E_ALL & ~E_NOTICE); define('WINDOWS', (substr(PHP_OS, 0, 3) == 'WIN')); -define('GO_PEAR_VER', '0.3.0'); +define('GO_PEAR_VER', '0.4.0'); define('WIN32GUI', !WEBINSTALLER && WINDOWS && $sapi_name=='cli' && which('cscript')); @@ -151,7 +151,6 @@ $installer_packages[] = 'Net_UserAgent_Detect'; $installer_packages[] = 'PEAR_Frontend_Web'; } -$version_n = explode(".",phpversion()); $pfc_packages = array( 'DB', @@ -160,7 +159,7 @@ 'Mail', 'XML_Parser', 'PHPUnit' - ); +); $config_desc = array( 'prefix' => 'Installation prefix', @@ -212,20 +211,19 @@ } if (!isset($_SESSION['go-pear']) || isset($_GET['restart'])) { - $sep = WINDOWS ? "\\" : '/'; $_SESSION['go-pear'] = array( 'http_proxy' => $http_proxy, 'config' => array( 'prefix' => dirname(__FILE__), 'bin_dir' => $bin_dir, 'php_bin' => $php_bin, - 'php_dir' => '$prefix'.$sep.'PEAR', + 'php_dir' => '$prefix/PEAR', 'doc_dir' => $doc_dir, 'data_dir' => $data_dir, 'test_dir' => $test_dir, - 'cache_dir' => '$php_dir'.$sep.'cache', + 'cache_dir' => '$php_dir/cache', 'cache_ttl' => 300, - 'webfrontend_file' => '$prefix'.$sep.'index.php', + 'webfrontend_file' => '$prefix/index.php', ), 'install_pfc' => true, 'DHTML' => true, @@ -246,9 +244,7 @@ foreach($_POST['config'] as $key => $value) { $_POST['config'][$key] = strip_magic_quotes($value); if($key!='cache_ttl'){ - if( ereg(' ', $_POST['config'][$key]) ) { - $www_errors[$key] = 'Spaces are not allowed in pathes. Please choose another path.'; - } elseif ( empty($_POST['config'][$key]) ) { + if ( empty($_POST['config'][$key]) ) { if (WEBINSTALLER && $key!='php_bin' ) { $www_errors[$key] = 'Please fill this path, you can use $prefix, $php_dir or a full path.'; } @@ -397,34 +393,6 @@ mkdir_p($ptmp, 0700); $ok = @chdir($ptmp); -// If for some reason the user has no rights to access to -// the standard tempdir, we assume that he has the right -// to access his prefix and choose $prefix/tmp as tempdir -if (!$ok) { - print "System's Tempdir failed, trying to use \$prefix/tmp ..."; - $res = mkdir_p($prefix.'/tmp'); - if (!$res) { - bail('mkdir '.$prefix.'/tmp'.' ... failed'); - } - $ptmp = tempnam($prefix.'/tmp', 'gope'); - - rm_rf($ptmp); - mkdir_p($ptmp, 0700); - $ok = @chdir($ptmp); - - if (!$ok) { // This should not happen, really ;) - bail('chdir '.$ptmp.' ... failed'); - } - - print "ok\n"; - - // Adjust TEMPDIR envvars - if (!isset($_ENV)) { - $_ENV = array(); - }; - $_ENV['TMPDIR'] = $_ENV['TEMP'] = $prefix.'/tmp'; -} - while (!WEBINSTALLER) { print " Below is a suggested file layout for your new PEAR installation. To @@ -433,12 +401,11 @@ accept these locations. "; - if( WINDOWS && $php_bin=='' ){ - } foreach ($config_vars as $n => $var) { printf("%2d. $descfmt : %s\n", $n, $config_desc[$var], $$var); } + print "\n$first-$last, 'all' or Enter to continue: "; $tmp = trim(fgets($tty, 1024)); if ( empty($tmp) ) { @@ -515,9 +482,11 @@ foreach ($config_vars as $var) { $dir = $$var; + if (!preg_match('/_dir$/', $var)) { continue; - }; + } + if (!@is_dir($dir)) { if (!mkdir_p($dir)) { $root = WINDOWS ? 'administrator' : 'root'; @@ -784,17 +753,17 @@ } $pear_cmd = $bin_dir . DIRECTORY_SEPARATOR . 'pear'; - $pear_cmd .= WINDOWS?'.bat':''; + $pear_cmd = WINDOWS ? strtolower($pear_cmd).'.bat' : $pear_cmd; // check that the installed pear and the one in tha path are the same (if any) $pear_old = which('pear', $bin_dir); if ($pear_old && $pear_old != $pear_cmd) { // check if it is a link or symlink - $islink = WINDOWS ? is_link($pear_old) : false; + $islink = WINDOWS ? false : is_link($pear_old) ; if ($islink && readlink($pear_old) != $pear_cmd) { print "\n** WARNING! The link $pear_old does not point to the " . "installed $pear_cmd\n"; - } elseif (is_writable($pear_old)) { + } elseif (is_writable($pear_old) && !is_dir($pear_old)) { rename($pear_old, "{$pear_old}_old"); print "\n** WARNING! Backed up old pear to {$pear_old}_old\n"; } else { @@ -992,7 +961,7 @@ file_exists($ret = "$tmp.com") || file_exists($ret = "$tmp.bat") || file_exists($ret = "$tmp.cmd")) { - return $ret; + return strtolower($ret); } } } else { @@ -1059,7 +1028,7 @@ function rm_rf($path) { - if (@is_dir($path)) { + if (@is_dir($path) && is_writable($path)) { $dp = opendir($path); while ($ent = readdir($dp)) { if ($ent == '.' || $ent == '..') { @@ -1068,8 +1037,11 @@ $file = $path . DIRECTORY_SEPARATOR . $ent; if (@is_dir($file)) { rm_rf($file); - } else { + } elseif (is_writable($file)) { unlink($file); + } else { + echo $file . "is not writable and cannot be removed. +Please fix the permission or select a new path.\n"; } } closedir($dp); @@ -1087,6 +1059,7 @@ function tmp_dir() { global $ptmp; + $_temp = false; if (WINDOWS){ if ( my_env('TEMP') ) { $_temp = my_env('TEMP'); @@ -1117,12 +1090,44 @@ } } $ptmp = $_temp; - return $_temp; + } else { + $_temp = my_env('TMPDIR'); + if (!$_temp) { + if (is_writable('/tmp')) { + $_temp = '/tmp'; + } + } } - if (my_env('TMPDIR')) { - return my_env('TMPDIR'); + + // If for some reason the user has no rights to access to + // the standard tempdir, we assume that he has the right + // to access his prefix and choose $prefix/tmp as tempdir + if (!$_temp) { + print "System's Tempdir failed, trying to use \$prefix/tmp ..."; + $res = mkdir_p($prefix.'/tmp'); + if (!$res) { + bail('mkdir '.$prefix.'/tmp'.' ... failed'); + } + + $_temp = tempnam($prefix.'/tmp', 'gope'); + + rm_rf($_temp); + mkdir_p($_temp, 0700); + $ok = @chdir($ptmp); + + if (!$ok) { // This should not happen, really ;) + bail('chdir '.$ptmp.' ... failed'); + } + + print "ok\n"; + + // Adjust TEMPDIR envvars + if (!isset($_ENV)) { + $_ENV = array(); + }; + $_ENV['TMPDIR'] = $_ENV['TEMP'] = $prefix.'/tmp'; } - return '/tmp'; + $ptmp = $_temp; } // }}} @@ -2014,7 +2019,7 @@ * - Replace WSH with calls to w32 as soon as callbacks work * @Author Pierrre-Alain Joye */ -function win32BrowseForFolder ( $label ) +function win32BrowseForFolder($label) { global $ptmp; static $wshSaved=false; @@ -2074,7 +2079,8 @@ * This addon set PEAR environment variables * @Author Pierrre-Alain Joye */ -function win32CreateRegEnv(){ +function win32CreateRegEnv() +{ global $prefix, $bin_dir, $php_dir, $php_bin, $doc_dir, $data_dir, $test_dir; $nl = "\r\n"; $reg ='REGEDIT4'.$nl. @@ -2086,7 +2092,7 @@ '"PHP_PEAR_DATA_DIR"="'.addslashes($data_dir).'"'.$nl. '"PHP_PEAR_PHP_BIN"="'.addslashes($php_bin).'"'.$nl. '"PHP_PEAR_TEST_DIR"="'.addslashes($test_dir).'"'.$nl; - //$path = dirname(__FILE__).DIRECTORY_SEPARATOR; + $fh = fopen($prefix.DIRECTORY_SEPARATOR.'PEAR_ENV.reg','wb'); if($fh){ fwrite($fh, $reg ,strlen($reg)); @@ -2318,4 +2324,4 @@ } return true; } -?> +?> \ No newline at end of file