1
0
Fork 0

Fix archive command crashing if a path cannot be realpathed on windows, fixes #11544

pull/12046/head
Jordi Boggiano 2024-07-11 09:29:55 +02:00
parent 68f6498bd3
commit bd03981ea7
No known key found for this signature in database
1 changed files with 11 additions and 7 deletions

View File

@ -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)