From 49810f237bc933dc2a49b24ff6b4208e7074540a Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Sun, 7 Apr 2024 21:16:54 +0200 Subject: [PATCH] Handle MetadataDirective gracefully. --- src/AwsS3V3/AwsS3V3Adapter.php | 5 ++++- src/AwsS3V3/AwsS3V3AdapterTest.php | 34 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/AwsS3V3/AwsS3V3Adapter.php b/src/AwsS3V3/AwsS3V3Adapter.php index 593784ae7..40174e1d6 100644 --- a/src/AwsS3V3/AwsS3V3Adapter.php +++ b/src/AwsS3V3/AwsS3V3Adapter.php @@ -431,6 +431,9 @@ public function copy(string $source, string $destination, Config $config): void ); } + $options = $this->createOptionsFromConfig($config); + $options['MetadataDirective'] = $config->get('MetadataDirective', 'COPY'); + try { $this->client->copy( $this->bucket, @@ -438,7 +441,7 @@ public function copy(string $source, string $destination, Config $config): void $this->bucket, $this->prefixer->prefixPath($destination), $this->visibility->visibilityToAcl($visibility ?: 'private'), - $this->createOptionsFromConfig($config)['params'] + $options, ); } catch (Throwable $exception) { throw UnableToCopyFile::fromLocationTo($source, $destination, $exception); diff --git a/src/AwsS3V3/AwsS3V3AdapterTest.php b/src/AwsS3V3/AwsS3V3AdapterTest.php index 6cbf6d990..8d098aa5a 100644 --- a/src/AwsS3V3/AwsS3V3AdapterTest.php +++ b/src/AwsS3V3/AwsS3V3AdapterTest.php @@ -337,6 +337,40 @@ public function moving_with_updated_metadata(): void $this->assertSame('text/plain+special', $mimeTypeDestination); } + /** + * @test + */ + public function moving_without_updated_metadata(): void + { + $adapter = $this->adapter(); + $adapter->write('source.txt', 'contents to be moved', new Config(['ContentType' => 'text/plain'])); + $mimeTypeSource = $adapter->mimeType('source.txt')->mimeType(); + $this->assertSame('text/plain', $mimeTypeSource); + + $adapter->move('source.txt', 'destination.txt', new Config( + ['ContentType' => 'text/plain+special'] + )); + $mimeTypeDestination = $adapter->mimeType('destination.txt')->mimeType(); + $this->assertSame('text/plain', $mimeTypeDestination); + } + + /** + * @test + */ + public function copying_with_updated_metadata(): void + { + $adapter = $this->adapter(); + $adapter->write('source.txt', 'contents to be moved', new Config(['ContentType' => 'text/plain'])); + $mimeTypeSource = $adapter->mimeType('source.txt')->mimeType(); + $this->assertSame('text/plain', $mimeTypeSource); + + $adapter->copy('source.txt', 'destination.txt', new Config( + ['ContentType' => 'text/plain+special', 'MetadataDirective' => 'REPLACE'] + )); + $mimeTypeDestination = $adapter->mimeType('destination.txt')->mimeType(); + $this->assertSame('text/plain+special', $mimeTypeDestination); + } + /** * @test */