src/Composer/Util/Filesystem.php
public function removeDirectory($directory)
    {
        if ($this->isSymlinkedDirectory($directory)) {
            return $this->unlinkSymlinkedDirectory($directory);
        }

        if ($this->isJunction($directory)) {
            return $this->removeJunction($directory);
        }

        if (is_link($directory)) {
            return unlink($directory);
        }

        if (!file_exists($directory) || !is_dir($directory)) {
            return true;
        }

        if (preg_match('{^(?:[a-z]:)?[/\\\\]+$}i', $directory)) {
            throw new \RuntimeException('Aborting an attempted deletion of '.$directory.', this was probably not intended, if it is a real use case please report it.');
        }

        if (!function_exists('proc_open')) {
            return $this->removeDirectoryPhp($directory);
        }

        if (Platform::isWindows()) {
            $cmd = sprintf('rmdir /S /Q %s', ProcessExecutor::escape(realpath($directory)));
        } else {
            $cmd = sprintf('rm -rf %s', ProcessExecutor::escape($directory));
        }

        $result = $this->getProcess()->execute($cmd, $output) === 0;

        // clear stat cache because external processes aren't tracked by the php stat cache
        clearstatcache();

        if ($result && !file_exists($directory)) {
            return true;
        }

        return $this->removeDirectoryPhp($directory);
    }
public function removeDirectory($directory)
    {
        if ($this->isSymlinkedDirectory($directory)) {
            return $this->unlinkSymlinkedDirectory($directory);
        }

        if ($this->isJunction($directory)) {
            return $this->removeJunction($directory);
        }

        if (is_link($directory)) {
            return unlink($directory);
        }

        if (!file_exists($directory) || !is_dir($directory)) {
            return true;
        }

        if (preg_match('{^(?:[a-z]:)?[/\\\\]+$}i', $directory)) {
            throw new \RuntimeException('Aborting an attempted deletion of '.$directory.', this was probably not intended, if it is a real use case please report it.');
        }

        if (!function_exists('proc_open')) {
            return $this->removeDirectoryPhp($directory);
        }

        if (Platform::isWindows()) {
            $cmd = sprintf('rmdir /S /Q %s', ProcessExecutor::escape(realpath($directory)));
        } else {
            $cmd = sprintf('rm -rf %s', ProcessExecutor::escape($directory));
        }

        $result = $this->getProcess()->execute($cmd, $output) === 0;

        // clear stat cache because external processes aren't tracked by the php stat cache
        clearstatcache();

        if ($result && !file_exists($directory)) {
            return true;
        }

        return $this->removeDirectoryPhp($directory);
    }
public function removeDirectory ( $ directory ) { if ( $ this -> isSymlinkedDirectory ( $ directory ) ) { return $ this -> unlinkSymlinkedDirectory ( $ directory ) ; } if ( $ this -> isJunction ( $ directory ) ) { return $ this -> removeJunction ( $ directory ) ; } if ( is_link ( $ directory ) ) { return unlink ( $ directory ) ; } if ( ! file_exists ( $ directory ) || ! is_dir ( $ directory ) ) { return true ; } if ( preg_match ( '{^(?:[a-z]:)?[/\\\\]+$}i' , $ directory ) ) { throw new \ RuntimeException ( 'Aborting an attempted deletion of ' . $ directory . ', this was probably not intended, if it is a real use case please report it.' ) ; } if ( ! function_exists ( 'proc_open' ) ) { return $ this -> removeDirectoryPhp ( $ directory ) ; } if ( Platform :: isWindows ( ) ) { $ cmd = sprintf ( 'rmdir /S /Q %s' , ProcessExecutor :: escape ( realpath ( $ directory ) ) ) ; } else { $ cmd = sprintf ( 'rm -rf %s' , ProcessExecutor :: escape ( $ directory ) ) ; } $ result = $ this -> getProcess ( ) -> execute ( $ cmd , $ output ) === 0 ; // clear stat cache because external processes aren't tracked by the php stat cache clearstatcache ( ) ; if ( $ result && ! file_exists ( $ directory ) ) { return true ; } return $ this -> removeDirectoryPhp ( $ directory ) ; }
Recursively remove a directory

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

@param  string            $directory
@throws \RuntimeException
@return bool
Recursively remove a directory