[evolvis-commits] r16947: Merged from Evolvis: use PHP readdir() rather than forking ls

mirabilos at evolvis.org mirabilos at evolvis.org
Tue Mar 1 01:53:03 CET 2011


Author: mirabilos
Date: 2011-03-01 01:53:03 +0100 (Tue, 01 Mar 2011)
New Revision: 16947

Modified:
   trunk/gforge_base/evolvisforge-5.1/src/common/include/utils.php
Log:
Merged from Evolvis: use PHP readdir() rather than forking ls

Modified: trunk/gforge_base/evolvisforge-5.1/src/common/include/utils.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/include/utils.php	2011-03-01 00:50:17 UTC (rev 16946)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/include/utils.php	2011-03-01 00:53:03 UTC (rev 16947)
@@ -948,21 +948,22 @@
  *	@return	array	array of file names.
  */
 function &ls($dir,$filter=false) {
-	if (!is_dir ($dir)) {
-		$out = array () ;
-		return $out ;
-	}
-	exec('ls -c1 '.$dir,$out);
-	if ($filter) {
-		for ($i=0; $i<count($out); $i++) {
-			if (util_is_valid_filename($out[$i]) && is_file($dir.'/'.$out[$i])) {
-				$filtered[]=$out[$i];
+	$out = array();
+
+	if (is_dir($dir) && ($h = opendir($dir))) {
+		while (($f = readdir($h)) !== false) {
+			if ($f[0] == '.')
+				continue;
+			if ($filter) {
+				if (!util_is_valid_filename($f) ||
+				    !is_file($dir . "/" . $f))
+					continue;
 			}
+			$out[] = $f;
 		}
-		return $filtered;
-	} else {
-		return $out;
+		closedir($h);
 	}
+	return $out;
 }
 
 /**



More information about the evolvis-commits mailing list