--- destinations.filesource.inc.orig 2010-11-09 00:41:11.000000000 -0500 +++ destinations.filesource.inc 2010-11-17 10:14:05.494596600 -0500 @@ -89,7 +89,7 @@ "#multiple" => TRUE, "#title" => t("Exclude the following files or directories"), "#default_value" => $settings['exclude_filepaths'], - "#description" => t("A list of files or directories to be excluded from backups. Add one path per line relative to the directory being backed up."), + "#description" => t("A list of files or directories to be excluded from backups. Add one path per line relative to the directory being backed up. Can include * as wildcard."), ); return $form; } @@ -125,9 +125,62 @@ } return FALSE; } + + + /** + * This override of the in_array function adds wildcard support (added by mstevetodd) + * fnmatch is included on some platforms, but not all, so included one here + */ + function in_array($needle, $haystack) { + if (!function_exists('fnmatch')) { + define('FNM_PATHNAME', 1); + define('FNM_NOESCAPE', 2); + define('FNM_PERIOD', 4); + define('FNM_CASEFOLD', 16); + + function fnmatch($pattern, $string, $flags = 0) { + return pcre_fnmatch($pattern, $string, $flags); + } + function pcre_fnmatch($pattern, $string, $flags = 0) { + $modifiers = null; + $transforms = array( + '\*' => '.*', + '\?' => '.', + '\[\!' => '[^', + '\[' => '[', + '\]' => ']', + '\.' => '\.', + '\\' => '\\\\' + ); + // Forward slash in string must be in pattern: + if ($flags & FNM_PATHNAME) { $transforms['\*'] = '[^/]*'; } + // Back slash should not be escaped: + if ($flags & FNM_NOESCAPE) { unset($transforms['\\']); } + // Perform case insensitive match: + if ($flags & FNM_CASEFOLD) { $modifiers .= 'i'; } + // Period at start must be the same as pattern: + if ($flags & FNM_PERIOD) { + if (strpos($string, '.') === 0 && strpos($pattern, '.') !== 0) return false; + } + $pattern = '#^' + . strtr(preg_quote($pattern, '#'), $transforms) + . '$#' + . $modifiers; + return (boolean)preg_match($pattern, $string); + } + } + + foreach ($haystack as $value) { + if (true === fnmatch($value, $needle)) { + return true; + } + } + return false; + } + /** - * Get a list of files to backup from the given set if dirs. Exclude any that match the array $exclude. + * Get a list of files to backup from the given set of dirs. Exclude any that match the array $exclude. */ function get_files_to_backup($dir, $settings, $exclude = array(), $base_dir = '') { $out = array(); @@ -137,7 +190,7 @@ } if ($handle = @opendir($dir)) { while (($file = readdir($handle)) !== FALSE) { - if ($file != '.' && $file != '..' && !in_array($file, $exclude)) { + if ($file != '.' && $file != '..' && !$this->in_array($file, $exclude)) { $file = realpath($dir. '/'. $file); if (is_dir($file)) { $subdir = $this->get_files_to_backup($file, $settings, $exclude, $base_dir);