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); + } }