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

Breadcrumb

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

function Filesystem::removeDirectoryAsync

Recursively remove a directory asynchronously

Uses the process component if proc_open is enabled on the PHP installation.

@phpstan-return PromiseInterface<bool>

Return value

PromiseInterface

Throws

\RuntimeException

File

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

Class

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

Namespace

Composer\Util

Code

public function removeDirectoryAsync(string $directory) {
    $edgeCaseResult = $this->removeEdgeCases($directory);
    if ($edgeCaseResult !== null) {
        return \React\Promise\resolve($edgeCaseResult);
    }
    if (Platform::isWindows()) {
        $cmd = [
            'rmdir',
            '/S',
            '/Q',
            Platform::realpath($directory),
        ];
    }
    else {
        $cmd = [
            'rm',
            '-rf',
            $directory,
        ];
    }
    $promise = $this->getProcess()
        ->executeAsync($cmd);
    return $promise->then(function ($process) use ($directory) {
        // clear stat cache because external processes aren't tracked by the php stat cache
        clearstatcache();
        if ($process->isSuccessful()) {
            if (!is_dir($directory)) {
                return \React\Promise\resolve(true);
            }
        }
        return \React\Promise\resolve($this->removeDirectoryPhp($directory));
    });
}

API Navigation

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