Skip to content

Commit

Permalink
skip already decrypted files on decrypt all command
Browse files Browse the repository at this point in the history
Signed-off-by: Bjoern Schiessle <[email protected]>
  • Loading branch information
schiessle committed Oct 24, 2018
1 parent 87657ff commit d76a87f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
6 changes: 6 additions & 0 deletions lib/private/Encryption/DecryptAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ protected function decryptUsersFiles($uid, ProgressBar $progress, $userCount) {
*/
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();

Expand Down
41 changes: 31 additions & 10 deletions tests/lib/Encryption/DecryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ function($path) {

}

public function testDecryptFile() {
/**
* @dataProvider dataTrueFalse
*/
public function testDecryptFile($isEncrypted) {

$path = 'test.txt';

Expand All @@ -327,15 +330,26 @@ public function testDecryptFile() {
->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])
);
Expand All @@ -356,6 +370,13 @@ public function testDecryptFileFailure() {
->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())
Expand Down

0 comments on commit d76a87f

Please sign in to comment.