From 4f2cd9c671778bd8301f37b9e5cba167af62d705 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Mon, 20 Jul 2020 01:17:36 +0400 Subject: [PATCH] Fix cache size limit on 32-bit devices --- submodules/Postbox/Sources/TimeBasedCleanup.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/submodules/Postbox/Sources/TimeBasedCleanup.swift b/submodules/Postbox/Sources/TimeBasedCleanup.swift index a3f40b25d1..f6e1f57123 100644 --- a/submodules/Postbox/Sources/TimeBasedCleanup.swift +++ b/submodules/Postbox/Sources/TimeBasedCleanup.swift @@ -102,14 +102,14 @@ private final class TimeBasedCleanupImpl { }) } - var checkFiles:[GeneralFile] = [] + var checkFiles: [GeneralFile] = [] - var totalLimitSize: Int = 0 + var totalLimitSize: UInt64 = 0 for path in generalPaths { scanFiles(at: path, olderThan: oldestGeneralTimestamp, anyway: { file, size, timestamp in checkFiles.append(GeneralFile(file: file, size: size, timestamp: timestamp)) - totalLimitSize += size + totalLimitSize += UInt64(size) }, unlink: { file in removedGeneralCount += 1 unlink(file) @@ -120,7 +120,11 @@ private final class TimeBasedCleanupImpl { if totalLimitSize > bytesLimit { unlink(item.file) removedGeneralLimitCount += 1 - totalLimitSize -= item.size + if totalLimitSize > UInt64(item.size) { + totalLimitSize -= UInt64(item.size) + } else { + totalLimitSize = 0 + } } else { break clear }