Skip to content
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
16 changes: 13 additions & 3 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OC\DB\Exceptions\DbalException;
use OC\DB\QueryBuilder\Sharded\ShardDefinition;
use OC\Files\Cache\Wrapper\CacheJail;
use OC\Files\Cache\Wrapper\CacheWrapper;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OC\Files\Storage\Wrapper\Encryption;
Expand Down Expand Up @@ -1215,8 +1217,16 @@ public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEnt
}

private function moveFromStorageSharded(ShardDefinition $shardDefinition, ICache $sourceCache, ICacheEntry $sourceEntry, $targetPath): void {
$sourcePath = $sourceEntry->getPath();
while ($sourceCache instanceof CacheWrapper) {
if ($sourceCache instanceof CacheJail) {
$sourcePath = $sourceCache->getSourcePath($sourcePath);
}
$sourceCache = $sourceCache->getCache();
}

if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
$fileIds = $this->getChildIds($sourceCache->getNumericStorageId(), $sourceEntry->getPath());
$fileIds = $this->getChildIds($sourceCache->getNumericStorageId(), $sourcePath);
} else {
$fileIds = [];
}
Expand All @@ -1234,9 +1244,9 @@ private function moveFromStorageSharded(ShardDefinition $shardDefinition, ICache
// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
$removeEncryptedFlag = ($sourceCache instanceof Cache && $sourceCache->hasEncryptionWrapper()) && !$this->hasEncryptionWrapper();

$sourcePathLength = strlen($sourceEntry->getPath());
$sourcePathLength = strlen($sourcePath);
foreach ($cacheItems as &$cacheItem) {
if ($cacheItem['path'] === $sourceEntry->getPath()) {
if ($cacheItem['path'] === $sourcePath) {
$cacheItem['path'] = $targetPath;
$cacheItem['parent'] = $this->getParentId($targetPath);
$cacheItem['name'] = basename($cacheItem['path']);
Expand Down
16 changes: 13 additions & 3 deletions lib/private/Files/Cache/Wrapper/CacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function __construct(?ICache $cache, ?CacheDependencies $dependencies = n
}
}

protected function getCache() {
public function getCache(): ICache {
if (!$this->cache) {
throw new \Exception('Source cache not initialized');
}
return $this->cache;
}

Expand Down Expand Up @@ -202,7 +205,12 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
* remove all entries for files that are stored on the storage from the cache
*/
public function clear() {
$this->getCache()->clear();
$cache = $this->getCache();
if ($cache instanceof Cache) {
$cache->clear();
} else {
$cache->remove('');
}
}

/**
Expand Down Expand Up @@ -252,7 +260,9 @@ public function calculateFolderSize($path, $entry = null) {
* @return int[]
*/
public function getAll() {
return $this->getCache()->getAll();
/** @var Cache $cache */
$cache = $this->getCache();
return $cache->getAll();
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/Files/Cache/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use OC\Files\Cache\Cache;
use OC\Files\Cache\CacheEntry;
use OC\Files\Cache\Wrapper\CacheJail;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OC\Files\Storage\Temporary;
Expand Down Expand Up @@ -521,6 +522,24 @@ public function testMoveFromCache(): void {
$this->assertTrue($this->cache->inCache('targetfolder/sub'));
}

public function testMoveFromCacheJail(): void {
$data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar'];
$folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE];

$this->cache2->put('folder', $folderData);
$this->cache2->put('folder/sub', $data);

$jail = new CacheJail($this->cache2, 'folder');

$this->cache->moveFromCache($jail, 'sub', 'targetsub');

$this->assertTrue($this->cache2->inCache('folder'));
$this->assertFalse($this->cache2->inCache('folder/sub'));

$this->assertTrue($this->cache->inCache('targetsub'));
$this->assertEquals($this->cache->getId(''), $this->cache->get('targetsub')->getParentId());
}

public function testGetIncomplete(): void {
$file1 = 'folder1';
$file2 = 'folder2';
Expand Down
Loading