Browse Source

Unbind the filter Closure from ArchivableFilesFinder to allow the object
to be garbage collected correctly, and the folder closed.

Fixes https://github.com/composer/satis/issues/64 for PHP 5.4

Peter Smith 11 years ago
parent
commit
8a7e2a3c00
1 changed files with 20 additions and 13 deletions
  1. 20 13
      src/Composer/Package/Archiver/ArchivableFilesFinder.php

+ 20 - 13
src/Composer/Package/Archiver/ArchivableFilesFinder.php

@@ -52,21 +52,28 @@ class ArchivableFilesFinder extends \FilterIterator
         );
         );
 
 
         $this->finder = new Finder\Finder();
         $this->finder = new Finder\Finder();
+
+        $filter = function (\SplFileInfo $file) use ($sources, $filters, $fs) {
+            $relativePath = preg_replace(
+                '#^'.preg_quote($sources, '#').'#',
+                '',
+                $fs->normalizePath($file->getRealPath())
+            );
+
+            $exclude = false;
+            foreach ($filters as $filter) {
+                $exclude = $filter->filter($relativePath, $exclude);
+            }
+            return !$exclude;
+        };
+
+        if (method_exists($filter, 'bindTo')) {
+            $filter = $filter->bindTo(null);
+        }
+
         $this->finder
         $this->finder
             ->in($sources)
             ->in($sources)
-            ->filter(function (\SplFileInfo $file) use ($sources, $filters, $fs) {
-                $relativePath = preg_replace(
-                    '#^'.preg_quote($sources, '#').'#',
-                    '',
-                    $fs->normalizePath($file->getRealPath())
-                );
-
-                $exclude = false;
-                foreach ($filters as $filter) {
-                    $exclude = $filter->filter($relativePath, $exclude);
-                }
-                return !$exclude;
-            })
+            ->filter($filter)
             ->ignoreVCS(true)
             ->ignoreVCS(true)
             ->ignoreDotFiles(false);
             ->ignoreDotFiles(false);