DirectoryWithMetadataDiscovery::getDirectoryIterator fails for symbolic links

Created on 8 August 2024, 8 months ago

Problem/Motivation

After upgrading to Drupal 10.3, my entire site failed to run claiming it was missing a template file that doesn't exist. After a deeper investigation, I discovered that the directory iterator provided by the DirectoryWithMetadataDiscovery class was returning a symlink directory as a false positive for a *.component.yml file. It did this for every symlink in that folder and the site crashed when it couldn't find the first template.

I inherited this project, but just as well that this issue was discovered. It looks like the original team used symlinks for certain react components.

Steps to reproduce

I believe adding any symlink on a linux based system in one of the searchable directories will reproduce this issue.

Proposed resolution

When I added the \FilesystemIterator::FOLLOW_SYMLINKS flag to the iterator, the issue went away. However, I'm not sure it is appropriate to follow symlinks in this case. At the minimum, detection for symlinks should be added, perhaps to the \Drupal\Core\Plugin\Discovery\RegexRecursiveFilterIterator class, to stop the iterator from reporting them as positive matches. In this case, the symlinks are both directories and leaves.

Since this is an important core system, I hope someone with more core experience can come up with a good solution.

πŸ› Bug report
Status

Active

Version

10.3 ✨

Component
PluginΒ  β†’

Last updated about 3 hours ago

Created by

πŸ‡¨πŸ‡¦Canada rzan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @rzan
  • The last time that class changed was in πŸ› SDC's discovery has overly lenient regex Fixed . Does reverting that regex also return the original behavior?

  • πŸ‡¨πŸ‡¦Canada rzan

    Hi cilefen,

    I tried reverting to the regex expression before the change from #3446381, but I still get the same behavior. In the version of Drupal were upgrading from, 10.2.7, the class was still part of the SDC module. We do have a folder named components in our theme directory so this may very well be related to that issue.

    It looks like in the working version, the \Drupal\Core\Plugin\Discovery\DirectoryWithMetadataPluginDiscovery class was never called at all in the previous version, thus no issue. One of the changes must have triggered this class to now be used for discovery so there must be more going on.

    Here is the stack trace I'm dealing with:

    Drupal\Core\Render\Component\Exception\InvalidComponentException: Unable to find the Twig template for the component "compony:select". in Drupal\Core\Plugin\Component->__construct() (line 58 of core/lib/Drupal/Core/Plugin/Component.php).
    Drupal\Core\Plugin\Factory\ContainerFactory->createInstance() (Line: 83)
    Drupal\Component\Plugin\PluginManagerBase->createInstance() (Line: 102)
    Drupal\Core\Theme\ComponentPluginManager->createInstance()
    array_map() (Line: 150)
    Drupal\Core\Theme\ComponentPluginManager->getAllComponents() (Line: 488)
    Drupal\Core\Asset\LibraryDiscoveryParser->librariesForComponents() (Line: 409)
    Drupal\Core\Asset\LibraryDiscoveryParser->parseLibraryInfo() (Line: 157)
    Drupal\Core\Asset\LibraryDiscoveryParser->buildByExtension() (Line: 87)
    Drupal\Core\Asset\LibraryDiscoveryCollector->getLibraryDefinitions() (Line: 66)
    Drupal\Core\Asset\LibraryDiscoveryCollector->resolveCacheMiss() (Line: 149)
    Drupal\Core\Cache\CacheCollector->get() (Line: 44)
    Drupal\Core\Asset\LibraryDiscovery->getLibrariesByExtension() (Line: 58)
    Drupal\Core\Asset\LibraryDiscovery->getLibraryByName() (Line: 68)
    Drupal\Core\Asset\LibraryDependencyResolver->doGetDependencies() (Line: 70)
    Drupal\Core\Asset\LibraryDependencyResolver->doGetDependencies() (Line: 41)
    Drupal\Core\Asset\LibraryDependencyResolver->getLibrariesWithDependencies() (Line: 87)
    Drupal\Core\Asset\LibraryDependencyResolver->getMinimalRepresentativeSubset() (Line: 113)
    Drupal\Core\Asset\AssetResolver->getLibrariesToLoad() (Line: 128)
    Drupal\Core\Asset\AssetResolver->getCssAssets() (Line: 323)
    Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAssetLibraries() (Line: 167)
    Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments() (Line: 97)
    Drupal\big_pipe\Render\BigPipeResponseAttachmentsProcessor->processAttachments() (Line: 45)
    Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond()
    call_user_func() (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 214)
    Symfony\Component\HttpKernel\HttpKernel->filterResponse() (Line: 202)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 53)
    Asm89\Stack\Cors->handle() (Line: 263)
    Drupal\shield\ShieldMiddleware->bypass() (Line: 219)
    Drupal\shield\ShieldMiddleware->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 124)
    Drupal\cloudflare\CloudFlareMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
    Drupal\Core\DrupalKernel->handle() (Line: 19)

  • πŸ‡³πŸ‡ΏNew Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

Production build 0.71.5 2024