Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Filesystem.php

function Filesystem::removeDirectoryPhp

Recursively delete directory using PHP iterators.

Uses a CHILD_FIRST RecursiveIteratorIterator to sort files before directories, creating a single non-recursive loop to delete files/directories in the correct order.

Return value

bool

4 calls to Filesystem::removeDirectoryPhp()
Filesystem::copyThenRemove in vendor/composer/composer/src/Composer/Util/Filesystem.php
Copy then delete is a non-atomic version of {@link rename}.
Filesystem::removeDirectory in vendor/composer/composer/src/Composer/Util/Filesystem.php
Recursively remove a directory
Filesystem::removeDirectoryAsync in vendor/composer/composer/src/Composer/Util/Filesystem.php
Recursively remove a directory asynchronously
Filesystem::removeEdgeCases in vendor/composer/composer/src/Composer/Util/Filesystem.php

File

vendor/composer/composer/src/Composer/Util/Filesystem.php, line 209

Class

Filesystem
@author Jordi Boggiano <j.boggiano@seld.be> @author Johannes M. Schmitt <schmittjoh@gmail.com>

Namespace

Composer\Util

Code

public function removeDirectoryPhp(string $directory) {
    $edgeCaseResult = $this->removeEdgeCases($directory, false);
    if ($edgeCaseResult !== null) {
        return $edgeCaseResult;
    }
    try {
        $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
    } catch (\UnexpectedValueException $e) {
        // re-try once after clearing the stat cache if it failed as it
        // sometimes fails without apparent reason, see https://github.com/composer/composer/issues/4009
        clearstatcache();
        usleep(100000);
        if (!is_dir($directory)) {
            return true;
        }
        $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
    }
    $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
    foreach ($ri as $file) {
        if ($file->isDir()) {
            $this->rmdir($file->getPathname());
        }
        else {
            $this->unlink($file->getPathname());
        }
    }
    // release locks on the directory, see https://github.com/composer/composer/issues/9945
    unset($ri, $it, $file);
    return $this->rmdir($directory);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal