From d76a87f3b0ad3f96373984db31470463b1fdc946 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 24 Oct 2018 16:49:39 +0200 Subject: [PATCH] skip already decrypted files on decrypt all command Signed-off-by: Bjoern Schiessle --- lib/private/Encryption/DecryptAll.php | 6 ++++ tests/lib/Encryption/DecryptAllTest.php | 37 +++++++++++++++++++------ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/lib/private/Encryption/DecryptAll.php b/lib/private/Encryption/DecryptAll.php index 12bda54a52..16eee34733 100644 --- a/lib/private/Encryption/DecryptAll.php +++ b/lib/private/Encryption/DecryptAll.php @@ -252,6 +252,12 @@ class DecryptAll { */ protected function decryptFile($path) { + // skip already decrypted files + $fileInfo = $this->rootView->getFileInfo($path); + if ($fileInfo !== false && !$fileInfo->isEncrypted()) { + return true; + } + $source = $path; $target = $path . '.decrypted.' . $this->getTimestamp(); diff --git a/tests/lib/Encryption/DecryptAllTest.php b/tests/lib/Encryption/DecryptAllTest.php index 59c24fb3c1..4e4b2438a2 100644 --- a/tests/lib/Encryption/DecryptAllTest.php +++ b/tests/lib/Encryption/DecryptAllTest.php @@ -311,7 +311,10 @@ class DecryptAllTest extends TestCase { } - public function testDecryptFile() { + /** + * @dataProvider dataTrueFalse + */ + public function testDecryptFile($isEncrypted) { $path = 'test.txt'; @@ -327,15 +330,26 @@ class DecryptAllTest extends TestCase { ->setMethods(['getTimestamp']) ->getMock(); - $instance->expects($this->any())->method('getTimestamp')->willReturn(42); + $fileInfo = $this->createMock(FileInfo::class); + $fileInfo->expects($this->any())->method('isEncrypted') + ->willReturn($isEncrypted); + $this->view->expects($this->any())->method('getFileInfo') + ->willReturn($fileInfo); - $this->view->expects($this->once()) - ->method('copy') - ->with($path, $path . '.decrypted.42'); - $this->view->expects($this->once()) - ->method('rename') - ->with($path . '.decrypted.42', $path); + if ($isEncrypted) { + $instance->expects($this->any())->method('getTimestamp')->willReturn(42); + $this->view->expects($this->once()) + ->method('copy') + ->with($path, $path . '.decrypted.42'); + $this->view->expects($this->once()) + ->method('rename') + ->with($path . '.decrypted.42', $path); + } else { + $instance->expects($this->never())->method('getTimestamp'); + $this->view->expects($this->never())->method('copy'); + $this->view->expects($this->never())->method('rename'); + } $this->assertTrue( $this->invokePrivate($instance, 'decryptFile', [$path]) ); @@ -356,6 +370,13 @@ class DecryptAllTest extends TestCase { ->setMethods(['getTimestamp']) ->getMock(); + + $fileInfo = $this->createMock(FileInfo::class); + $fileInfo->expects($this->any())->method('isEncrypted') + ->willReturn(true); + $this->view->expects($this->any())->method('getFileInfo') + ->willReturn($fileInfo); + $instance->expects($this->any())->method('getTimestamp')->willReturn(42); $this->view->expects($this->once())