Composer\Satis\Builder\PackagesBuilder::pruneIncludeDirectories PHP Method

pruneIncludeDirectories() private method

Remove all files matching the includeUrl pattern next to just created include jsons
    private function pruneIncludeDirectories()
    {
        $this->output->writeln('<info>Pruning include directories</info>');
        $paths = [];
        while ($this->writtenIncludeJsons) {
            list($hash, $includesUrl) = array_shift($this->writtenIncludeJsons);
            $path = $this->outputDir . '/' . ltrim($includesUrl, '/');
            $dirname = dirname($path);
            $basename = basename($path);
            if (strpos($dirname, '%hash%') !== false) {
                throw new \RuntimeException('Refusing to prune when %hash% is in dirname');
            }
            $pattern = '#^' . str_replace('%hash%', '([0-9a-zA-Z]{' . strlen($hash) . '})', preg_quote($basename, '#')) . '$#';
            $paths[$dirname][] = [$pattern, $hash];
        }
        foreach ($paths as $dirname => $entries) {
            foreach (new \DirectoryIterator($dirname) as $file) {
                foreach ($entries as $entry) {
                    list($pattern, $hash) = $entry;
                    if (preg_match($pattern, $file->getFilename(), $matches) && $matches[1] !== $hash) {
                        unlink($file->getPathname());
                        $this->output->writeln('<comment>Deleted ' . $file->getPathname() . '</comment>');
                    }
                }
            }
        }
    }