function SymlinkValidator::validate

Flags errors if the project root or stage directory contain symbolic links.

Overrides BaseRequirementValidatorTrait::validate

File

core/modules/package_manager/src/Validator/SymlinkValidator.php, line 40

Class

SymlinkValidator
Flags errors if unsupported symbolic links are detected.

Namespace

Drupal\package_manager\Validator

Code

public function validate(PreOperationStageEvent $event) : void {
    if ($event instanceof PreRequireEvent) {
        // We don't need to check symlinks again during PreRequireEvent; this was
        // already just validated during PreCreateEvent.
        return;
    }
    $active_dir = $this->pathFactory
        ->create($this->pathLocator
        ->getProjectRoot());
    // The precondition requires us to pass both an active and stage directory,
    // so if the stage hasn't been created or claimed yet, use the directory
    // that contains this file, which contains only a few files and no symlinks,
    // as the stage directory. The precondition itself doesn't care if the
    // directory actually exists or not.
    $stage_dir = __DIR__;
    if ($event->stage
        ->stageDirectoryExists()) {
        $stage_dir = $event->stage
            ->getStageDirectory();
    }
    $stage_dir = $this->pathFactory
        ->create($stage_dir);
    // Return early if no excluded paths were collected because this validator
    // is dependent on knowing which paths to exclude when searching for
    // symlinks.
    // @see \Drupal\package_manager\StatusCheckTrait::runStatusCheck()
    if ($event->excludedPaths === NULL) {
        return;
    }
    // The list of excluded paths is immutable, but the precondition may need to
    // mutate it, so convert it back to a normal, mutable path list.
    $exclusions = $this->pathListFactory
        ->create(...$event->excludedPaths
        ->getAll());
    try {
        $this->precondition
            ->assertIsFulfilled($active_dir, $stage_dir, $exclusions);
    } catch (PreconditionException $e) {
        $event->addErrorFromThrowable($e);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.