Skip to content

Commit 08954d4

Browse files
committed
fix: fix moving cache items from cache jail with sharding
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 2975a99 commit 08954d4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/private/Files/Cache/Cache.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
1111
use OC\DB\Exceptions\DbalException;
1212
use OC\DB\QueryBuilder\Sharded\ShardDefinition;
13+
use OC\Files\Cache\Wrapper\CacheJail;
14+
use OC\Files\Cache\Wrapper\CacheWrapper;
1315
use OC\Files\Search\SearchComparison;
1416
use OC\Files\Search\SearchQuery;
1517
use OC\Files\Storage\Wrapper\Encryption;
@@ -1215,8 +1217,16 @@ public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEnt
12151217
}
12161218

12171219
private function moveFromStorageSharded(ShardDefinition $shardDefinition, ICache $sourceCache, ICacheEntry $sourceEntry, $targetPath): void {
1220+
$sourcePath = $sourceEntry->getPath();
1221+
while ($sourceCache instanceof CacheWrapper) {
1222+
if ($sourceCache instanceof CacheJail) {
1223+
$sourcePath = $sourceCache->getSourcePath($sourcePath);
1224+
}
1225+
$sourceCache = $sourceCache->getCache();
1226+
}
1227+
12181228
if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
1219-
$fileIds = $this->getChildIds($sourceCache->getNumericStorageId(), $sourceEntry->getPath());
1229+
$fileIds = $this->getChildIds($sourceCache->getNumericStorageId(), $sourcePath);
12201230
} else {
12211231
$fileIds = [];
12221232
}
@@ -1234,9 +1244,9 @@ private function moveFromStorageSharded(ShardDefinition $shardDefinition, ICache
12341244
// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
12351245
$removeEncryptedFlag = ($sourceCache instanceof Cache && $sourceCache->hasEncryptionWrapper()) && !$this->hasEncryptionWrapper();
12361246

1237-
$sourcePathLength = strlen($sourceEntry->getPath());
1247+
$sourcePathLength = strlen($sourcePath);
12381248
foreach ($cacheItems as &$cacheItem) {
1239-
if ($cacheItem['path'] === $sourceEntry->getPath()) {
1249+
if ($cacheItem['path'] === $sourcePath) {
12401250
$cacheItem['path'] = $targetPath;
12411251
$cacheItem['parent'] = $this->getParentId($targetPath);
12421252
$cacheItem['name'] = basename($cacheItem['path']);

lib/private/Files/Cache/Wrapper/CacheWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(?ICache $cache, ?CacheDependencies $dependencies = n
3737
}
3838
}
3939

40-
protected function getCache() {
40+
public function getCache(): ICache {
4141
return $this->cache;
4242
}
4343

0 commit comments

Comments
 (0)