Package Manager throws exception when attempting to exclude private files when they are out of project root

Created on 13 February 2025, about 2 months ago

Problem/Motivation

1. I have private files configured on an absolute path outside of the webroot (and even the project root).
2. This throws off SiteFilesExcluder, because it attempts to exclude public, private and asset files, but as part of that it also forces those to be under either the webroot (if relative paths) of the project root (if absolute paths).

 /**
   * Excludes public and private files from stage operations.
   *
   * @param \Drupal\package_manager\Event\CollectPathsToExcludeEvent $event
   *   The event object.
   */
  public function excludeSiteFiles(CollectPathsToExcludeEvent $event): void {
    // Exclude files handled by the stream wrappers listed in $this->wrappers.
    // These paths could be either absolute or relative, depending on site
    // settings. If they are absolute, treat them as relative to the project
    // root. Otherwise, treat them as relative to the web root.
    foreach ($this->wrappers as $scheme) {
      $wrapper = $this->streamWrapperManager->getViaScheme($scheme);
      if ($wrapper instanceof LocalStream) {
        $path = $wrapper->getDirectoryPath();

        if ($this->fileSystem->isAbsolutePath($path)) {
          if ($path = realpath($path)) {
            $event->addPathsRelativeToProjectRoot([$path]);
          }
        }
        else {
          $event->addPathsRelativeToWebRoot([$path]);
        }
      }
    }
  }

(exception is thrown from addPathsRelativeToProjectRoot() as the path is of course not inside the project root).

Steps to reproduce

Have private files outside of the project root.

Proposed resolution

Since the files are attempted to be excluded anyway and they are at an entirely different place, they would be naturally excluded? So at this point, if something is outside of the area that is used for creating the stage, it should be just ignored I think? Wold that be "outside of the project root"?

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.1 🔥

Component

package_manager.module

Created by

🇭🇺Hungary Gábor Hojtsy Hungary

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024