]> source.dussan.org Git - nextcloud-server.git/commitdiff
skip already decrypted files on decrypt all command 12045/head
authorBjoern Schiessle <bjoern@schiessle.org>
Wed, 24 Oct 2018 14:49:39 +0000 (16:49 +0200)
committerBjoern Schiessle <bjoern@schiessle.org>
Thu, 25 Oct 2018 15:52:51 +0000 (17:52 +0200)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
lib/private/Encryption/DecryptAll.php
tests/lib/Encryption/DecryptAllTest.php

index 12bda54a52e9e1df0252691a30b6276b07f49693..16eee34733453778fb189b8158d27835a4998dbd 100644 (file)
@@ -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();
 
index 59c24fb3c1d425a68a4800f17bdcfd8ddd935a57..4e4b2438a25cd40967df584c2d9901a40eab8826 100644 (file)
@@ -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);
-
-               $this->view->expects($this->once())
-                       ->method('copy')
-                       ->with($path, $path . '.decrypted.42');
-               $this->view->expects($this->once())
-                       ->method('rename')
-                       ->with($path . '.decrypted.42', $path);
-
+               $fileInfo = $this->createMock(FileInfo::class);
+               $fileInfo->expects($this->any())->method('isEncrypted')
+                       ->willReturn($isEncrypted);
+               $this->view->expects($this->any())->method('getFileInfo')
+                       ->willReturn($fileInfo);
+
+               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())