瀏覽代碼

skip already encrypted files on encrypt all command

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
tags/v15.0.0beta1
Bjoern Schiessle 5 年之前
父節點
當前提交
87657fffd8
沒有連結到貢獻者的電子郵件帳戶。
共有 2 個檔案被更改,包括 39 行新增0 行删除
  1. 6
    0
      apps/encryption/lib/Crypto/EncryptAll.php
  2. 33
    0
      apps/encryption/tests/Crypto/EncryptAllTest.php

+ 6
- 0
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();


+ 33
- 0
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],
];
}

}

Loading…
取消
儲存