]> granicus.if.org Git - php/commitdiff
Dont't stop if directory can't be openedbecause of user rights etc
authorMarcus Boerger <helly@php.net>
Wed, 19 Nov 2003 00:18:30 +0000 (00:18 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 19 Nov 2003 00:18:30 +0000 (00:18 +0000)
ext/spl/examples/cachingrecursiveiterator.inc
ext/spl/examples/directorytreeiterator.inc

index cb89fdb6d80872488cd0e17620edec793cf156c6..55acd1e1956af9400595e7fbcd897ef12ca8b809 100644 (file)
@@ -4,14 +4,28 @@ class CachingRecursiveIterator extends CachingIterator implements RecursiveItera
 {
        protected $hasChildren;
        protected $getChildren;
+       protected $catch_get_child_exceptions;
 
-       function __construct(RecursiveIterator $it) {
+       function __construct(RecursiveIterator $it, $catch_get_child_exceptions = false) {
+               $this->catch_get_child_exceptions = $catch_get_child_exceptions;
                parent::__construct($it);
        }
        
        function next() {
                if ($this->hasChildren = $this->it->hasChildren()) {
-                       $this->getChildren = new CachingRecursiveIterator($this->it->getChildren());
+                       try {
+                               //$this->getChildren = new CachingRecursiveIterator($this->it->getChildren(), $this->catch_get_child_exceptions);
+                               // workaround memleaks...
+                               $child = $this->it->getChildren();
+                               $this->getChildren = new CachingRecursiveIterator($child, $this->catch_get_child_exceptions);
+                       }
+                       catch(Exception $e) {
+                               if (!$this->catch_get_child_exceptions) {
+                                       throw $e;
+                               }
+                               $this->hasChildren = false;
+                               $this->getChildren = NULL;
+                       }
                } else {
                        $this->getChildren = NULL;
                }
index e7e297aca2585cebbd90e8815b1cb7b63a5d61bf..bd815b6821d93edb02df1e521974bc1c595ed854 100644 (file)
@@ -4,7 +4,7 @@ class DirectoryTreeIterator extends RecursiveIteratorIterator
 {
        function __construct($path)
        {
-               parent::__construct(new CachingRecursiveIterator(new RecursiveDirectoryIterator($path)), 1);
+               parent::__construct(new CachingRecursiveIterator(new RecursiveDirectoryIterator($path), true), 1);
        }
        
        function current()