diff --git a/package_manager/src/PathExcluder/SiteConfigurationExcluder.php b/package_manager/src/PathExcluder/SiteConfigurationExcluder.php index 96c29f006061b46dff81c7f22f4101f9d3b936de..0c4bd7b498ccf2c91c47af924bcbdc569bc3d832 100644 --- a/package_manager/src/PathExcluder/SiteConfigurationExcluder.php +++ b/package_manager/src/PathExcluder/SiteConfigurationExcluder.php @@ -86,25 +86,41 @@ class SiteConfigurationExcluder implements EventSubscriberInterface { * The event being handled. * * @throws \Drupal\Core\File\Exception\FileException - * If the permissions of the live `sites/default` cannot be determined, or - * changed on the staged `sites/default`. + * If the permissions of the either the live or staged `sites/default` + * cannot be determined, or changed on the staged `sites/default`. */ public function syncDefaultSiteDirectoryPermissions(PreApplyEvent $event): void { $live_dir = $this->getDefaultSiteDirectoryPath($this->pathLocator->getProjectRoot()); $staged_dir = $this->getDefaultSiteDirectoryPath($event->stage->getStageDirectory()); - $original_permissions = fileperms($live_dir); - if ($original_permissions === FALSE) { - throw new FileException("Could not determine permissions for '$live_dir'."); - } + // This is borrowed from \Symfony\Component\Filesystem\Filesystem::copy(). + $permissions = $this->getPermissions($staged_dir) | ($this->getPermissions($live_dir) & 0111); - // @see \Symfony\Component\Filesystem\Filesystem::copy() for another use - // of the 0111 bitmask. - if (!$this->fileSystem->chmod($staged_dir, $original_permissions & 0111)) { + if (!$this->fileSystem->chmod($staged_dir, $permissions)) { throw new FileException("Could not change permissions on '$staged_dir'."); } } + /** + * Gets the current file permissions of a path. + * + * @param string $path + * The path to examine. + * + * @return int + * The current permissions of the path. + * + * @throws \Drupal\Core\File\Exception\FileException + * Thrown if the file permissions cannot be determined. + */ + private function getPermissions(string $path): int { + $permissions = fileperms($path); + if ($permissions === FALSE) { + throw new FileException("Could not determine permissions for '$path'."); + } + return $permissions; + } + /** * Returns the full path to `sites/default`, relative to a root directory. *