Skip to content
Snippets Groups Projects

Issue #3231996: Ensure file system is writeable

Compare and Show latest version
2 files
+ 77
2
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -7,13 +7,9 @@ use Drupal\automatic_updates\Event\UpdateEvent;
use Drupal\automatic_updates\PathLocator;
use Drupal\automatic_updates\Validation\ValidationResult;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Validates that important file system paths are writable.
*/
class WriteableFileSystemValidator implements EventSubscriberInterface {
class WritableFileSystemValidator implements EventSubscriberInterface {
use StringTranslationTrait;
@@ -25,7 +21,7 @@ class WriteableFileSystemValidator implements EventSubscriberInterface {
protected $pathLocator;
/**
* Constructs a WriteableFileSystemValidator object.
* Constructs a WritableFileSystemValidator object.
*
* @param \Drupal\automatic_updates\PathLocator $path_locator
* The path locator service.
@@ -35,41 +31,36 @@ class WriteableFileSystemValidator implements EventSubscriberInterface {
}
/**
* Validates that the file system is writable.
* Checks that the file system is writable.
*
* @param \Drupal\automatic_updates\Event\UpdateEvent $event
* The event object.
*/
public function checkPermissions(UpdateEvent $event): void {
$messages = [];
$dir = $this->pathLocator->getProjectRoot();
$message = $this->t('The project directory "@dir" is not writable.', [
'@dir' => $dir,
]);
$this->checkPath($dir, $event, $message);
if (!is_writable($dir)) {
$messages[] = $this->t('The project directory "@dir" is not writable.', ['@dir' => $dir]);
}
$web_root = $this->pathLocator->getWebRoot();
if ($web_root) {
$dir .= DIRECTORY_SEPARATOR . $web_root;
if (!is_writable($dir)) {
$messages[] = $this->t('The Drupal directory "@dir" is not writable.', ['@dir' => $dir]);
}
}
$dir = $this->pathLocator->getVendorDirectory();
$message = $this->t('The vendor directory "@dir" is not writable.', [
'@dir' => $dir,
]);
$this->checkPath($dir, $event, $message);
}
if (!is_writable($dir)) {
$messages[] = $this->t('The vendor directory "@dir" is not writable.', ['@dir' => $dir]);
}
/**
* Checks that a path is writable, and flags an error if it's not.
*
* @param string $path
* The path to check.
* @param \Drupal\automatic_updates\Event\UpdateEvent $event
* The event object.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup $error_message
* The translated error message if the path is not writeable.
*/
protected function checkPath(string $path, UpdateEvent $event, TranslatableMarkup $error_message): void {
if (is_writable($path)) {
return;
if ($messages) {
$result = ValidationResult::createError($messages, $this->t('The file system is not writable.'));
$event->addValidationResult($result);
}
$result = ValidationResult::createError([$error_message]);
$event->addValidationResult($result);
}
/**
Loading