Skip to content

Commit

Permalink
Merge pull request #33562 from nextcloud/empty-folder-size-24
Browse files Browse the repository at this point in the history
[24] fix updating size when folder is empty
  • Loading branch information
icewind1991 authored Aug 17, 2022
2 parents a512a6c + ea9509e commit ba606f1
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
]);
}
}
}
Expand Down

0 comments on commit ba606f1

Please sign in to comment.