Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Wrap partial cache entry in CacheEntry #49434

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ public function insert($file, array $data) {
$file = $this->normalize($file);

if (isset($this->partial[$file])) { //add any saved partial data
$data = array_merge($this->partial[$file], $data);
$data = array_merge($this->partial[$file]->getData(), $data);
unset($this->partial[$file]);
}

$requiredFields = ['size', 'mtime', 'mimetype'];
foreach ($requiredFields as $field) {
if (!isset($data[$field])) { //data not complete save as partial and return
$this->partial[$file] = $data;
$this->partial[$file] = new CacheEntry($data);
return -1;
}
}
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/Files/Cache/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Test\Files\Cache;

use OC\Files\Cache\Cache;
use OC\Files\Cache\CacheEntry;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OCP\EventDispatcher\IEventDispatcher;
Expand Down Expand Up @@ -127,13 +128,13 @@ public function testPartial(): void {
$file1 = 'foo';

$this->cache->put($file1, ['size' => 10]);
$this->assertEquals(['size' => 10], $this->cache->get($file1));
$this->assertEquals(new CacheEntry(['size' => 10]), $this->cache->get($file1));

$this->cache->put($file1, ['mtime' => 15]);
$this->assertEquals(['size' => 10, 'mtime' => 15], $this->cache->get($file1));
$this->assertEquals(new CacheEntry(['size' => 10, 'mtime' => 15]), $this->cache->get($file1));

$this->cache->put($file1, ['size' => 12]);
$this->assertEquals(['size' => 12, 'mtime' => 15], $this->cache->get($file1));
$this->assertEquals(new CacheEntry(['size' => 12, 'mtime' => 15]), $this->cache->get($file1));
}

/**
Expand Down
Loading