Skip to content

Commit

Permalink
AssetAdapter - If the visibility is already correct, do not try to re…
Browse files Browse the repository at this point in the history
…-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. This commit fixes that issue.
  • Loading branch information
nathanbrauer committed Jul 23, 2023
1 parent baa3ff6 commit 3f9fa6e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Flysystem/AssetAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,21 @@ protected function configureServer($forceOverwrite = false)

// Apply each configuration
$config = new FlysystemConfig();
$config->set('visibility', $visibility);
foreach ($configurations as $file => $template) {

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);
}
}

// Ensure file contents
if ($forceOverwrite || !$this->has($file)) {
// Evaluate file
Expand All @@ -157,7 +170,8 @@ protected function configureServer($forceOverwrite = false)
throw new Exception("Error writing server configuration file \"{$file}\"");
}
}
$perms = $this->getVisibility($file);

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

0 comments on commit 3f9fa6e

Please sign in to comment.