Optimize put - Dont try to fetch filecache for not existing filecache in encription

This commit is contained in:
Piotr M 2017-03-28 14:49:06 +02:00 committed by Joas Schilling
parent af42ca2025
commit dc78f1251e
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
2 changed files with 13 additions and 6 deletions

View File

@ -910,7 +910,8 @@ class Encryption extends Wrapper {
*/ */
protected function getHeader($path) { protected function getHeader($path) {
$realFile = $this->util->stripPartialFileExtension($path); $realFile = $this->util->stripPartialFileExtension($path);
if ($this->storage->file_exists($realFile)) { $exists = $this->storage->file_exists($realFile);
if ($exists) {
$path = $realFile; $path = $realFile;
} }
@ -922,8 +923,9 @@ class Encryption extends Wrapper {
if (!isset($result[Util::HEADER_ENCRYPTION_MODULE_KEY])) { if (!isset($result[Util::HEADER_ENCRYPTION_MODULE_KEY])) {
if (!empty($result)) { if (!empty($result)) {
$result[Util::HEADER_ENCRYPTION_MODULE_KEY] = 'OC_DEFAULT_MODULE'; $result[Util::HEADER_ENCRYPTION_MODULE_KEY] = 'OC_DEFAULT_MODULE';
} else { } else if ($exists) {
// if the header was empty we have to check first if it is a encrypted file at all // if the header was empty we have to check first if it is a encrypted file at all
// We would do query to filecache only if we know that entry in filecache exists
$info = $this->getCache()->get($path); $info = $this->getCache()->get($path);
if (isset($info['encrypted']) && $info['encrypted'] === true) { if (isset($info['encrypted']) && $info['encrypted'] === true) {
$result[Util::HEADER_ENCRYPTION_MODULE_KEY] = 'OC_DEFAULT_MODULE'; $result[Util::HEADER_ENCRYPTION_MODULE_KEY] = 'OC_DEFAULT_MODULE';

View File

@ -614,11 +614,15 @@ class EncryptionTest extends Storage {
* *
* @dataProvider dataTestGetHeaderAddLegacyModule * @dataProvider dataTestGetHeaderAddLegacyModule
*/ */
public function testGetHeaderAddLegacyModule($header, $isEncrypted, $expected) { public function testGetHeaderAddLegacyModule($header, $isEncrypted, $exists, $expected) {
$sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage') $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$sourceStorage->expects($this->once())
->method('file_exists')
->willReturnCallback(function() use ($exists) {return $exists;});
$util = $this->getMockBuilder('\OC\Encryption\Util') $util = $this->getMockBuilder('\OC\Encryption\Util')
->setConstructorArgs([new View(), new Manager($this->config), $this->groupManager, $this->config, $this->arrayCache]) ->setConstructorArgs([new View(), new Manager($this->config), $this->groupManager, $this->config, $this->arrayCache])
->getMock(); ->getMock();
@ -657,9 +661,10 @@ class EncryptionTest extends Storage {
public function dataTestGetHeaderAddLegacyModule() { public function dataTestGetHeaderAddLegacyModule() {
return [ return [
[['cipher' => 'AES-128'], true, ['cipher' => 'AES-128', Util::HEADER_ENCRYPTION_MODULE_KEY => 'OC_DEFAULT_MODULE']], [['cipher' => 'AES-128'], true, true, ['cipher' => 'AES-128', Util::HEADER_ENCRYPTION_MODULE_KEY => 'OC_DEFAULT_MODULE']],
[[], true, [Util::HEADER_ENCRYPTION_MODULE_KEY => 'OC_DEFAULT_MODULE']], [[], true, false, []],
[[], false, []], [[], true, true, [Util::HEADER_ENCRYPTION_MODULE_KEY => 'OC_DEFAULT_MODULE']],
[[], false, true, []],
]; ];
} }