[Pkg-owncloud-commits] [php-sabredav] 33/64: Replace `scandir` by `FilesystemIterator`.

David Prévot taffit at moszumanska.debian.org
Thu Dec 11 15:13:25 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to tag 2.2.0alpha1
in repository php-sabredav.

commit 8c81bc362d4d842d8dced9a3cf9067796328b984
Author: Ivan Enderlin <ivan.enderlin at hoa-project.net>
Date:   Fri Nov 21 13:30:54 2014 +0100

    Replace `scandir` by `FilesystemIterator`.
    
    1. `scandir` is slow compared to `FilesystemIterator`,
    2. `FilesystemIterator::SKIP_DOTS` is cross-FS,
    3. using an iterator is better than looping on a huge array (in the case
       where there is a lot of entries in the directory), it saves memory.
---
 lib/DAV/FS/Directory.php    | 11 ++++++++++-
 lib/DAV/FSExt/Directory.php | 16 +++++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/lib/DAV/FS/Directory.php b/lib/DAV/FS/Directory.php
index 3728eea..cf8d3a9 100644
--- a/lib/DAV/FS/Directory.php
+++ b/lib/DAV/FS/Directory.php
@@ -92,7 +92,16 @@ class Directory extends Node implements DAV\ICollection, DAV\IQuota {
     function getChildren() {
 
         $nodes = [];
-        foreach(scandir($this->path) as $node) if($node!='.' && $node!='..') $nodes[] = $this->getChild($node);
+        $iterator = new \FilesystemIterator(
+            $this->path,
+            \FilesystemIterator::CURRENT_AS_SELF
+          | \FilesystemIterator::SKIP_DOTS
+        );
+        foreach($iterator as $entry) {
+
+            $nodes[] = $this->getChild($entry->getFilename());
+
+        }
         return $nodes;
 
     }
diff --git a/lib/DAV/FSExt/Directory.php b/lib/DAV/FSExt/Directory.php
index 11871f0..a419cf6 100644
--- a/lib/DAV/FSExt/Directory.php
+++ b/lib/DAV/FSExt/Directory.php
@@ -116,7 +116,21 @@ class Directory extends Node implements DAV\ICollection, DAV\IQuota, DAV\IMoveTa
     function getChildren() {
 
         $nodes = [];
-        foreach(scandir($this->path) as $node) if($node!='.' && $node!='..' && $node!='.sabredav') $nodes[] = $this->getChild($node);
+        $iterator = new \FilesystemIterator(
+            $this->path,
+            \FilesystemIterator::CURRENT_AS_SELF
+          | \FilesystemIterator::SKIP_DOTS
+        );
+        foreach($iterator as $entry) {
+
+            $node = $entry->getFilename();
+
+            if($node === '.sabredav')
+                continue;
+
+            $nodes[] = $this->getChild($node);
+
+        }
         return $nodes;
 
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list