From 1eff2f49b7dc0d0a3c4937d3d24e24b53f11de1c Mon Sep 17 00:00:00 2001 From: Sujith H Date: Tue, 16 Oct 2018 22:57:52 +0530 Subject: [PATCH] [stable10] Backport of Fix re-encrypting encrypted files When the files are already encrypted the files need not be encrypted again. Signed-off-by: Sujith H --- apps/encryption/lib/Crypto/EncryptAll.php | 5 ++++- apps/encryption/tests/Crypto/EncryptAllTest.php | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/encryption/lib/Crypto/EncryptAll.php b/apps/encryption/lib/Crypto/EncryptAll.php index af4742bff4c2..ac6bbf9471da 100644 --- a/apps/encryption/lib/Crypto/EncryptAll.php +++ b/apps/encryption/lib/Crypto/EncryptAll.php @@ -297,7 +297,10 @@ protected function encryptFile($path) { $target = $path . '.encrypted.' . $this->getTimeStamp() . '.part'; try { - $this->keyManager->setVersion($source, 0, $this->rootView); + $version = $this->keyManager->getVersion($source, $this->rootView); + if ($version > 0) { + return false; + } $this->rootView->copy($source, $target); $this->rootView->rename($target, $source); } catch (DecryptionFailedException $e) { diff --git a/apps/encryption/tests/Crypto/EncryptAllTest.php b/apps/encryption/tests/Crypto/EncryptAllTest.php index 39616176fce2..ea48c51a9ca5 100644 --- a/apps/encryption/tests/Crypto/EncryptAllTest.php +++ b/apps/encryption/tests/Crypto/EncryptAllTest.php @@ -673,4 +673,12 @@ public function testGetTimeStamp() { $result = $this->invokePrivate($encryptAll, 'getTimeStamp', []); $this->assertGreaterThan(10000, $result); } + + public function testEncryptAlreadyEncryptedFile() { + $this->keyManager->method('getVersion') + ->with('/user1/files/bar.txt', $this->view) + ->willReturn(1); + $result = $this->invokePrivate($this->encryptAll, 'encryptFile', ['/user1/files/bar.txt']); + $this->assertFalse($result); + } }