diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-10-24 18:27:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-24 18:27:03 +0200 |
commit | 410bd9d784fdd3f365cd1755f46265fbb28fbc15 (patch) | |
tree | c5323311a03027f89045bbb9745b4c59109a14f0 /apps | |
parent | 37782b1084275d54474700e4ae7863b18e23dc04 (diff) | |
parent | d76a87f3b0ad3f96373984db31470463b1fdc946 (diff) | |
download | nextcloud-server-410bd9d784fdd3f365cd1755f46265fbb28fbc15.tar.gz nextcloud-server-410bd9d784fdd3f365cd1755f46265fbb28fbc15.zip |
Merge pull request #12018 from nextcloud/improve-encrypt-all
Improve encrypt all / decrypt all
Diffstat (limited to 'apps')
-rw-r--r-- | apps/encryption/lib/Crypto/EncryptAll.php | 6 | ||||
-rw-r--r-- | apps/encryption/tests/Crypto/EncryptAllTest.php | 33 |
2 files changed, 39 insertions, 0 deletions
diff --git a/apps/encryption/lib/Crypto/EncryptAll.php b/apps/encryption/lib/Crypto/EncryptAll.php index c2619dc8ef1..ee13fee9eef 100644 --- a/apps/encryption/lib/Crypto/EncryptAll.php +++ b/apps/encryption/lib/Crypto/EncryptAll.php @@ -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(); diff --git a/apps/encryption/tests/Crypto/EncryptAllTest.php b/apps/encryption/tests/Crypto/EncryptAllTest.php index a39bf7befb6..647b951a0a6 100644 --- a/apps/encryption/tests/Crypto/EncryptAllTest.php +++ b/apps/encryption/tests/Crypto/EncryptAllTest.php @@ -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], + ]; + } + } |