From a16ca5a1c283f2410120b3fe771b0b7948c8acb7 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Wed, 19 Nov 2003 00:18:30 +0000 Subject: [PATCH] Dont't stop if directory can't be openedbecause of user rights etc --- ext/spl/examples/cachingrecursiveiterator.inc | 18 ++++++++++++++++-- ext/spl/examples/directorytreeiterator.inc | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ext/spl/examples/cachingrecursiveiterator.inc b/ext/spl/examples/cachingrecursiveiterator.inc index cb89fdb6d8..55acd1e195 100644 --- a/ext/spl/examples/cachingrecursiveiterator.inc +++ b/ext/spl/examples/cachingrecursiveiterator.inc @@ -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; } diff --git a/ext/spl/examples/directorytreeiterator.inc b/ext/spl/examples/directorytreeiterator.inc index e7e297aca2..bd815b6821 100644 --- a/ext/spl/examples/directorytreeiterator.inc +++ b/ext/spl/examples/directorytreeiterator.inc @@ -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() -- 2.50.1