diff --git a/lib/private/encryption/keys/storage.php b/lib/private/encryption/keys/storage.php index e34d7370ef..118c8dc920 100644 --- a/lib/private/encryption/keys/storage.php +++ b/lib/private/encryption/keys/storage.php @@ -235,6 +235,7 @@ class Storage implements IStorage { * * @param string $source * @param string $target + * @return boolean */ public function renameKeys($source, $target) { @@ -253,7 +254,11 @@ class Storage implements IStorage { if ($this->view->file_exists($sourcePath)) { $this->keySetPreparation(dirname($targetPath)); $this->view->rename($sourcePath, $targetPath); + + return true; } + + return false; } /** @@ -261,6 +266,7 @@ class Storage implements IStorage { * * @param string $source * @param string $target + * @return boolean */ public function copyKeys($source, $target) { @@ -279,7 +285,10 @@ class Storage implements IStorage { if ($this->view->file_exists($sourcePath)) { $this->keySetPreparation(dirname($targetPath)); $this->view->copy($sourcePath, $targetPath); + return true; } + + return false; } /** diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index 0f6096adb7..4d546495aa 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -230,8 +230,11 @@ class Encryption extends Wrapper { if (isset($this->unencryptedSize[$source])) { $this->unencryptedSize[$target] = $this->unencryptedSize[$source]; } - $this->keyStorage->renameKeys($source, $target); - if (dirname($source) !== dirname($target) && $this->util->isFile($target)) { + $keysRenamed = $this->keyStorage->renameKeys($source, $target); + if ($keysRenamed && + dirname($source) !== dirname($target) && + $this->util->isFile($target) + ) { $this->update->update($target); } } @@ -256,8 +259,11 @@ class Encryption extends Wrapper { $result = $this->storage->copy($path1, $path2); if ($result) { $target = $this->getFullPath($path2); - $this->keyStorage->copyKeys($source, $target); - if (dirname($source) !== dirname($target) && $this->util->isFile($target)) { + $keysCopied = $this->keyStorage->copyKeys($source, $target); + if ($keysCopied && + dirname($source) !== dirname($target) && + $this->util->isFile($target) + ) { $this->update->update($target); } } diff --git a/lib/public/encryption/keys/istorage.php b/lib/public/encryption/keys/istorage.php index 696d537331..ffbffdc1a2 100644 --- a/lib/public/encryption/keys/istorage.php +++ b/lib/public/encryption/keys/istorage.php @@ -153,6 +153,7 @@ interface IStorage { * * @param string $source * @param string $target + * @return boolean * @since 8.1.0 */ public function renameKeys($source, $target); @@ -162,6 +163,7 @@ interface IStorage { * * @param string $source * @param string $target + * @retrun boolean * @since 8.1.0 */ public function copyKeys($source, $target); diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php index f22f02f568..2d3f10ecdf 100644 --- a/tests/lib/files/storage/wrapper/encryption.php +++ b/tests/lib/files/storage/wrapper/encryption.php @@ -136,7 +136,8 @@ class Encryption extends \Test\Files\Storage\Storage { public function testRename($source, $target, $shouldUpdate) { $this->keyStore ->expects($this->once()) - ->method('renameKeys'); + ->method('renameKeys') + ->willReturn(true); $this->util->expects($this->any()) ->method('isFile')->willReturn(true); if ($shouldUpdate) { @@ -174,7 +175,8 @@ class Encryption extends \Test\Files\Storage\Storage { public function testCopy($source, $target, $shouldUpdate) { $this->keyStore ->expects($this->once()) - ->method('copyKeys'); + ->method('copyKeys') + ->willReturn(true); $this->util->expects($this->any()) ->method('isFile')->willReturn(true); if ($shouldUpdate) {