diff --git a/core/includes/file.inc b/core/includes/file.inc index 15a1811..8c2e13a 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -946,15 +946,18 @@ function file_scan_directory($dir, $mask, $options = array(), $depth = 0) { $dir_has_slash = (substr($dir, -1) === '/'); } - // By default, do not check for files in common special-purpose directories. - // The folders here are front-end related and they have been added to avoid - // issues with Drupal recursive scanning. In this case, we added node_modules - // and bower_components. This also improves performance on frontend builds. - $ignore_directories = Settings::get('drupal_file_scan_ignore_directories', [ - 'node_modules', - 'bower_components', - ]); - $default_nomask = '/^' . implode('|', $ignore_directories) . '$/'; + // By default, when there is no explicit 'nomask' option, do not check for + // files in common special-purpose directories. The folders here are front-end + // related and they have been added to avoid issues with Drupal recursive + // scanning. In this case, we added node_modules and bower_components. This + // also improves performance on frontend builds. + if (!isset($options['nomask'])) { + $ignore_directories = Settings::get('drupal_file_scan_ignore_directories', [ + 'node_modules', + 'bower_components', + ]); + $options['nomask'] = '/^' . implode('|', $ignore_directories) . '$/'; + } $options['key'] = in_array($options['key'], array('uri', 'filename', 'name')) ? $options['key'] : 'uri'; $files = array(); @@ -964,10 +967,7 @@ function file_scan_directory($dir, $mask, $options = array(), $depth = 0) { if ($handle = @opendir($dir)) { while (FALSE !== ($filename = readdir($handle))) { // Skip this file if it matches the nomask or starts with a dot. - if ($filename[0] != '.' - && !(isset($options['nomask']) && preg_match($options['nomask'], $filename)) - && !(!empty($default_nomask) && preg_match($default_nomask, $filename)) - ) { + if ($filename[0] != '.' && !(isset($options['nomask']) && preg_match($options['nomask'], $filename))) { if ($depth == 0 && $dir_has_slash) { $uri = "$dir$filename"; }