From bd03981ea73ee7c73084cc88d0bf9d2f6962355a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 11 Jul 2024 09:29:55 +0200 Subject: [PATCH] Fix archive command crashing if a path cannot be realpathed on windows, fixes #11544 --- .../Package/Archiver/ArchivableFilesFinder.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Composer/Package/Archiver/ArchivableFilesFinder.php b/src/Composer/Package/Archiver/ArchivableFilesFinder.php index b2b6b87b8..2cf7ffc72 100644 --- a/src/Composer/Package/Archiver/ArchivableFilesFinder.php +++ b/src/Composer/Package/Archiver/ArchivableFilesFinder.php @@ -47,7 +47,11 @@ class ArchivableFilesFinder extends FilterIterator { $fs = new Filesystem(); - $sources = $fs->normalizePath(realpath($sources)); + $sourcesRealPath = realpath($sources); + if ($sourcesRealPath === false) { + throw new \RuntimeException('Could not realpath() the source directory "'.$sources.'"'); + } + $sources = $fs->normalizePath($sourcesRealPath); if ($ignoreFilters) { $filters = []; @@ -61,14 +65,18 @@ class ArchivableFilesFinder extends FilterIterator $this->finder = new Finder(); $filter = static function (\SplFileInfo $file) use ($sources, $filters, $fs): bool { - if ($file->isLink() && ($file->getRealPath() === false || strpos($file->getRealPath(), $sources) !== 0)) { + $realpath = $file->getRealPath(); + if ($realpath === false) { + return false; + } + if ($file->isLink() && strpos($realpath, $sources) !== 0) { return false; } $relativePath = Preg::replace( '#^'.preg_quote($sources, '#').'#', '', - $fs->normalizePath($file->getRealPath()) + $fs->normalizePath($realpath) ); $exclude = false; @@ -79,10 +87,6 @@ class ArchivableFilesFinder extends FilterIterator return !$exclude; }; - if (method_exists($filter, 'bindTo')) { - $filter = $filter->bindTo(null); - } - $this->finder ->in($sources) ->filter($filter)