From f8b6e17b0871b1b9dd3df95ad0f081923dacc1c9 Mon Sep 17 00:00:00 2001 From: Maciej Raczkowski Date: Fri, 11 Oct 2024 15:29:48 -0500 Subject: [PATCH] Fix ACLs for copy method --- src/AwsS3V3/AwsS3V3Adapter.php | 3 ++- src/AwsS3V3/AwsS3V3AdapterTest.php | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/AwsS3V3/AwsS3V3Adapter.php b/src/AwsS3V3/AwsS3V3Adapter.php index c0203352d..55555f7f5 100644 --- a/src/AwsS3V3/AwsS3V3Adapter.php +++ b/src/AwsS3V3/AwsS3V3Adapter.php @@ -441,6 +441,7 @@ public function copy(string $source, string $destination, Config $config): void $options = $this->createOptionsFromConfig($config); $options['MetadataDirective'] = $config->get('MetadataDirective', 'COPY'); + $acl = $options['params']['ACL'] ?? $this->determineAcl($config); try { $this->client->copy( @@ -448,7 +449,7 @@ public function copy(string $source, string $destination, Config $config): void $this->prefixer->prefixPath($source), $this->bucket, $this->prefixer->prefixPath($destination), - $this->visibility->visibilityToAcl($visibility ?: 'private'), + $acl $options, ); } catch (Throwable $exception) { diff --git a/src/AwsS3V3/AwsS3V3AdapterTest.php b/src/AwsS3V3/AwsS3V3AdapterTest.php index d2fbb5c66..3d60522a1 100644 --- a/src/AwsS3V3/AwsS3V3AdapterTest.php +++ b/src/AwsS3V3/AwsS3V3AdapterTest.php @@ -459,6 +459,28 @@ public function copying_a_file_with_visibility(): void }); } + /** + * @test + */ + public function copying_a_file_with_acls(): void + { + $this->runScenario(function () { + $aclConfig = new Config(['ACL' => 'bucket-owner-full-control']) + $adapter = $this->adapter(); + $adapter->write( + 'source.txt', + 'contents to be copied', + $aclConfig + ); + + $adapter->copy('source.txt', 'destination.txt', $aclConfig); + + $this->assertTrue($adapter->fileExists('source.txt')); + $this->assertTrue($adapter->fileExists('destination.txt')); + $this->assertEquals('contents to be copied', $adapter->read('destination.txt')); + }); + } + protected static function createFilesystemAdapter(bool $streaming = true, array $options = []): FilesystemAdapter { static::$stubS3Client = new S3ClientStub(static::s3Client());