protected function doCleanup($fileList, $dir, $path)
{
$errorList = [];
foreach (array_diff(@scandir($path . '/' . $dir) ?: [], ['..', '.']) as $file) {
$file = ($dir ? $dir . '/' : '') . $file;
$realPath = $path . '/' . $file;
if (is_dir($realPath)) {
array_merge($errorList, $this->doCleanup($fileList, $file, $path));
if (!in_array($file, $fileList)) {
@rmdir($realPath);
}
} else {
if (!in_array($file, $fileList) && !unlink($realPath)) {
$errorList[] = $file;
}
}
}
return $errorList;
}