Skip to content
Permalink
Browse files

Fixing some errors related to unlink() on windows

  • Loading branch information...
hiromi2424
hiromi2424 committed Aug 9, 2013
1 parent dc381dd commit 29314e0fcc94c36b03f082a7c83ad5707acff31d
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/Cake/Cache/Engine/FileEngine.php
@@ -223,6 +223,8 @@ public function clear($check) {
if (!$this->_init) {
return false;
}
$this->_File = null;
$threshold = $now = false;
if ($check) {
$now = time();
@@ -233,11 +235,17 @@ public function clear($check) {
$directory = new RecursiveDirectoryIterator($this->settings['path']);
$contents = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
$cleared = array();
foreach ($contents as $path) {
if ($path->isFile()) {
continue;
}
$this->_clearDirectory($path->getRealPath() . DS, $now, $threshold);
$path = $path->getRealPath() . DS;
if (!in_array($path, $cleared)) {
$this->_clearDirectory($path, $now, $threshold);
$cleared[] = $path;
}
}
return true;
}
@@ -263,7 +271,7 @@ protected function _clearDirectory($path, $now, $threshold) {
continue;
}
$filePath = $path . $entry;
if (is_dir($filePath)) {
if (!file_exists($filePath) || is_dir($filePath)) {
continue;
}
$file = new SplFileObject($path . $entry, 'r');
@@ -282,7 +290,7 @@ protected function _clearDirectory($path, $now, $threshold) {
}
if ($file->isFile()) {
$_path = $file->getRealPath();
unset($file);
$file = null;
unlink($_path);
}
}
@@ -390,6 +398,7 @@ public function key($key) {
* @return boolean success
*/
public function clearGroup($group) {
$this->_File = null;
$directoryIterator = new RecursiveDirectoryIterator($this->settings['path']);
$contents = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($contents as $object) {
@@ -399,7 +408,6 @@ public function clearGroup($group) {
unlink($object->getPathName());
}
}
$this->_File = null;
return true;
}
}

0 comments on commit 29314e0

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.