You are here

public function WritableFileSystemValidator::checkPermissions in Automatic Updates 8.2

Checks that the file system is writable.

@todo It might make sense to use a more sophisticated method of testing writability than is_writable(), since it's not clear if that can return false negatives/positives due to things like SELinux, exotic file systems, and so forth.

Parameters

\Drupal\automatic_updates\Event\UpdateEvent $event: The event object.

File

src/Validator/WritableFileSystemValidator.php, line 61

Class

WritableFileSystemValidator
Checks that the file system is writable.

Namespace

Drupal\automatic_updates\Validator

Code

public function checkPermissions(UpdateEvent $event) : void {
  $messages = [];
  if (!is_writable($this->appRoot)) {
    $messages[] = $this
      ->t('The Drupal directory "@dir" is not writable.', [
      '@dir' => $this->appRoot,
    ]);
  }
  $dir = $this->pathLocator
    ->getVendorDirectory();
  if (!is_writable($dir)) {
    $messages[] = $this
      ->t('The vendor directory "@dir" is not writable.', [
      '@dir' => $dir,
    ]);
  }
  if ($messages) {
    $result = ValidationResult::createError($messages, $this
      ->t('The file system is not writable.'));
    $event
      ->addValidationResult($result);
  }
}