From b996c1f43f2e75bbb3aed7b0832ac25db30ba258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20J=C3=BCrges?= Date: Tue, 8 Mar 2016 16:24:27 +0100 Subject: [PATCH 1/4] Check if file needs to decrypted or not for speed up large oc setups. --- lib/private/Encryption/DecryptAll.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/private/Encryption/DecryptAll.php b/lib/private/Encryption/DecryptAll.php index 973036fe14d..303e7776a61 100644 --- a/lib/private/Encryption/DecryptAll.php +++ b/lib/private/Encryption/DecryptAll.php @@ -133,6 +133,7 @@ class DecryptAll { /** * iterate over all user and encrypt their files + * * @param string $user which users files should be decrypted, default = all users */ protected function decryptAllUsersFiles($user = '') { @@ -200,9 +201,9 @@ class DecryptAll { $this->setupUserFS($uid); $directories = array(); - $directories[] = '/' . $uid . '/files'; + $directories[] = '/' . $uid . '/files'; - while($root = array_pop($directories)) { + while ($root = array_pop($directories)) { $content = $this->rootView->getDirectoryContent($root); foreach ($content as $file) { $path = $root . '/' . $file['name']; @@ -213,9 +214,14 @@ class DecryptAll { try { $progress->setMessage("decrypt files for user $userCount: $path"); $progress->advance(); - if ($this->decryptFile($path) === false) { + if ($file->getData()['encrypted'] == 0) { $progress->setMessage("decrypt files for user $userCount: $path (already decrypted)"); $progress->advance(); + } else { + if ($this->decryptFile($path) === false) { + $progress->setMessage("decrypt files for user $userCount: $path (already decrypted)"); + $progress->advance(); + } } } catch (\Exception $e) { if (isset($this->failed[$uid])) { From fd4f9091fdad984b34626da7a8d9d37a00d7482f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20J=C3=BCrges?= Date: Wed, 9 Mar 2016 12:47:19 +0100 Subject: [PATCH 2/4] Respect oc coding style guide. --- lib/private/Encryption/DecryptAll.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Encryption/DecryptAll.php b/lib/private/Encryption/DecryptAll.php index 303e7776a61..904a247e41c 100644 --- a/lib/private/Encryption/DecryptAll.php +++ b/lib/private/Encryption/DecryptAll.php @@ -214,7 +214,7 @@ class DecryptAll { try { $progress->setMessage("decrypt files for user $userCount: $path"); $progress->advance(); - if ($file->getData()['encrypted'] == 0) { + if ((int)$file->getData()['encrypted'] === 0) { $progress->setMessage("decrypt files for user $userCount: $path (already decrypted)"); $progress->advance(); } else { From 1423cf1d9d2b855d44aa74267c7ff84e8bc5b00c Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 24 May 2016 10:24:21 +0200 Subject: [PATCH 3/4] Use isEncrpyted() instead --- lib/private/Encryption/DecryptAll.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Encryption/DecryptAll.php b/lib/private/Encryption/DecryptAll.php index 904a247e41c..8676bc09575 100644 --- a/lib/private/Encryption/DecryptAll.php +++ b/lib/private/Encryption/DecryptAll.php @@ -214,7 +214,7 @@ class DecryptAll { try { $progress->setMessage("decrypt files for user $userCount: $path"); $progress->advance(); - if ((int)$file->getData()['encrypted'] === 0) { + if ($file->isEncrypted() === false) { $progress->setMessage("decrypt files for user $userCount: $path (already decrypted)"); $progress->advance(); } else { From b15babd061c811e26093624ac4140c88a9e5ebcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Wed, 25 May 2016 15:42:33 +0200 Subject: [PATCH 4/4] fix unit tests --- tests/lib/Encryption/DecryptAllTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/lib/Encryption/DecryptAllTest.php b/tests/lib/Encryption/DecryptAllTest.php index 85fbe3e0ed9..ffcbbc74a99 100644 --- a/tests/lib/Encryption/DecryptAllTest.php +++ b/tests/lib/Encryption/DecryptAllTest.php @@ -26,6 +26,7 @@ namespace Test\Encryption; use OC\Encryption\DecryptAll; use OC\Encryption\Exceptions\DecryptionFailedException; use OC\Encryption\Manager; +use OC\Files\FileInfo; use OC\Files\View; use OCP\IUserManager; use Test\TestCase; @@ -242,15 +243,15 @@ class DecryptAllTest extends TestCase { $this->view->expects($this->at(0))->method('getDirectoryContent') ->with('/user1/files')->willReturn( [ - ['name' => 'foo', 'type'=>'dir'], - ['name' => 'bar', 'type'=>'file'], + new FileInfo('path', null, 'intPath', ['name' => 'foo', 'type'=>'dir'], null), + new FileInfo('path', null, 'intPath', ['name' => 'bar', 'type'=>'file', 'encrypted'=>true], null) ] ); $this->view->expects($this->at(3))->method('getDirectoryContent') ->with('/user1/files/foo')->willReturn( [ - ['name' => 'subfile', 'type'=>'file'] + new FileInfo('path', null, 'intPath', ['name' => 'subfile', 'type'=>'file', 'encrypted'=>true], null) ] );