aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2023-02-24 17:38:25 +0100
committerRobin Appelman <robin@icewind.nl>2023-04-04 16:48:10 +0200
commit63fb33538cada5402d04f8b933bb098e6bb22d13 (patch)
tree56ba88a7ded3a0318f20f6b83ca4c100a16b8a3a /lib
parent59d0e7711dc84d46b30fd7a66ec13d8207b87150 (diff)
downloadnextcloud-server-63fb33538cada5402d04f8b933bb098e6bb22d13.tar.gz
nextcloud-server-63fb33538cada5402d04f8b933bb098e6bb22d13.zip
fix unencrypted_size for folders when scanning the filesystem with encryption enabled
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Cache/Cache.php8
-rw-r--r--lib/private/Files/Cache/Scanner.php14
2 files changed, 16 insertions, 6 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index afa464a8138..77ef61b2449 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -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,
diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php
index f7d1d105d83..801c5239754 100644
--- a/lib/private/Files/Cache/Scanner.php
+++ b/lib/private/Files/Cache/Scanner.php
@@ -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;