Merge pull request #33562 from nextcloud/empty-folder-size-24

[24] fix updating size when folder is empty
This commit is contained in:
Robin Appelman 2022-08-17 11:13:22 +02:00 committed by GitHub
commit ba606f1bb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -891,7 +891,7 @@ class Cache implements ICache {
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 @@ class Cache implements ICache {
} 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,
]);
}
}
}