]> source.dussan.org Git - nextcloud-server.git/commitdiff
skip already encrypted files on encrypt all command
authorBjoern Schiessle <bjoern@schiessle.org>
Wed, 24 Oct 2018 14:15:17 +0000 (16:15 +0200)
committerBjoern Schiessle <bjoern@schiessle.org>
Thu, 25 Oct 2018 15:52:40 +0000 (17:52 +0200)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
apps/encryption/lib/Crypto/EncryptAll.php
apps/encryption/tests/Crypto/EncryptAllTest.php

index c2619dc8ef1ffee8c344790e6b3816a5c687734e..ee13fee9eef73171f6a7e3749d436d2afc39d7b7 100644 (file)
@@ -295,6 +295,12 @@ class EncryptAll {
         */
        protected function encryptFile($path) {
 
+               // skip already encrypted files
+               $fileInfo = $this->rootView->getFileInfo($path);
+               if ($fileInfo !== false && $fileInfo->isEncrypted()) {
+                       return true;
+               }
+
                $source = $path;
                $target = $path . '.encrypted.' . time();
 
index a39bf7befb6a35b034904a418cfbd0a0fef24e1c..647b951a0a67e520f4296efdb6d4fcac69a76355 100644 (file)
@@ -33,6 +33,7 @@ use OCA\Encryption\Crypto\EncryptAll;
 use OCA\Encryption\KeyManager;
 use OCA\Encryption\Users\Setup;
 use OCA\Encryption\Util;
+use OCP\Files\FileInfo;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IUserManager;
@@ -354,4 +355,36 @@ class EncryptAllTest extends TestCase {
                $this->assertSame($password, $userPasswords['user1']);
        }
 
+       /**
+        * @dataProvider dataTestEncryptFile
+        * @param $isEncrypted
+        */
+       public function testEncryptFile($isEncrypted) {
+               $fileInfo = $this->createMock(FileInfo::class);
+               $fileInfo->expects($this->any())->method('isEncrypted')
+                       ->willReturn($isEncrypted);
+               $this->view->expects($this->any())->method('getFileInfo')
+                       ->willReturn($fileInfo);
+
+
+               if($isEncrypted) {
+                       $this->view->expects($this->never())->method('copy');
+                       $this->view->expects($this->never())->method('rename');
+               } else {
+                       $this->view->expects($this->once())->method('copy');
+                       $this->view->expects($this->once())->method('rename');
+               }
+
+               $this->assertTrue(
+                       $this->invokePrivate($this->encryptAll, 'encryptFile', ['foo.txt'])
+               );
+       }
+
+       public function dataTestEncryptFile() {
+               return [
+                       [true],
+                       [false],
+               ];
+       }
+
 }