Skip to content

Commit 9c6defe

Browse files
committed
fix: allow configuring retain_visibility on a filesystem
1 parent bd7acf3 commit 9c6defe

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

docs/2-cloud-storage-providers.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ flysystem:
161161
## Cloudflare R2
162162
163163
The Cloudflare R2 is compatible with the AWS S3 API, meaning that you can use the same configuration
164-
as for an AWS storage. For example:
164+
as for an AWS storage. Both the regular and the async AWS Client can be used. As example:
165165
166166
```yaml
167167
# config/packages/flysystem.yaml
@@ -184,6 +184,23 @@ flysystem:
184184
bucket: '%env(CLOUDFLARE_R2_BUCKET)%'
185185
```
186186
187+
Cloudflare R2 does not have implemented ACL-related features yet, and thereby making use of Flysystem's `move` and `copy`
188+
methods requires configuring explicit value for `visibility` and setting `retain_visibility` to `false` to prevent the
189+
S3 adapter to call the `GetObjectAcl` command to retrieve an object's current ACL visibility, then resulting in an exception.
190+
191+
```yaml
192+
flysystem:
193+
storages:
194+
cdn.storage:
195+
# ...
196+
visibility: private # or public
197+
198+
# to use the visibility as defined above instead of retaining the object's visibility, and not having to run
199+
# the unsupported `GetObjectAcl` command to get the object's current visibility.
200+
retain_visibility: false
201+
# ...
202+
```
203+
187204
## Next
188205

189206
[Interacting with FTP and SFTP servers](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/3-interacting-with-ftp-and-sftp-servers.md)

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getConfigTreeBuilder(): TreeBuilder
4242
->end()
4343
->scalarNode('visibility')->defaultNull()->end()
4444
->scalarNode('directory_visibility')->defaultNull()->end()
45-
->booleanNode('retain_visibility')->defaultTrue()->end()
45+
->booleanNode('retain_visibility')->defaultNull()->end()
4646
->booleanNode('case_sensitive')->defaultTrue()->end()
4747
->booleanNode('disable_asserts')->defaultFalse()->end()
4848
->arrayNode('public_url')

tests/DependencyInjection/FlysystemExtensionTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Aws\S3\S3Client;
1616
use Google\Cloud\Storage\Bucket;
1717
use Google\Cloud\Storage\StorageClient;
18+
use League\Flysystem\Filesystem;
1819
use League\Flysystem\FilesystemOperator;
1920
use League\Flysystem\UnableToWriteFile;
2021
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
@@ -118,6 +119,28 @@ public function testReadOnly(): void
118119
$fs->write('/path/to/file', 'Unable to write in read only');
119120
}
120121

122+
public function testNotRetainingVisibilityPreventsAclCommandInvocation(): void
123+
{
124+
$kernel = $this->createFlysystemKernel();
125+
$container = $kernel->getContainer()->get('test.service_container');
126+
127+
$calledGetObjectAcl = false;
128+
129+
/** @var S3Client $mock */
130+
$mock = $container->get('aws_client_service');
131+
$mock->method('getCommand')->with($this->callback(function ($name) use (&$calledGetObjectAcl) {
132+
if ('GetObjectAcl' === $name) {
133+
$calledGetObjectAcl = true;
134+
}
135+
}));
136+
137+
/** @var Filesystem $fs */
138+
$fs = $container->get('flysystem.test.fs_aws');
139+
$fs->copy('test.txt', 'test2.txt');
140+
141+
self::assertFalse($calledGetObjectAcl, 'The ACL command should not be called when `retain_visibility` is set to `false`.');
142+
}
143+
121144
private function createFlysystemKernel(): FlysystemAppKernel
122145
{
123146
(new Dotenv())->populate([

tests/Kernel/config/flysystem.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
],
1616
'fs_aws' => [
1717
'adapter' => 'aws',
18+
'visibility' => 'private',
19+
'retain_visibility' => false,
1820
'options' => [
1921
'client' => 'aws_client_service',
2022
'bucket' => '%env(AWS_BUCKET)%',

0 commit comments

Comments
 (0)