More reliable cache flusher that does not require glob().
git-svn-id: http://svn.automattic.com/wordpress/trunk@3400 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
dd8e5a3aae
commit
9675f5fd55
|
@ -91,7 +91,7 @@ class WP_Object_Cache {
|
||||||
if ( !$this->cache_enabled )
|
if ( !$this->cache_enabled )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$this->rm($this->cache_dir.'*');
|
$this->rm_cache_dir();
|
||||||
$this->cache = array ();
|
$this->cache = array ();
|
||||||
$this->dirty_objects = array ();
|
$this->dirty_objects = array ();
|
||||||
$this->non_existant_objects = array ();
|
$this->non_existant_objects = array ();
|
||||||
|
@ -214,25 +214,34 @@ class WP_Object_Cache {
|
||||||
return $this->cache_dir."$group_dir/";
|
return $this->cache_dir."$group_dir/";
|
||||||
}
|
}
|
||||||
|
|
||||||
function rm($fileglob) {
|
function rm_cache_dir() {
|
||||||
if (is_file($fileglob)) {
|
$dir = $this->cache_dir;
|
||||||
return @ unlink($fileglob);
|
$dir = rtrim($dir, DIRECTORY_SEPARATOR);
|
||||||
} else
|
$stack = array($dir);
|
||||||
if (is_dir($fileglob)) {
|
|
||||||
$ok = WP_Object_Cache::rm("$fileglob/*");
|
while (count($stack)) {
|
||||||
if (!$ok)
|
# Get last directory on stack
|
||||||
return false;
|
$dir = end($stack);
|
||||||
return @ rmdir($fileglob);
|
|
||||||
} else {
|
$dh = @ opendir($dir);
|
||||||
$matching = glob($fileglob);
|
if (!$dh)
|
||||||
if ($matching === false)
|
return false;
|
||||||
return true;
|
|
||||||
$rcs = array_map(array ('WP_Object_Cache', 'rm'), $matching);
|
while (($file = @ readdir($dh)) !== false) {
|
||||||
if (in_array(false, $rcs)) {
|
if ($file == '.' or $file == '..')
|
||||||
return false;
|
continue;
|
||||||
}
|
|
||||||
|
if (@ is_dir($dir . DIRECTORY_SEPARATOR . $file))
|
||||||
|
$stack[] = $dir . DIRECTORY_SEPARATOR . $file;
|
||||||
|
else if (@ is_file($dir . DIRECTORY_SEPARATOR . $file))
|
||||||
|
@ unlink($dir . DIRECTORY_SEPARATOR . $file);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
if (end($stack) == $dir) {
|
||||||
|
@ rmdir($dir);
|
||||||
|
array_pop($stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function replace($id, $data, $group = 'default', $expire = '') {
|
function replace($id, $data, $group = 'default', $expire = '') {
|
||||||
|
|
|
@ -89,67 +89,4 @@ if (!function_exists('array_change_key_case')) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Added in PHP 4.3.0 */
|
|
||||||
|
|
||||||
if( !function_exists('glob') ):
|
|
||||||
function glob($pattern) {
|
|
||||||
// get pathname (everything up until the last / or \)
|
|
||||||
$path=$output=null;
|
|
||||||
// if(PHP_OS=='WIN32')
|
|
||||||
// $slash='\\';
|
|
||||||
// else
|
|
||||||
// $slash='/';
|
|
||||||
$slash = '/';
|
|
||||||
$lastpos=strrpos($pattern,$slash);
|
|
||||||
if(!($lastpos===false)) {
|
|
||||||
$path=substr($pattern,0,$lastpos); #negative length means take from the right
|
|
||||||
$pattern=substr($pattern,$lastpos+1);
|
|
||||||
} else {
|
|
||||||
//no dir info, use current dir
|
|
||||||
$path=getcwd();
|
|
||||||
}
|
|
||||||
$handle=@ opendir($path);
|
|
||||||
if($handle===false)
|
|
||||||
return false;
|
|
||||||
while($dir=readdir($handle)) {
|
|
||||||
if ( '.' == $dir || '..' == $dir )
|
|
||||||
continue;
|
|
||||||
if (pattern_match($pattern,$dir))
|
|
||||||
$output[]=$path . '/' . $dir;
|
|
||||||
}
|
|
||||||
closedir($handle);
|
|
||||||
if(is_array($output))
|
|
||||||
return $output;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function pattern_match($pattern,$string) {
|
|
||||||
// basically prepare a regular expression
|
|
||||||
$out=null;
|
|
||||||
$chunks=explode(';',$pattern);
|
|
||||||
foreach($chunks as $pattern) {
|
|
||||||
$escape=array('$','^','.','{','}','(',')','[',']','|');
|
|
||||||
while(strpos($pattern,'**')!==false)
|
|
||||||
$pattern=str_replace('**','*',$pattern);
|
|
||||||
foreach($escape as $probe)
|
|
||||||
$pattern=str_replace($probe,"\\$probe",$pattern);
|
|
||||||
|
|
||||||
$pattern=str_replace('?*','*',
|
|
||||||
str_replace('*?','*',
|
|
||||||
str_replace('*',".*",
|
|
||||||
str_replace('?','.{1,1}',$pattern))));
|
|
||||||
$out[]=$pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count($out)==1)
|
|
||||||
return(eregi("^$out[0]$",$string));
|
|
||||||
else
|
|
||||||
foreach($out as $tester)
|
|
||||||
if(eregi("^$tester$",$string))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
endif;
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue