Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
skip already decrypted files on decrypt all command
Signed-off-by: Bjoern Schiessle <[email protected]>
  • Loading branch information
schiessle committed Oct 25, 2018
commit 6f3328a9cd37c9bb6ff2bc0e85135f4955fb851a
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