From 3d639c1b65f84c3fbcffe086ec29c4530d4528ba Mon Sep 17 00:00:00 2001 From: Nicolas MURE Date: Thu, 8 Feb 2018 17:47:20 +0100 Subject: [PATCH] also transfert metadata when renaming a file --- spec/Gaufrette/Adapter/OpenStackSpec.php | 5 ++++- src/Gaufrette/Adapter/OpenStack.php | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/Gaufrette/Adapter/OpenStackSpec.php b/spec/Gaufrette/Adapter/OpenStackSpec.php index d0bd183ae..2c4b2c99a 100644 --- a/spec/Gaufrette/Adapter/OpenStackSpec.php +++ b/spec/Gaufrette/Adapter/OpenStackSpec.php @@ -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', diff --git a/src/Gaufrette/Adapter/OpenStack.php b/src/Gaufrette/Adapter/OpenStack.php index e52cf9d31..1cce3384d 100644 --- a/src/Gaufrette/Adapter/OpenStack.php +++ b/src/Gaufrette/Adapter/OpenStack.php @@ -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(