From 00d0d849301c0b84b1e7588d3beab5d6645f3062 Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Mon, 23 May 2011 01:42:18 -0400
Subject: [PATCH] Issue #1165694 by pillarsdotnet: file_scan_directory() should include common version-control and temporary files in its default nomask pattern

---
 includes/file.inc |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/includes/file.inc b/includes/file.inc
index b7a12047055ee0aab3081fec0df9c48ec1dcb625..d6e639678682dadf3a72f6d1510e35cdc35fe7ad 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -1939,7 +1939,13 @@ function file_download() {
  * @param $options
  *   An associative array of additional options, with the following elements:
  *   - 'nomask': The preg_match() regular expression of the files to ignore.
- *     Defaults to '/(\.\.?|CVS)$/'.
+ *     The default includes the following sub-patterns:
+ *     - \.\.?: Current and parent directories.
+ *     - CVS(\.adm)?: CVS directories.
+ *     - RCS(LOG)?|SCCS: RCS and SCCS directories.
+ *     - \.svn|\.git|\.bzr: Other version-control directories.
+ *     - (cvslog\.|\.?#|,|_\$|\.del-).*: Temporary file prefixes.
+ *     - .*?(~|\$|\.(old|bak|BAK|orig|rej)): Temporary file suffixes.
  *   - 'callback': The callback function to call for each match. There is no
  *     default callback.
  *   - 'recurse': When TRUE, the directory scan will recurse the entire tree
@@ -1961,7 +1967,15 @@ function file_download() {
 function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
   // Merge in defaults.
   $options += array(
-    'nomask' => '/(\.\.?|CVS)$/',
+    // The following is a subset of what rsync uses for its cvs-exclude option.
+    'nomask' => '/^('
+    . '\.\.?' // Current and parent directories.
+    . '|CVS(\.adm)?' // CVS directories.
+    . '|RCS(LOG)?|SCCS' // RCS and SCCS directories.
+    . '|\.svn|\.git|\.bzr' // Other version-control directories.
+    . '|(cvslog\.|\.?#|,|_\$|\.del-).*' // Temporary file prefixes.
+    . '|.*?(~|\$|\.(old|bak|BAK|orig|rej))' // Temporary file suffixes.
+    . ')$/',
     'callback' => 0,
     'recurse' => TRUE,
     'key' => 'uri',
-- 
1.7.4.1

