Project

General

Profile

« Previous | Next » 

Revision 0fdf1eaa

Added by Colin Smith over 20 years ago

rmdir_recursive: Check that the specified directories actually exist before trying to remove them.

View differences:

etc/inc/pfsense-utils.inc
930 930
function rmdir_recursive($path,$follow_links=false) {
931 931
	$to_do = glob($path);
932 932
	if(!is_array($to_do)) {
933
		$dir = opendir($path);
934
		while ($entry = readdir($dir)) {
935
			if (is_file("$path/$entry") || ((!$follow_links) && is_link("$path/$entry")))
936
				unlink("$path/$entry");
937
       			elseif (is_dir("$path/$entry") && $entry!='.' && $entry!='..')
938
				rmdir_recursive("$path/$entry");
939
		}
940
		closedir($dir);
941
		rmdir($path);
942
		return;
943
	} else {
944
		foreach($to_do as $workingdir) { // Handle wildcards by foreaching.
945
			$dir = opendir($workingdir);
933
		if(file_exists($to_do)) {
934
			$dir = opendir($path);
946 935
			while ($entry = readdir($dir)) {
947
                        if (is_file("$workingdir/$entry") || ((!$follow_links) && is_link("$workingdir/$entry")))
948
                                unlink("$workingdir/$entry");
949
                        elseif (is_dir("$workingdir/$entry") && $entry!='.' && $entry!='..')
950
                                rmdir_recursive("$workingdir/$entry");
936
				if (is_file("$path/$entry") || ((!$follow_links) && is_link("$path/$entry")))
937
					unlink("$path/$entry");
938
      	 			elseif (is_dir("$path/$entry") && $entry!='.' && $entry!='..')
939
					rmdir_recursive("$path/$entry");
951 940
			}
952 941
			closedir($dir);
953
			rmdir($workingdir);
954
                }
942
			rmdir($path);
943
			return;
944
		}
945
	} else {
946
		foreach($to_do as $workingdir) { // Handle wildcards by foreaching.
947
			if(file_exists($workingdir)) {
948
				$dir = opendir($workingdir);
949
				while ($entry = readdir($dir)) {
950
					if (is_file("$workingdir/$entry") || ((!$follow_links) && is_link("$workingdir/$entry")))
951
					unlink("$workingdir/$entry");
952
					elseif (is_dir("$workingdir/$entry") && $entry!='.' && $entry!='..')
953
					rmdir_recursive("$workingdir/$entry");
954
				}
955
				closedir($dir);
956
				rmdir($workingdir);
957
                	}
958
		}
955 959
		return;
956 960
	}
957 961
	return;
......
1004 1008
	return;
1005 1009
}
1006 1010

  
1007
function xmlrpc_value_to_php($value) {
1008
	if($value->kindOf() == 'array') {
1009
		$toreturn = array();
1010
		for($i= 0; $i < $value->arraysize(); $i++) {
1011
			$arrayval = $value->arraymem($i);
1012
			if($arrayval->kindOf() == 'array') {
1013
				$toreturn[] = xmlrpc_value_to_php($arrayval);
1014
			} else {
1015
				$toreturn[] = $arrayval->scalarval();	
1016
			}
1017
		}
1018
	} else {
1019
		$toreturn = $value->scalarval();
1020
	}
1021
	return $toreturn;
1022
}
1023

  
1024

  
1025 1011
/*
1026 1012
 * check_firmware_version(): Check whether the current firmware installed is the most recently released.
1027 1013
 */
......
1043 1029
	if($resp->faultCode()) return -1;
1044 1030
        if($return_php == false) return $resp->serialize();
1045 1031
	$raw_versions = $resp->value();
1046
	return xmlrpc_value_to_php($raw_versions);
1032
	$toreturn = array();
1033
	for($i = 0; $i < $raw_versions->arraysize(); $i++) {
1034
		$arrayval = $raw_versions->arraymem($i);
1035
		$toreturn[] = $arrayval->scalarval();
1036
	}
1037
	return $toreturn;
1047 1038
}
1048 1039

  
1049 1040
?>

Also available in: Unified diff