[dev] Patches to VFS.

Chris Shepherd cshepherd at s21c.net
Mon Jan 20 16:11:11 PST 2003


If I can ever do something to botch something up, chances are, I'll do it.

Attached is a single patch for all the aforementioned files, please disregard 
the last series of patches.
 

-- 
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 21:13:08 -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/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 21:13:08 -0000
@@ -264,13 +264,15 @@
      * 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();
+	    $files = array();
         $path = isset($path) ? $this->_getNativePath($path) : $this->_getNativePath();
 
         if (!is_dir($path)) {
@@ -281,6 +283,25 @@
             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.
@@ -325,9 +346,28 @@
                 $file['type'] = '**dir';
                 $file['size'] = -1;
             } elseif (is_link($entry)) {
-                $file['perms'] = 'l' . $file['perms'];
+				$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 +391,26 @@
                     $file['perms'] = '?' . $file['perms'];
                 }
             }
+			// 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);
         }
 
-        /* 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';
-                    }
-                } else {
-                    $file['type'] = '**broken';
-                }
-                $files[$key] = $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 21:13:08 -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,26 @@
                     }
                 }
             }
+
+			
+			// 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);
         }
 
-        /* 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';
-                }
-                $files[$key] = $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 21:13:09 -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 21:13:09 -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,24 @@
             $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 21:13:09 -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'] = '-';
 
-            $files[$file['name']] = $file;
-        }
+			// 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 21:13:09 -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