function Composer::deleteRecursive

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Composer/Composer.php \Drupal\Core\Composer\Composer::deleteRecursive()

Helper method to remove directories and the files they contain.

Parameters

string $path: The directory or file to remove. It must exist.

Return value

bool TRUE on success or FALSE on failure.

1 call to Composer::deleteRecursive()
Composer::vendorTestCodeCleanup in core/lib/Drupal/Core/Composer/Composer.php
Remove possibly problematic test files from vendored projects.

File

core/lib/Drupal/Core/Composer/Composer.php, line 259

Class

Composer
Provides static functions for composer script events.

Namespace

Drupal\Core\Composer

Code

protected static function deleteRecursive($path) {
    if (is_file($path) || is_link($path)) {
        return unlink($path);
    }
    $success = TRUE;
    $dir = dir($path);
    while (($entry = $dir->read()) !== FALSE) {
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        $entry_path = $path . '/' . $entry;
        $success = static::deleteRecursive($entry_path) && $success;
    }
    $dir->close();
    return rmdir($path) && $success;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.