Skip to content

Commit 29314e0

Browse files
author
hiromi2424
committed
Fixing some errors related to unlink() on windows
1 parent dc381dd commit 29314e0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/Cake/Cache/Engine/FileEngine.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ public function clear($check) {
223223
if (!$this->_init) {
224224
return false;
225225
}
226+
$this->_File = null;
227+
226228
$threshold = $now = false;
227229
if ($check) {
228230
$now = time();
@@ -233,11 +235,17 @@ public function clear($check) {
233235

234236
$directory = new RecursiveDirectoryIterator($this->settings['path']);
235237
$contents = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
238+
$cleared = array();
236239
foreach ($contents as $path) {
237240
if ($path->isFile()) {
238241
continue;
239242
}
240-
$this->_clearDirectory($path->getRealPath() . DS, $now, $threshold);
243+
244+
$path = $path->getRealPath() . DS;
245+
if (!in_array($path, $cleared)) {
246+
$this->_clearDirectory($path, $now, $threshold);
247+
$cleared[] = $path;
248+
}
241249
}
242250
return true;
243251
}
@@ -263,7 +271,7 @@ protected function _clearDirectory($path, $now, $threshold) {
263271
continue;
264272
}
265273
$filePath = $path . $entry;
266-
if (is_dir($filePath)) {
274+
if (!file_exists($filePath) || is_dir($filePath)) {
267275
continue;
268276
}
269277
$file = new SplFileObject($path . $entry, 'r');
@@ -282,7 +290,7 @@ protected function _clearDirectory($path, $now, $threshold) {
282290
}
283291
if ($file->isFile()) {
284292
$_path = $file->getRealPath();
285-
unset($file);
293+
$file = null;
286294
unlink($_path);
287295
}
288296
}
@@ -390,6 +398,7 @@ public function key($key) {
390398
* @return boolean success
391399
*/
392400
public function clearGroup($group) {
401+
$this->_File = null;
393402
$directoryIterator = new RecursiveDirectoryIterator($this->settings['path']);
394403
$contents = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::CHILD_FIRST);
395404
foreach ($contents as $object) {
@@ -399,7 +408,6 @@ public function clearGroup($group) {
399408
unlink($object->getPathName());
400409
}
401410
}
402-
$this->_File = null;
403411
return true;
404412
}
405413
}

0 commit comments

Comments
 (0)