Browse Source

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

tags/v12.0.0beta1
Piotr M 7 years ago
parent
commit
dc78f1251e
No account linked to committer's email address

+ 4
- 2
lib/private/Files/Storage/Wrapper/Encryption.php View File

@@ -910,7 +910,8 @@ class Encryption extends Wrapper {
*/
protected function getHeader($path) {
$realFile = $this->util->stripPartialFileExtension($path);
if ($this->storage->file_exists($realFile)) {
$exists = $this->storage->file_exists($realFile);
if ($exists) {
$path = $realFile;
}

@@ -922,8 +923,9 @@ class Encryption extends Wrapper {
if (!isset($result[Util::HEADER_ENCRYPTION_MODULE_KEY])) {
if (!empty($result)) {
$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
// We would do query to filecache only if we know that entry in filecache exists
$info = $this->getCache()->get($path);
if (isset($info['encrypted']) && $info['encrypted'] === true) {
$result[Util::HEADER_ENCRYPTION_MODULE_KEY] = 'OC_DEFAULT_MODULE';

+ 9
- 4
tests/lib/Files/Storage/Wrapper/EncryptionTest.php View File

@@ -614,11 +614,15 @@ class EncryptionTest extends Storage {
*
* @dataProvider dataTestGetHeaderAddLegacyModule
*/
public function testGetHeaderAddLegacyModule($header, $isEncrypted, $expected) {
public function testGetHeaderAddLegacyModule($header, $isEncrypted, $exists, $expected) {

$sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()->getMock();

$sourceStorage->expects($this->once())
->method('file_exists')
->willReturnCallback(function() use ($exists) {return $exists;});

$util = $this->getMockBuilder('\OC\Encryption\Util')
->setConstructorArgs([new View(), new Manager($this->config), $this->groupManager, $this->config, $this->arrayCache])
->getMock();
@@ -657,9 +661,10 @@ class EncryptionTest extends Storage {

public function dataTestGetHeaderAddLegacyModule() {
return [
[['cipher' => 'AES-128'], true, ['cipher' => 'AES-128', Util::HEADER_ENCRYPTION_MODULE_KEY => 'OC_DEFAULT_MODULE']],
[[], true, [Util::HEADER_ENCRYPTION_MODULE_KEY => 'OC_DEFAULT_MODULE']],
[[], false, []],
[['cipher' => 'AES-128'], true, true, ['cipher' => 'AES-128', Util::HEADER_ENCRYPTION_MODULE_KEY => 'OC_DEFAULT_MODULE']],
[[], true, false, []],
[[], true, true, [Util::HEADER_ENCRYPTION_MODULE_KEY => 'OC_DEFAULT_MODULE']],
[[], false, true, []],
];
}


Loading…
Cancel
Save