Skip to content

Commit

Permalink
also transfert metadata when renaming a file
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasmure committed Oct 11, 2018
1 parent b8dd9dd commit 3d639c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion spec/Gaufrette/Adapter/OpenStackSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,15 @@ function it_throws_storage_failure_while_deleting(Container $container, StorageO
$this->shouldThrow('Gaufrette\Exception\StorageFailure')->duringdelete('test');
}

function it_renames_file(Container $container, StorageObject $source)
function it_renames_file(Container $container, StorageObject $source, StorageObject $dest)
{
$container->objectExists('dest')->willReturn(false);

$container->getObject('source')->willReturn($source);
$container->getObject('dest')->willReturn($dest);
$source->download()->willReturn($this->getReadableStream('Hello World!'));
$source->getMetadata()->willReturn(['meta' => 'data']);
$dest->resetMetadata(['meta' => 'data'])->shouldBeCalled();

$container->createObject([
'name' => 'dest',
Expand Down
5 changes: 5 additions & 0 deletions src/Gaufrette/Adapter/OpenStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ public function rename($sourceKey, $targetKey)
try {
$this->write($targetKey, $this->read($sourceKey));

$metadata = $this->getMetadata($sourceKey);
if (!empty($metadata)) {
$this->setMetadata($targetKey, $metadata);
}

$this->delete($sourceKey);
} catch (StorageFailure $e) {
throw StorageFailure::unexpectedFailure(
Expand Down

0 comments on commit 3d639c1

Please sign in to comment.