@@ -223,6 +223,8 @@ public function clear($check) {
223
223
if (!$ this ->_init ) {
224
224
return false ;
225
225
}
226
+ $ this ->_File = null ;
227
+
226
228
$ threshold = $ now = false ;
227
229
if ($ check ) {
228
230
$ now = time ();
@@ -233,11 +235,17 @@ public function clear($check) {
233
235
234
236
$ directory = new RecursiveDirectoryIterator ($ this ->settings ['path ' ]);
235
237
$ contents = new RecursiveIteratorIterator ($ directory , RecursiveIteratorIterator::SELF_FIRST );
238
+ $ cleared = array ();
236
239
foreach ($ contents as $ path ) {
237
240
if ($ path ->isFile ()) {
238
241
continue ;
239
242
}
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
+ }
241
249
}
242
250
return true ;
243
251
}
@@ -263,7 +271,7 @@ protected function _clearDirectory($path, $now, $threshold) {
263
271
continue ;
264
272
}
265
273
$ filePath = $ path . $ entry ;
266
- if (is_dir ($ filePath )) {
274
+ if (! file_exists ( $ filePath ) || is_dir ($ filePath )) {
267
275
continue ;
268
276
}
269
277
$ file = new SplFileObject ($ path . $ entry , 'r ' );
@@ -282,7 +290,7 @@ protected function _clearDirectory($path, $now, $threshold) {
282
290
}
283
291
if ($ file ->isFile ()) {
284
292
$ _path = $ file ->getRealPath ();
285
- unset( $ file) ;
293
+ $ file = null ;
286
294
unlink ($ _path );
287
295
}
288
296
}
@@ -390,6 +398,7 @@ public function key($key) {
390
398
* @return boolean success
391
399
*/
392
400
public function clearGroup ($ group ) {
401
+ $ this ->_File = null ;
393
402
$ directoryIterator = new RecursiveDirectoryIterator ($ this ->settings ['path ' ]);
394
403
$ contents = new RecursiveIteratorIterator ($ directoryIterator , RecursiveIteratorIterator::CHILD_FIRST );
395
404
foreach ($ contents as $ object ) {
@@ -399,7 +408,6 @@ public function clearGroup($group) {
399
408
unlink ($ object ->getPathName ());
400
409
}
401
410
}
402
- $ this ->_File = null ;
403
411
return true ;
404
412
}
405
413
}
0 commit comments