public static function rmdir($dir, $traverseSymlinks = false)
{
if (!file_exists($dir)) {
return true;
} elseif (!is_dir($dir)) {
throw new \RuntimeException('Given path is not a directory');
}
if (!is_link($dir) || $traverseSymlinks) {
foreach (scandir($dir) as $file) {
if ($file === '.' || $file === '..') {
continue;
}
$currentPath = $dir . '/' . $file;
if (is_dir($currentPath)) {
self::rmdir($currentPath, $traverseSymlinks);
} elseif (!unlink($currentPath)) {
// @codeCoverageIgnoreStart
throw new \RuntimeException('Unable to delete ' . $currentPath);
// @codeCoverageIgnoreEnd
}
}
}
// @codeCoverageIgnoreStart
// Windows treats removing directory symlinks identically to removing directories.
if (is_link($dir) && !defined('PHP_WINDOWS_VERSION_MAJOR')) {
if (!unlink($dir)) {
throw new \RuntimeException('Unable to delete ' . $dir);
}
} else {
if (!rmdir($dir)) {
throw new \RuntimeException('Unable to delete ' . $dir);
}
}
return true;
// @codeCoverageIgnoreEnd
}
public function setUp() { $this->_root = FS::clean(__DIR__ . '/test', '/'); FS::rmdir($this->_root); mkdir($this->_root, 0777, true); $this->_paths = array($this->_root, $this->_root . DS . 'folder'); }