private function emptyDirectory($path)
{
$errors = array();
$dir = new FilesystemIterator($path);
foreach ($dir as $file => $info) {
if ($info->isDir()) {
$this->verbose('<debug>Filesystem::recursiveRemoveDirectory() <comment>' . $file . '</comment></debug>');
if (!isset($fs)) {
$fs = new Filesystem();
}
if (!$fs->recursiveRemoveDirectory($file)) {
$errors[] = $file;
}
} else {
$this->verbose('<debug>unlink() <comment>' . $file . '</comment></debug>');
if (!unlink($file)) {
$errors[] = $file;
}
}
}
if (!$errors) {
return true;
}
$message = sprintf("Failed to empty directory %s, unable to remove:\n", var_export($path, true));
foreach ($errors as $error) {
$message .= sprintf(" - %s\n", var_export($error, true));
}
throw new RuntimeException($message);
}