Skip to content

Commit

Permalink
[stable10] Backport of Fix re-encrypting encrypted files
Browse files Browse the repository at this point in the history
When the files are already encrypted the
files need not be encrypted again.

Signed-off-by: Sujith H <[email protected]>
  • Loading branch information
sharidas committed Oct 16, 2018
1 parent 8119395 commit 1eff2f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion apps/encryption/lib/Crypto/EncryptAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions apps/encryption/tests/Crypto/EncryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 1eff2f4

Please sign in to comment.