]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix unencrypted_size for folders when scanning the filesystem with encryption enabled
authorRobin Appelman <robin@icewind.nl>
Fri, 24 Feb 2023 16:38:25 +0000 (17:38 +0100)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Wed, 11 Oct 2023 12:41:43 +0000 (14:41 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/Cache/Cache.php
lib/private/Files/Cache/Scanner.php

index 9e475057a36dfa5a9c1b61f99f61ecdd87472dab..7ad16e34a62d4ad72618775e26f2d83ed362638f 100644 (file)
@@ -937,9 +937,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,
index 42f8f1b375bc9ea79a22455355d6971705356014..720428e9bd821377639781cc853a2c0a84d90098 100644 (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;