function test_mkdirs_1() { @ini_set('track_errors', true); $php_errormsg = ''; $dir = FREEBEER_BASE . '/var/tmp/test1/test2/test3'; $rv = fbFile::mkdirs($dir); $this->assertTrue($rv, "mkdirs() failed"); $this->assertTrue(@is_dir($dir), "mkdirs() failed to create '{$dir}': {$php_errormsg}"); rmdir($dir); rmdir(dirname($dir)); rmdir(dirname(dirname($dir))); }
function mkdirs($path, $rights = 0777, $umask = null) { if (!$path) { return false; } if (@is_dir($path)) { return true; } $dirname = dirname($path); if ($dirname == $path) { // we've reached / or c:\ return false; } $track_errors = @ini_set('track_errors', true); $php_errormsg = ''; $rv = false; do { if (!@is_dir($dirname)) { if (!fbFile::mkdirs($dirname, $rights)) { break; } } if (!is_null($umask)) { $saved_umask = @umask(); @umask($umask); } $rv = @mkdir($path, $rights); if (!is_null($umask)) { @umask($saved_umask); } if (!$rv) { trigger_error(sprintf('Could not create directory \'%s\': %s', $path, $php_errormsg)); } } while (false); if (!$track_errors) { @ini_set('track_errors', $track_errors); } return $rv; }
$full_testname2 = strtr($full_testname2, '.', '_'); $full_testname2 = strtr($full_testname2, '-', '_'); echo "file={$file}\nfull_testname={$full_testname}\nd={$d}\nfull_testname2={$full_testname2}\n"; $phpunit_code = ''; if ($full_testname2 != $testname) { $phpunit_code = "\n# make PHPUnit_GUI_SetupDecorator() happy\nclass _{$full_testname2} extends _{$testname} {\n}\n"; } //echo "testname=$testname\n"; if ($after_lib_name) { $test = $test_dir . '/' . $after_lib_name . '/' . $testname . '.php'; } else { $test = $test_dir . '/' . $testname . '.php'; } //echo "test=$test\n"; if (!@is_dir($test_dir . '/' . $after_lib_name)) { fbFile::mkdirs($test_dir . '/' . $after_lib_name, 0777, 00); } $exists = is_file($test); if ($exists) { $filesize = filesize($test); } $fp = fopen($test, 'a+b'); if (!$fp) { die("Can't open {$test}: {$php_errormsg}"); } if ($after_lib_name) { $after_lib_name .= '/'; } if (!$exists) { $data = <<<EOD <?php
#!/usr/bin/php <?php // $CVSHeader: _freebeer/bin/make_www_lib_tests.php,v 1.2 2004/03/07 17:51:14 ross Exp $ // Copyright (c) 2002-2004, Ross Smith. All rights reserved. // Licensed under the BSD or LGPL License. See license.txt for details. error_reporting(2047); @ini_set('html_errors', false); @ini_set('track_errors', true); @ob_implicit_flush(true); @set_time_limit(0); defined('FREEBEER_BASE') || define('FREEBEER_BASE', getenv('FREEBEER_BASE') ? getenv('FREEBEER_BASE') : dirname(dirname(__FILE__))); require_once FREEBEER_BASE . '/lib/File.php'; // scandir() $file_dir = FREEBEER_BASE . '/www/lib'; $test_dir = FREEBEER_BASE . '/www/lib/tests'; $files = fbFile::scandir($file_dir, null, true); //print_r($files); $test_files = array(); foreach ($files as $file) { /// \todo use DIRECTORY_SEPARATOR instead of hardcoded / $file = strtr($file, '\\', '/'); if (!preg_match('/\\.js$/i', $file)) { continue; } if (preg_match('/jsunit\\.net/i', $file)) { continue; } $test_files[$file] = substr($file, strlen(FREEBEER_BASE) + 4); } print_r($test_files); foreach ($test_files as $file => $www_file) {
@ini_set('track_errors', true); @ob_implicit_flush(true); @set_time_limit(0); defined('FREEBEER_BASE') || define('FREEBEER_BASE', getenv('FREEBEER_BASE') ? getenv('FREEBEER_BASE') : dirname(dirname(__FILE__))); //if (phpversion() < '5.0') { // require_once FREEBEER_BASE . '/lib/Backport.php'; // scandir //} //require_once FREEBEER_BASE . '/lib/System.php'; require_once FREEBEER_BASE . '/lib/File.php'; // scandir $exts = array('cmd' => array('prior' => '@echo off', 'start' => 3, 'prefix' => ':: ', 'suffix' => ''), 'htm' => array('prior' => '', 'start' => 1, 'prefix' => '<!-- ', 'suffix' => ' -->'), 'ini' => array('prior' => '', 'start' => 1, 'prefix' => '# ', 'suffix' => ''), 'js' => array('prior' => '', 'start' => 1, 'prefix' => '// ', 'suffix' => ''), 'php' => array('prior' => '<?php', 'start' => 3, 'prefix' => '// ', 'suffix' => ''), 'pl' => array('prior' => '#!/usr/bin/perl', 'start' => 3, 'prefix' => '# ', 'suffix' => ''), 'po' => array('prior' => '', 'start' => 2, 'prefix' => '# ', 'suffix' => ''), 'sh' => array('prior' => '#!/bin/sh', 'start' => 3, 'prefix' => '# ', 'suffix' => ''), 'sql' => array('prior' => '', 'start' => 1, 'prefix' => '-- ', 'suffix' => ''), 'txt' => array('prior' => '', 'start' => 1, 'prefix' => '', 'suffix' => '')); $exts['bat'] = $exts['cmd']; $exts['html'] = $exts['htm']; $exts['pot'] = $exts['po']; $search1 = array('|^(\\S+)\\s*\\$CVSHeader[^\\$]*|i' => '$' . 'CVSHeader$', '|^\\s*$|' => '', '|^(\\S+)\\s*Copyright.*Ross\\s+Smith|i' => 'Copyright (c) 2002-2004, Ross Smith. All rights reserved.', '|^(\\S+)\\s*Licensed\\s+under\\s+the\\s+BSD|i' => 'Licensed under the BSD or LGPL License. See license.txt for details.'); $files = fbFile::scandir(FREEBEER_BASE, 0, true); foreach ($files as $file) { $basename = basename($file); $base = $basename; $ext = ''; if (preg_match('/(.+)\\.([^\\.]+)/', $basename, $matches)) { $base = $matches[1]; $ext = $matches[2]; } $found = false; foreach ($exts as $extregex => $extrules) { if (preg_match('/' . $extregex . '/', $ext, $matches)) { $found = true; break; } }
<?php // $CVSHeader: _freebeer/www/lib/tests/index.php,v 1.3 2004/03/08 04:29:18 ross Exp $ // Copyright (c) 2002-2004, Ross Smith. All rights reserved. // Licensed under the BSD or LGPL License. See license.txt for details. error_reporting(2047); defined('FREEBEER_BASE') || define('FREEBEER_BASE', getenv('FREEBEER_BASE') ? getenv('FREEBEER_BASE') : dirname(dirname(dirname(dirname(__FILE__))))); // no longer required, right? // require_once FREEBEER_BASE . '/lib/Pear/Pear.php'; require_once FREEBEER_BASE . '/lib/File.php'; // scandir() require_once FREEBEER_BASE . '/www/fbWeb.php'; $www_root = fbWeb::getWebRoot(); $rootdir = $www_root . '/lib/tests/'; $files = fbFile::scandir('.', null, true); $files2 = array(); $files3 = array(); foreach ($files as $file) { $file = substr($file, 2); /// \todo change to DIRECTORY_SEPARATOR, or remove $file = strtr($file, "\\", '/'); if (!preg_match('/\\.(php|htm|html)$/i', $file)) { continue; } if (preg_match('/^index\\.php$/i', $file)) { continue; } if (preg_match('/^_.*\\.php$/i', $file)) { continue; } $path = $rootdir . $file;
function update_htaccess($dir, $depth) { if (preg_match('|/CVS$|', $dir)) { return true; } if (preg_match('|/opt$|', $dir)) { return true; } if (preg_match('|/wip$|', $dir)) { return true; } if (preg_match('|/www$|', $dir)) { return true; } $files = fbFile::scandir($dir, 0, false); $dirs = array(); $found = false; foreach ($files as $file) { $path = $dir . '/' . $file; if (@is_dir($path)) { $dirs[] = $path; continue; } if ($file == '.htaccess') { $found = true; continue; } } // foreach($files as $file) $cvsheader_found = false; $deny_found = false; $lines = array(); $path = $dir . '/.htaccess'; if ($found) { $lines = file($path); if ($lines === false) { die(sprintf("Can't open '%s': %s", $file, $php_errormsg)); } for ($i = 0; $i < count($lines); ++$i) { if (preg_match('/(allow|deny)\\s+from\\s+all/i', $lines[$i])) { $deny_found = true; } if (preg_match('/\\$CVSHeader[^\\$]*\\$/', $lines[$i])) { $cvsheader_found = true; } if ($deny_found && $cvsheader_found) { break; } } } if (!$deny_found || !$cvsheader_found) { if (!$deny_found) { $lines[] = "Deny from all\n"; } if (!$cvsheader_found) { $lines[] = "\n# \$CVSHeader\$\n"; } if ($found) { $file_tmp = $path . '.tmp'; $file_bak = $path . '.bak'; } else { $file_tmp = $path; } $fp = fopen($file_tmp, 'wb'); if (!$fp) { die(sprintf("Can't create '%s': %s", $file_tmp, $php_errormsg)); } for ($i = 0; $i < count($lines); ++$i) { fwrite($fp, $lines[$i]); } fclose($fp); printf("Updated %s\n", $path); if ($found) { if (!@rename($path, $file_bak)) { die(sprintf("Can't rename '%s' to '%s': %s", $path, $file_bak, $php_errormsg)); } if (!@rename($file_tmp, $path)) { die(sprintf("Can't rename '%s' to '%s': %s", $file_tmp, $path, $php_errormsg)); } } } // if (!$deny_found || !$cvsheader_found) if ($depth == 0) { foreach ($dirs as $dir) { if (!update_htaccess($dir, $depth + 1)) { return false; } } } return true; }