Verified Commit 00a4c7e9 authored by godotislate's avatar godotislate
Browse files

fix: #3564112 Cache rebuild triggers file_get_contents Permission denied in...

fix: #3564112 Cache rebuild triggers file_get_contents Permission denied in theme node_modules despite file_scan_ignore_directories

By: dotoree
By: berdir
By: nicxvan
By: richard.thomas
By: godotislate
(cherry picked from commit 7e0c9a2e)
parent 978748dd
Loading
Loading
Loading
Loading
Loading
+4 −4
Changes for core/assets/scaffold/files/default.settings.php: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -780,11 +780,11 @@
# $settings['trusted_host_patterns'] = [];

/**
 * The default list of directories that will be ignored by Drupal's file API.
 * Directories that will be ignored by Drupal's file API and when scanning for
 * extensions and hooks.
 *
 * By default ignore node_modules and bower_components folders to avoid issues
 * with common frontend tools and recursive scanning of directories looking for
 * extensions.
 * By default, node_modules and bower_components are ignored to speed up scanning
 * by skipping folders containing non-PHP build dependencies.
 *
 * @see \Drupal\Core\File\FileSystemInterface::scanDirectory()
 * @see \Drupal\Core\Extension\ExtensionDiscovery::scanDirectory()
+3 −1
Changes for core/lib/Drupal/Core/Hook/HookCollectorPass.php: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
use Drupal\Core\Hook\Attribute\RemoveHook;
use Drupal\Core\Hook\Attribute\ReorderHook;
use Drupal\Core\Hook\OrderOperation\OrderOperation;
use Drupal\Core\Site\Settings;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

@@ -636,8 +637,9 @@ protected static function filterIterator(\SplFileInfo $fileInfo, $key, \Recursiv
      if ($sub_path_name === 'src' || $sub_path_name === 'src/Hook') {
        return TRUE;
      }
      $ignore_directories = Settings::get('file_scan_ignore_directories', []);
      // glob() doesn't support streams but scandir() does.
      return !in_array($fileInfo->getFilename(), ['tests', 'js', 'css']) && !array_filter(scandir($key), static fn ($filename) => str_ends_with($filename, '.info.yml'));
      return !in_array($fileInfo->getFilename(), array_merge(['tests', 'js', 'css'], $ignore_directories)) && !array_filter(scandir($key), static fn ($filename) => str_ends_with($filename, '.info.yml'));
    }
    return in_array($extension, ['inc', 'module', 'profile', 'install']);
  }
+3 −1
Changes for core/lib/Drupal/Core/Hook/ThemeHookCollectorPass.php: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
use Drupal\Core\Hook\Attribute\RemoveHook;
use Drupal\Core\Hook\Attribute\ProceduralHookScanStop;
use Drupal\Core\Hook\Attribute\ReorderHook;
use Drupal\Core\Site\Settings;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

@@ -357,8 +358,9 @@ protected static function filterIterator(\SplFileInfo $fileInfo, $key, \Recursiv
      if ($subPathName === 'src' || $subPathName === 'src/Hook') {
        return TRUE;
      }
      $ignore_directories = Settings::get('file_scan_ignore_directories', []);
      // glob() doesn't support streams but scandir() does.
      return !in_array($fileInfo->getFilename(), ['tests', 'js', 'css', 'templates']) && !array_filter(scandir($key), static fn($filename) => str_ends_with($filename, '.info.yml'));
      return !in_array($fileInfo->getFilename(), array_merge(['tests', 'js', 'css', 'templates'], $ignore_directories)) && !array_filter(scandir($key), static fn($filename) => str_ends_with($filename, '.info.yml'));
    }
    if ($fileInfo->getFilename() === 'theme-settings.php') {
      return TRUE;
+5 −0
Changes for core/modules/system/tests/modules/HookCollector/ignored_directories_hook_collector_test/ignored_directories_hook_collector_test.info.yml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
name: Test module used to test ignored directories in hook collector
type: module
description: 'Test module used to test ignored directories in hook collector.'
package: Testing
version: VERSION
+16 −0
Changes for core/modules/system/tests/modules/HookCollector/ignored_directories_hook_collector_test/ignored_directory/procedural_hooks.inc: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Test hooks to check directory ignore when scanning.
 *
 * @todo Remove this module when procedural hooks in modules are no
 *    longer supported https://www.drupal.org/project/drupal/issues/3481555
 */

declare(strict_types=1);

/**
 * Implements hook_ignored_alter().
 */
function ignored_directories_hook_collector_test_ignored_alter(): void {}
Loading