Skip to content

Commit

Permalink
Handle MetadataDirective gracefully.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Apr 7, 2024
1 parent 37d1942 commit 49810f2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/AwsS3V3/AwsS3V3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,17 @@ 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,
$this->prefixer->prefixPath($source),
$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);
Expand Down
34 changes: 34 additions & 0 deletions src/AwsS3V3/AwsS3V3AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 49810f2

Please sign in to comment.