migrated install_switch's recursive_* routines
This commit is contained in:
+78
-29
@@ -144,27 +144,78 @@
|
||||
}
|
||||
|
||||
if (!function_exists('recursive_copy')) {
|
||||
function recursive_copy($src,$dst) {
|
||||
$dir = opendir($src);
|
||||
if (!$dir) {
|
||||
throw new Exception("recursive_copy() source directory '".$src."' does not exist.");
|
||||
}
|
||||
if (!is_dir($dst)) {
|
||||
if (!mkdir($dst)) {
|
||||
throw new Exception("recursive_copy() failed to create destination directory '".$dst."'");
|
||||
if (file_exists('/bin/cp')) {
|
||||
function recursive_copy($src, $dst, $options = '') {
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'SUN') {
|
||||
//copy -R recursive, preserve attributes for SUN
|
||||
$cmd = 'cp -Rp '.$src.'/* '.$dst;
|
||||
} else {
|
||||
//copy -R recursive, -L follow symbolic links, -p preserve attributes for other Posix systemss
|
||||
$cmd = 'cp -RLp '.$options.' '.$src.'/* '.$dst;
|
||||
}
|
||||
$this->write_debug($cmd);
|
||||
exec ($cmd);
|
||||
}
|
||||
while(false !== ( $file = readdir($dir)) ) {
|
||||
if (( $file != '.' ) && ( $file != '..' )) {
|
||||
if ( is_dir($src . '/' . $file) ) {
|
||||
recursive_copy($src . '/' . $file,$dst . '/' . $file);
|
||||
}
|
||||
else {
|
||||
copy($src . '/' . $file,$dst . '/' . $file);
|
||||
}elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
|
||||
function recursive_copy($src, $dst, $options = '') {
|
||||
$src = normalize_path_to_os($src);
|
||||
$dst = normalize_path_to_os($dst);
|
||||
exec("xcopy /E /Y \"$src\" \"$dst\"");
|
||||
}
|
||||
}else{
|
||||
function recursive_copy($src, $dst, $options = '') {
|
||||
$dir = opendir($src);
|
||||
if (!$dir) {
|
||||
throw new Exception("recursive_copy() source directory '".$src."' does not exist.");
|
||||
}
|
||||
if (!is_dir($dst)) {
|
||||
if (!mkdir($dst)) {
|
||||
throw new Exception("recursive_copy() failed to create destination directory '".$dst."'");
|
||||
}
|
||||
}
|
||||
while(false !== ( $file = readdir($dir)) ) {
|
||||
if (( $file != '.' ) && ( $file != '..' )) {
|
||||
if ( is_dir($src . '/' . $file) ) {
|
||||
recursive_copy($src . '/' . $file,$dst . '/' . $file);
|
||||
}
|
||||
else {
|
||||
copy($src . '/' . $file,$dst . '/' . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('recursive_delete')) {
|
||||
if (file_exists('/bin/rm')) {
|
||||
protected function recursive_delete($dir) {
|
||||
$this->write_debug('rm -Rf '.$dir.'/*');
|
||||
exec ('rm -Rf '.$dir.'/*');
|
||||
clearstatcache();
|
||||
}
|
||||
}elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
|
||||
protected function recursive_delete($dir) {
|
||||
$dst = normalize_path_to_os($dst);
|
||||
$this->write_debug("del /S /F /Q \"$dir\"");
|
||||
exec("del /S /F /Q \"$dir\"");
|
||||
clearstatcache();
|
||||
}
|
||||
}else{
|
||||
protected function recursive_delete($dir) {
|
||||
foreach (glob($dir) as $file) {
|
||||
if (is_dir($file)) {
|
||||
$this->write_debug("rm dir: ".$file);
|
||||
$this->recursive_delete("$file/*");
|
||||
rmdir($file);
|
||||
} else {
|
||||
$this->write_debug("delete file: ".$file);
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
clearstatcache();
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1326,19 +1377,17 @@ function number_pad($number,$n) {
|
||||
}
|
||||
|
||||
//email validate
|
||||
if (!function_exists('email_validate')) {
|
||||
function email_validate($strEmail){
|
||||
$validRegExp = '/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,3}$/';
|
||||
// search email text for regular exp matches
|
||||
preg_match($validRegExp, $strEmail, $matches, PREG_OFFSET_CAPTURE);
|
||||
function email_validate($strEmail){
|
||||
$validRegExp = '/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,3}$/';
|
||||
// search email text for regular exp matches
|
||||
preg_match($validRegExp, $strEmail, $matches, PREG_OFFSET_CAPTURE);
|
||||
|
||||
if (count($matches) == 0) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($matches) == 0) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user