[dev] Patches to VFS.

Chris Shepherd cshepherd at s21c.net
Mon Jan 20 17:21:48 PST 2003


Here's the fixed patch for VFS.

-- 
Chris Shepherd

-------------------------------------------------
This email may contain confidential information. Use of any such information
is strictly prohibited without express written consent of the sender
-------------- next part --------------
Index: horde/lib/VFS.php
===================================================================
RCS file: /repository/horde/lib/VFS.php,v
retrieving revision 1.32
diff -u -r1.32 VFS.php
--- horde/lib/VFS.php	6 Jan 2003 22:02:59 -0000	1.32
+++ horde/lib/VFS.php	20 Jan 2003 22:07:31 -0000
@@ -268,12 +268,14 @@
      * Returns a file list of the directory passed in.
      *
      * @param string  $path     The path of the directory.
+     * @param mixed   $filter	(optional) String/hash to filter file/dirname on.
      * @param boolean $dotfiles (optional) Show dotfiles?
+     * @param boolean $dironly	(optional) Show only directories?
      *
      * @return mixed  File list (array) on success or a PEAR_Error
      *                object on failure.
      */
-    function listFolder($path, $dotfiles = true)
+    function listFolder($path, $filter = null, $dotfiles = true, $dironly = false)
     {
         return PEAR::raiseError('not supported');
     }
Index: horde/lib/VFS/Browser.php
===================================================================
RCS file: /repository/horde/lib/VFS/Browser.php,v
retrieving revision 1.3
diff -u -r1.3 Browser.php
--- horde/lib/VFS/Browser.php	3 Jan 2003 15:20:20 -0000	1.3
+++ horde/lib/VFS/Browser.php	20 Jan 2003 22:07:31 -0000
@@ -41,4 +41,9 @@
         $this->_vfs = &$vfs;
     }
 
+	function getUI($path, $dotfiles = false, $dironly = false) {
+		$this->_vfs->listFolder($path, $dotfiles, $dironly)
+
+	}
+
 }
Index: horde/lib/VFS/file.php
===================================================================
RCS file: /repository/horde/lib/VFS/file.php,v
retrieving revision 1.33
diff -u -r1.33 file.php
--- horde/lib/VFS/file.php	12 Jan 2003 15:24:51 -0000	1.33
+++ horde/lib/VFS/file.php	20 Jan 2003 22:07:31 -0000
@@ -264,11 +264,13 @@
      * Return a list of the contents of a folder.
      *
      * @param string  $path     Holds the path of the directory.
+     * @param mixed   $filter	(optional) String/hash to filter file/dirname on.
      * @param boolean $dotfiles (optional) Show dotfiles?
-     *
+     * @param boolean $dironly	(optional) Show only directories?
+	 *
      * @return mixed  File list on success or false on failure.
      */
-    function listFolder($path, $dotfiles = true)
+    function listFolder($path, $filter = null, $dotfiles = true, $dironly = false)
     {
         $files = array();
         $path = isset($path) ? $this->_getNativePath($path) : $this->_getNativePath();
@@ -281,6 +283,26 @@
             return PEAR::raiseError('Unable to access VFS directory.');
         }
 
+        // build a regexp based on $filter
+        if ($filter !== null) {
+            $namefilter = '/';
+            if (is_array($filter['name'])) {
+                $once = false;
+                foreach ($filter as $item) {
+                    if ($once !== true) {
+                        $namefilter .= '(';
+                        $once = true;
+                    } else {
+                        $namefilter .= '|(';
+                    }
+                    $namefilter .= $item . ')';	
+                }
+            } else {
+                $namefilter .= '(' . $filter['name'] . ')';
+            }
+            $namefilter .= '/';
+        }
+
         $handle = opendir($path);
         while (($entry = readdir($handle)) !== false) {
             // Filter out '.' and '..' entries.
@@ -328,6 +350,25 @@
                 $file['perms'] = 'l' . $file['perms'];
                 $file['type'] = '**sym';
                 $file['link'] = readlink($entry);
+                if (file_exists($file['link'])) {
+                    if (is_dir($file['link'])) {
+                        $file['type'] = '**dir';
+                        $file['size'] = -1;
+                    } elseif (is_link($file['link'])) {
+                        $file['type'] = '**sym';
+                    } elseif (is_file($file['link'])) {
+                        $ext = explode('.', $file['link']);
+                        if (count($ext) == 1 || (substr($file['name'], 0, 1) === '.' && count($ext) == 2)) {
+                            $file['type'] = '**none';
+                        } else {
+                            $file['type'] = Horde_VFS::strtolower($ext[count($ext)-1]);
+                        }
+                    } else {
+                        $file['type'] = '**none';
+                    }
+                } else {
+                    $file['type'] = '**broken';
+                }
             } elseif (is_file($entry)) {
                 $file['perms'] = '-' . $file['perms'];
                 $ext = explode('.', $entry);
@@ -351,40 +392,25 @@
                     $file['perms'] = '?' . $file['perms'];
                 }
             }
-
-            $files[$file['name']] = $file;
-            unset($file);
-        }
-
-        /* Figure out the real type of symlinks. */
-        foreach ($files as $key => $file) {
-            if ($file['type'] === '**sym') {
-                if (file_exists($file['link'])) {
-                    if (is_dir($file['link'])) {
-                        $file['type'] = '**dir';
-                        $file['size'] = -1;
-                    } elseif (is_link($file['link'])) {
-                        $file['type'] = '**sym';
-                    } elseif (is_file($file['link'])) {
-                        $ext = explode('.', $file['link']);
-                        if (count($ext) == 1 || (substr($file['name'], 0, 1) === '.' && count($ext) == 2)) {
-                            $file['type'] = '**none';
-                        } else {
-                            $file['type'] = Horde_VFS::strtolower($ext[count($ext)-1]);
-                        }
-                    } else {
-                        $file['type'] = '**none';
+            // filtering
+            if ($filter !== null) {
+                if (isset($namefilter)) {
+                    if (preg_match($namefilter, $file['name'])) {
+                        unset($file);
+                        continue;	
                     }
-                } else {
-                    $file['type'] = '**broken';
                 }
-                $files[$key] = $file;
             }
+            if ($dironly && $file['type'] !== '**dir') {
+                unset($file);
+                continue;
+            }				
+            $files[$file['name']] = $file;
+            unset($file);
         }
 
         return $files;
     }
-
     /**
      * Return Unix style perms.
      *
@@ -513,5 +539,4 @@
             return PEAR::raiseError(_("Unable to read the vfsroot directory."));
         }
     }
-
 }
Index: horde/lib/VFS/ftp.php
===================================================================
RCS file: /repository/horde/lib/VFS/ftp.php,v
retrieving revision 1.34
diff -u -r1.34 ftp.php
--- horde/lib/VFS/ftp.php	12 Jan 2003 15:24:51 -0000	1.34
+++ horde/lib/VFS/ftp.php	20 Jan 2003 22:07:31 -0000
@@ -277,11 +277,13 @@
      * Returns an unsorted file list.
      *
      * @param string  $path     The path of the directory to get the file list for.
+     * @param mixed   $filter   (optional) hash of items to filter based on filename.
      * @param boolean $dotfiles (optional) Show dotfiles?
+     * @param boolean $dironly  (optional) Show directories only?
      *
      * @return mixed  File list on success or a PEAR_Error object on failure.
      */
-    function listFolder($path = '', $dotfiles = true)
+    function listFolder($path = '', $filter = null $dotfiles = true, $dironly = false)
     {
         $conn = $this->_connect();
         if (is_a($conn, 'PEAR_Error')) {
@@ -291,6 +293,26 @@
         $files = array();
         $type = @ftp_systype($this->_stream);
 
+        // build a regexp based on $filter
+        if ($filter !== null) {
+            $namefilter = '/';
+            if (is_array($filter['name'])) {
+                $once = false;
+                foreach ($filter as $item) {
+                    if ($once !== true) {
+                        $namefilter .= '(';
+                        $once = true;
+                    } else {
+                        $namefilter .= '|(';
+                    }
+                    $namefilter .= $item . ')';	
+                }
+            } else {
+                $namefilter .= '(' . $filter['name'] . ')';
+            }
+            $namefilter .= '/';
+        }
+
         if (!empty($path)) {
             if (!@ftp_chdir($this->_stream, $path)) {
                 return PEAR::raiseError('Unable to open ' . $path . '.');
@@ -390,20 +412,25 @@
                     }
                 }
             }
-            $files[$file['name']] = $file;
-        }
 
-        /* Figure out the real type of symlinks. */
-        foreach ($files as $key => $file) {
-            if ($file['type'] === '**sym') {
-                if (isset($files[$file['link']]) && ($file['name'] !== $file['link'])) {
-                    $file['type'] = $files[$file['link']]['type'];
-                } else {
-                    $file['type'] = '**broken';
+            // filtering
+            if ($filter !== null) {
+                if (isset($namefilter)) {
+                    if (preg_match($namefilter, $file['name'])) {
+                        unset($file);
+                        continue;	
+                    }
                 }
-                $files[$key] = $file;
             }
+            if ($dironly && $file['type'] !== '**dir') {
+                unset($file);
+                continue;
+            }				
+
+            $files[$file['name']] = $file;
+            unset($file);
         }
+
         return $files;
     }
 
Index: horde/lib/VFS/musql.php
===================================================================
RCS file: /repository/horde/lib/VFS/musql.php,v
retrieving revision 1.12
diff -u -r1.12 musql.php
--- horde/lib/VFS/musql.php	13 Jan 2003 23:21:12 -0000	1.12
+++ horde/lib/VFS/musql.php	20 Jan 2003 22:07:31 -0000
@@ -326,11 +326,13 @@
      * Return a list of the contents of a folder.
      *
      * @param string  $path     Holds the path of the directory.
+	 * @param mixed   $filter	(optional) String/hash to filter file/dirname on.
      * @param boolean $dotfiles (optional) Show dotfiles?
+	 * @param boolean $dironly	(optional) Show only directories?
      *
      * @return mixed  File list on success or false on failure.
      */
-    function listFolder($path, $dotfiles = true)
+    function listFolder($path, $filter = null, $dotfiles = true, $dironly = false)
     {
         $conn = $this->_connect();
         if (is_a($conn, 'PEAR_Error')) {
@@ -340,6 +342,26 @@
         $files = array();
         $fileList = array();
 
+        // build a regexp based on $filter
+        if ($filter !== null) {
+            $namefilter = '/';
+            if (is_array($filter['name'])) {
+                $once = false;
+                foreach ($filter as $item) {
+                    if ($once !== true) {
+                        $namefilter .= '(';
+                        $once = true;
+                    } else {
+                        $namefilter .= '|(';
+                    }
+                    $namefilter .= $item . ')';	
+                }
+            } else {
+                $namefilter .= '(' . $filter['name'] . ')';
+            }
+            $namefilter .= '/';
+        }
+
         $fileList = $this->_db->getAll(sprintf('SELECT vfs_name, vfs_type, vfs_modified, vfs_owner, vfs_perms, vfs_data FROM %s
                                                WHERE vfs_path = %s AND (vfs_owner = %s or vfs_perms && %s)',
                                                $this->_params['table'],
@@ -385,7 +407,22 @@
             $file['perms'] .= '-';
             $file['group'] = '-';
 
+            // filtering
+            if ($filter !== null) {
+                if (isset($namefilter)) {
+                    if (preg_match($namefilter, $file['name'])) {
+                        unset($file);
+                        continue;	
+                    }
+                }
+            }
+            if ($dironly && $file['type'] !== '**dir') {
+                unset($file);
+                continue;
+            }				
+
             $files[$file['name']] = $file;
+            unset($file);
         }
 
         return $files;
Index: horde/lib/VFS/sql.php
===================================================================
RCS file: /repository/horde/lib/VFS/sql.php,v
retrieving revision 1.39
diff -u -r1.39 sql.php
--- horde/lib/VFS/sql.php	13 Jan 2003 23:21:13 -0000	1.39
+++ horde/lib/VFS/sql.php	20 Jan 2003 22:07:31 -0000
@@ -381,11 +381,13 @@
      * Return a list of the contents of a folder.
      *
      * @param string  $path     Holds the path of the directory.
+     * @param mixed	  $filter	(optional) hash of items to filter based on filename.
      * @param boolean $dotfiles (optional) Show dotfiles?
+     * @param boolean $dironly  (optional) Show directories only?
      *
      * @return mixed  File list on success or false on failure.
      */
-    function listFolder($path, $dotfiles = true)
+    function listFolder($path, $filter = null, $dotfiles = true, $dironly = false)
     {
         $conn = $this->_connect();
         if (is_a($conn, 'PEAR_Error')) {
@@ -395,6 +397,26 @@
         $files = array();
         $fileList = array();
 
+        // build a regexp based on $filter
+        if ($filter !== null) {
+            $namefilter = '/';
+            if (is_array($filter['name'])) {
+                $once = false;
+                foreach ($filter as $item) {
+                    if ($once !== true) {
+                        $namefilter .= '(';
+                        $once = true;
+                    } else {
+                        $namefilter .= '|(';
+                    }
+                    $namefilter .= $item . ')';	
+                }
+            } else {
+                $namefilter .= '(' . $filter['name'] . ')';
+            }
+            $namefilter .= '/';
+        }
+
         // Fix for an ODD Oracle quirk.
         if (empty($path) && $this->_db->dbsyntax == 'oci8') {
             $where = 'vfs_path IS NULL';
@@ -438,8 +460,23 @@
             $file['perms'] = '-';
             $file['group'] = '-';
 
+            // filtering
+            if ($filter !== null) {
+                if (isset($namefilter)) {
+                    if (preg_match($namefilter, $file['name'])) {
+                        unset($file);
+                        continue;	
+                    }
+                }
+            }
+            if ($dironly && $file['type'] !== '**dir') {
+                unset($file);
+                continue;
+            }				
+
             $files[$file['name']] = $file;
-        }
+            unset($file);
+	    }
 
         return $files;
     }
Index: horde/lib/VFS/sql_file.php
===================================================================
RCS file: /repository/horde/lib/VFS/sql_file.php,v
retrieving revision 1.15
diff -u -r1.15 sql_file.php
--- horde/lib/VFS/sql_file.php	13 Jan 2003 23:21:14 -0000	1.15
+++ horde/lib/VFS/sql_file.php	20 Jan 2003 22:07:31 -0000
@@ -137,7 +137,7 @@
             return $conn;
         }
 
-        $fileCheck = $this->listFolder($dest, false);
+        $fileCheck = $this->listFolder($dest, null, false);
         foreach ($fileCheck as $file) {
             if ($file['name'] == $name) {
                 return PEAR::raiseError('Unable to move VFS file.');
@@ -167,7 +167,7 @@
             return $conn;
         }
 
-        $fileCheck = $this->listFolder($dest, false);
+        $fileCheck = $this->listFolder($dest, null, false);
         foreach ($fileCheck as $file) {
             if ($file['name'] == $name) {
                 return PEAR::raiseError('Unable to copy VFS file.');
@@ -528,11 +528,13 @@
      * Return a list of the contents of a folder.
      *
      * @param string  $path     Holds the path of the directory.
+     * @param mixed	  $filter	(optional) hash of items to filter based on filename.
      * @param boolean $dotfiles (optional) Show dotfiles?
+     * @param boolean $dironly  (optional) Show directories only?
      *
      * @return mixed  File list on success or false on failure.
      */
-    function listFolder($path, $dotfiles = true)
+    function listFolder($path, $filter = null, $dotfiles = true, $dironly = false)
     {
         $conn = $this->_connect();
         if (is_a($conn, 'PEAR_Error')) {
@@ -542,6 +544,26 @@
         $files = array();
         $fileList = array();
 
+        // build a regexp based on $filter
+        if ($filter !== null) {
+            $namefilter = '/';
+            if (is_array($filter['name'])) {
+                $once = false;
+                foreach ($filter as $item) {
+                    if ($once !== true) {
+                        $namefilter .= '(';
+                        $once = true;
+                    } else {
+                        $namefilter .= '|(';
+                    }
+                    $namefilter .= $item . ')';	
+                }
+            } else {
+                $namefilter .= '(' . $filter['name'] . ')';
+            }
+            $namefilter .= '/';
+        }
+
         $fileList = $this->_db->getAll(sprintf('SELECT vfs_name, vfs_type, vfs_modified, vfs_owner FROM %s
                                                WHERE vfs_path = %s',
                                                $this->_params['table'],
@@ -578,8 +600,23 @@
             $file['perms'] = '-';
             $file['group'] = '-';
 
+            // filtering
+            if ($filter !== null) {
+                if (isset($namefilter)) {
+                    if (preg_match($namefilter, $file['name'])) {
+                        unset($file);
+                        continue;	
+                    }
+                }
+            }
+            if ($dironly && $file['type'] !== '**dir') {
+                unset($file);
+                continue;
+            }				
+
             $files[$file['name']] = $file;
-        }
+            unset($file);
+		}
 
         return $files;
     }
Index: gollem/lib/Gollem.php
===================================================================
RCS file: /repository/gollem/lib/Gollem.php,v
retrieving revision 1.73
diff -u -r1.73 Gollem.php
--- gollem/lib/Gollem.php	9 Jan 2003 19:19:01 -0000	1.73
+++ gollem/lib/Gollem.php	20 Jan 2003 22:07:31 -0000
@@ -230,7 +230,7 @@
     {
         global $prefs;
 
-        $files = $GLOBALS['vfs']->listFolder($dir, $prefs->getValue('show_dotfiles'));
+        $files = $GLOBALS['vfs']->listFolder($dir, null, $prefs->getValue('show_dotfiles'));
         if (!is_a($files, 'PEAR_Error')) {
             switch ($GLOBALS['prefs']->getValue('sortby')) {
             case SORT_TYPE:


More information about the dev mailing list