[dev] Streamlined VFS patch.
Chris Shepherd
cshepherd at s21c.net
Thu Jan 23 10:19:28 PST 2003
Hi all,
As chuck mentioned earlier, the code needed tidying up, I just didn't have
the time to do it earlier, so I pasted carbon copies into each file.
Attached is the streamlined version which now uses a function defined in the
parent VFS class, as it should be.
Comments/Critiques welcome.
--
Chris Shepherd
Network Administrator
-------------------------------------------------
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.33
diff -u -r1.33 VFS.php
--- horde/lib/VFS.php 23 Jan 2003 04:04:47 -0000 1.33
+++ horde/lib/VFS.php 23 Jan 2003 15:18:56 -0000
@@ -281,6 +281,46 @@
}
/**
+ * Returns a boolean indicating whether or not the filename matches any filter
+ * element.
+ *
+ * @param mixed $filter String/Hash to build the regular expression from.
+ * @param string $filename String containing the filename to match.
+ *
+ * @return boolean True on match, False on no match.
+ */
+ function _filterMatch($filter, $filename)
+ {
+ $namefilter = null;
+ // build a regexp based on $filter
+ if ($filter !== null) {
+ $namefilter = '/';
+ if (is_array($filter)) {
+ $once = false;
+ foreach ($filter as $item) {
+ if ($once !== true) {
+ $namefilter .= '(';
+ $once = true;
+ } else {
+ $namefilter .= '|(';
+ }
+ $namefilter .= $item . ')';
+ }
+ } else {
+ $namefilter .= '(' . $filter . ')';
+ }
+ $namefilter .= '/';
+ }
+
+ $match = false;
+ if ($namefilter !== null) {
+ $match = preg_match($namefilter, $filename);
+ }
+
+ return $match;
+ }
+
+ /**
* Changes permissions for an Item on the VFS.
*
* @param string $path Holds the path of directory of the Item.
Index: horde/lib/VFS/file.php
===================================================================
RCS file: /repository/horde/lib/VFS/file.php,v
retrieving revision 1.34
diff -u -r1.34 file.php
--- horde/lib/VFS/file.php 23 Jan 2003 04:04:48 -0000 1.34
+++ horde/lib/VFS/file.php 23 Jan 2003 15:18:56 -0000
@@ -283,26 +283,6 @@
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.
@@ -392,14 +372,10 @@
$file['perms'] = '?' . $file['perms'];
}
}
- // filtering
- if ($filter !== null) {
- if (isset($namefilter)) {
- if (preg_match($namefilter, $file['name'])) {
- unset($file);
- continue;
- }
- }
+ // filtering
+ if ($this->_filterMatch($filter, $file['name'])) {
+ unset($file);
+ continue;
}
if ($dironly && $file['type'] !== '**dir') {
unset($file);
Index: horde/lib/VFS/ftp.php
===================================================================
RCS file: /repository/horde/lib/VFS/ftp.php,v
retrieving revision 1.35
diff -u -r1.35 ftp.php
--- horde/lib/VFS/ftp.php 23 Jan 2003 04:04:48 -0000 1.35
+++ horde/lib/VFS/ftp.php 23 Jan 2003 15:18:57 -0000
@@ -293,26 +293,6 @@
$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 . '.');
@@ -413,14 +393,10 @@
}
}
- // filtering
- if ($filter !== null) {
- if (isset($namefilter)) {
- if (preg_match($namefilter, $file['name'])) {
- unset($file);
- continue;
- }
- }
+ // filtering
+ if ($this->_filterMatch($filter, $file['name'])) {
+ unset($file);
+ continue;
}
if ($dironly && $file['type'] !== '**dir') {
unset($file);
Index: horde/lib/VFS/musql.php
===================================================================
RCS file: /repository/horde/lib/VFS/musql.php,v
retrieving revision 1.13
diff -u -r1.13 musql.php
--- horde/lib/VFS/musql.php 23 Jan 2003 04:04:48 -0000 1.13
+++ horde/lib/VFS/musql.php 23 Jan 2003 15:18:57 -0000
@@ -342,26 +342,6 @@
$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'],
@@ -407,14 +387,10 @@
$file['perms'] .= '-';
$file['group'] = '-';
- // filtering
- if ($filter !== null) {
- if (isset($namefilter)) {
- if (preg_match($namefilter, $file['name'])) {
- unset($file);
- continue;
- }
- }
+ // filtering
+ if ($this->_filterMatch($filter, $file['name'])) {
+ unset($file);
+ continue;
}
if ($dironly && $file['type'] !== '**dir') {
unset($file);
Index: horde/lib/VFS/sql.php
===================================================================
RCS file: /repository/horde/lib/VFS/sql.php,v
retrieving revision 1.40
diff -u -r1.40 sql.php
--- horde/lib/VFS/sql.php 23 Jan 2003 04:04:48 -0000 1.40
+++ horde/lib/VFS/sql.php 23 Jan 2003 15:18:57 -0000
@@ -397,26 +397,6 @@
$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';
@@ -460,14 +440,10 @@
$file['perms'] = '-';
$file['group'] = '-';
- // filtering
- if ($filter !== null) {
- if (isset($namefilter)) {
- if (preg_match($namefilter, $file['name'])) {
- unset($file);
- continue;
- }
- }
+ // filtering
+ if ($this->_filterMatch($filter, $file['name'])) {
+ unset($file);
+ continue;
}
if ($dironly && $file['type'] !== '**dir') {
unset($file);
Index: horde/lib/VFS/sql_file.php
===================================================================
RCS file: /repository/horde/lib/VFS/sql_file.php,v
retrieving revision 1.16
diff -u -r1.16 sql_file.php
--- horde/lib/VFS/sql_file.php 23 Jan 2003 04:04:48 -0000 1.16
+++ horde/lib/VFS/sql_file.php 23 Jan 2003 15:18:57 -0000
@@ -544,26 +544,6 @@
$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'],
@@ -600,14 +580,10 @@
$file['perms'] = '-';
$file['group'] = '-';
- // filtering
- if ($filter !== null) {
- if (isset($namefilter)) {
- if (preg_match($namefilter, $file['name'])) {
- unset($file);
- continue;
- }
- }
+ // filtering
+ if ($this->_filterMatch($filter, $file['name'])) {
+ unset($file);
+ continue;
}
if ($dironly && $file['type'] !== '**dir') {
unset($file);
More information about the dev
mailing list