From ea9509eaf9d6caba28320efa92fc538a8fceaf6c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 16 Aug 2022 11:16:14 +0200 Subject: [PATCH] fix updating size when folder is empty Signed-off-by: Robin Appelman --- lib/private/Files/Cache/Cache.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 5dded8c32dd38..ed5c40e86d25c 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -891,7 +891,7 @@ public function calculateFolderSize($path, $entry = null) { return (int)$row['unencrypted_size']; }, $rows); $unencryptedSizes = array_map(function (array $row) { - return (int)(($row['unencrypted_size'] > 0) ? $row['unencrypted_size']: $row['size']); + return (int)(($row['unencrypted_size'] > 0) ? $row['unencrypted_size'] : $row['size']); }, $rows); $sum = array_sum($sizes); @@ -913,18 +913,22 @@ public function calculateFolderSize($path, $entry = null) { } else { $unencryptedTotal = $unencryptedSum; } - if ($entry['size'] !== $totalSize) { - // only set unencrypted size for a folder if any child entries have it set - if ($unencryptedMax > 0) { - $this->update($id, [ - 'size' => $totalSize, - 'unencrypted_size' => $unencryptedTotal, - ]); - } else { - $this->update($id, [ - 'size' => $totalSize, - ]); - } + } else { + $totalSize = 0; + $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) { + $this->update($id, [ + 'size' => $totalSize, + 'unencrypted_size' => $unencryptedTotal, + ]); + } else { + $this->update($id, [ + 'size' => $totalSize, + ]); } } }