Skip to content

Commit

Permalink
AssetAdapter - If visibility's already correct, don't try to re-set it.
Browse files Browse the repository at this point in the history
Attempting to set the visibility of a file/folder when the filesystem is already set correctly causes "Operation not permitted" errors on some Linux servers. This commit fixes that issue.
  • Loading branch information
nathanbrauer committed Aug 22, 2023
1 parent 7c8440d commit a791b09
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Flysystem/AssetAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,28 @@ protected function configureServer($forceOverwrite = false)

// Apply each configuration
$config = new FlysystemConfig();
$config->set('visibility', $visibility);
foreach ($configurations as $file => $template) {
// Ensure file contents
if ($forceOverwrite || !$this->has($file)) {
if ($this->has($file)) {
$perms = $this->getVisibility($file);
if ($perms['visibility'] === $visibility) {
// If the visibility is already correct, do not try to re-set it.
// Attempting to set the visibility of a file/folder when the filesystem is already
// set correctly causes "Operation not permitted" errors on some Linux servers.
$config->set('visibility', null);
} else {
$config->set('visibility', $visibility);
}
}
// Evaluate file
$content = $this->renderTemplate($template);
$success = $this->write($file, $content, $config);
if (!$success) {
throw new Exception("Error writing server configuration file \"{$file}\"");
}
}

$perms = $this->getVisibility($file);
if ($perms['visibility'] !== $visibility) {
// Ensure correct permissions
Expand Down

0 comments on commit a791b09

Please sign in to comment.