summaryrefslogtreecommitdiffstats
path: root/src/network/access
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-07-16 14:05:06 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2021-07-20 18:30:44 +0200
commitd9f80502f6450f0bc8e6d7ca13e1c912ad485599 (patch)
tree6d5d781b28dddee9eeb74486713c199b3d8f689e /src/network/access
parentaf000203359d7a0df2dc4901db605c4e18511e99 (diff)
QNetworkDiskCache: Fix tracking of size during storeItem()
If the file already existed we simply removed the old one without adjusting the size. So use the removeFile() function which takes care of that. Additionally, if the current size was non-null we previously increased the size (presumably meant to be temporarily but wasn't) and called expire() which would either: 1. not do anything and return currentCacheSize, if it was not greater than the max size. This would mean that the size of the file would be counted twice. or, 2. discard currentCacheSize, measure the size of the items, and then remove some items if the total size surpassed the max cache size Neither of those branches need us to (temporarily) increase currentCacheSize. It also doesn't attain the (presumed) goal of trying to keep below the max cache size after having added the new item. Fixes: QTBUG-95009 Pick-to: 6.2 6.1 5.15 Change-Id: I2b5b13ff473a7aa8169cf2aecfea783c97f2d09a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/network/access')
-rw-r--r--src/network/access/qnetworkdiskcache.cpp4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp
index 6f02405c0f..7b17540417 100644
--- a/src/network/access/qnetworkdiskcache.cpp
+++ b/src/network/access/qnetworkdiskcache.cpp
@@ -273,14 +273,12 @@ void QNetworkDiskCachePrivate::storeItem(QCacheItem *cacheItem)
Q_ASSERT(!fileName.isEmpty());
if (QFile::exists(fileName)) {
- if (!QFile::remove(fileName)) {
+ if (!removeFile(fileName)) {
qWarning() << "QNetworkDiskCache: couldn't remove the cache file " << fileName;
return;
}
}
- if (currentCacheSize > 0)
- currentCacheSize += 1024 + cacheItem->size();
currentCacheSize = q->expire();
if (!cacheItem->file) {
QString templateName = tmpCacheFileName();