https://bugs.kde.org/show_bug.cgi?id=464517

--- Comment #5 from Fabian Vogt <fab...@ritter-vogt.de> ---
It's a bug in plasma-desktop's attica-kde plugin triggering a bug in
QNetworkDiskCache:

     const QString cacheDir =
QStandardPaths::writableLocation(QStandardPaths::CacheLocation) +
QStringLiteral("/attica");
     QNetworkDiskCache *cache = new QNetworkDiskCache(m_accessManager);
     QStorageInfo storageInfo(cacheDir);
     cache->setCacheDirectory(cacheDir);
     cache->setMaximumCacheSize(storageInfo.bytesTotal() / 1000);

QStorageInfo returns -1 there if the cache directory didn't exist yet.
QNetworkDiskCache happily accepts 0 as max size and eagerly deletes everything
it can on every occasion.

This happens in the worst possible spot, QNetworkDiskCachePrivate::storeItem:

void QNetworkDiskCachePrivate::storeItem(QCacheItem *cacheItem)
{
...
    currentCacheSize = q->expire();
    if (!cacheItem->file) {
        QString templateName = tmpCacheFileName();
        cacheItem->file = new QTemporaryFile(templateName, &cacheItem->data);
        if (cacheItem->file->open()) {
            cacheItem->writeHeader(cacheItem->file);
            cacheItem->writeCompressedData(cacheItem->file);
        }
    }

    if (cacheItem->file
        && cacheItem->file->isOpen()
        && cacheItem->file->error() == QFile::NoError) {
        cacheItem->file->setAutoRemove(false);
        // ### use atomic rename rather then remove & rename
        if (cacheItem->file->rename(fileName))
            currentCacheSize += cacheItem->file->size();
        else
            cacheItem->file->setAutoRemove(true);
    }

cacheItem->file is the temporary file with the cached contents. q->expire()
however notices that the cache is too big and deletes it, setting
cacheItem->file to nullptr. This unfortunately triggers the if block below,
which is only meant for compressed caches, which are backed by cacheItem->data
instead of cacheItem->file. The categories cache will not be compressed, which
means that cacheItem->data is empty and it writes no actual data into the new
file.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to