fix unencrypted_size for folders when scanning the filesystem with encryption enabled

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2023-02-24 17:38:25 +01:00
parent 59d0e7711d
commit 63fb33538c
No known key found for this signature in database
GPG key ID: 42B69D8A64526EFB
2 changed files with 16 additions and 6 deletions

View file

@ -954,9 +954,11 @@ class Cache implements ICache {
$unencryptedTotal = 0;
$unencryptedMax = 0;
}
if ($entry['size'] !== $totalSize) {
// only set unencrypted size for a folder if any child entries have it set, or the folder is empty
if ($unencryptedMax > 0 || $totalSize === 0) {
// only set unencrypted size for a folder if any child entries have it set, or the folder is empty
$shouldWriteUnEncryptedSize = $unencryptedMax > 0 || $totalSize === 0;
if ($entry['size'] !== $totalSize || ($entry['unencrypted_size'] !== $unencryptedTotal && $shouldWriteUnEncryptedSize)) {
if ($shouldWriteUnEncryptedSize) {
$this->update($id, [
'size' => $totalSize,
'unencrypted_size' => $unencryptedTotal,

View file

@ -36,6 +36,7 @@
namespace OC\Files\Cache;
use Doctrine\DBAL\Exception;
use OC\Files\Storage\Wrapper\Encryption;
use OCP\Files\Cache\IScanner;
use OCP\Files\ForbiddenException;
use OCP\Files\Storage\IReliableEtagStorage;
@ -219,7 +220,7 @@ class Scanner extends BasicEmitter implements IScanner {
$newData['parent'] = $parentId;
$data['fileid'] = $this->addToCache($file, $newData, $fileId);
}
$data['oldSize'] = ($cacheData && isset($cacheData['size'])) ? $cacheData['size'] : 0;
if ($cacheData && isset($cacheData['encrypted'])) {
@ -390,8 +391,15 @@ class Scanner extends BasicEmitter implements IScanner {
}
}
$oldSize = $data['size'] ?? null;
if ($this->cacheActive && $oldSize !== $size) {
$this->cache->update($folderId, ['size' => $size]);
// for encrypted storages, we trigger a regular folder size calculation instead of using the calculated size
// to make sure we also updated the unencrypted-size where applicable
if ($this->storage->instanceOfStorage(Encryption::class)) {
$this->cache->calculateFolderSize($path);
} else {
if ($this->cacheActive && $oldSize !== $size) {
$this->cache->update($folderId, ['size' => $size]);
}
}
$this->emit('\OC\Files\Cache\Scanner', 'postScanFolder', [$path, $this->storageId]);
return $size;