From c9fa91936a96d3999186e2850599034a24b49814 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 18 Apr 2016 13:46:45 -0700 Subject: [PATCH] Cleanup disk cache io device --- libraries/networking/src/AssetUtils.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/AssetUtils.cpp b/libraries/networking/src/AssetUtils.cpp index e25f357fcc..c505d108e5 100644 --- a/libraries/networking/src/AssetUtils.cpp +++ b/libraries/networking/src/AssetUtils.cpp @@ -11,6 +11,8 @@ #include "AssetUtils.h" +#include + #include #include @@ -29,12 +31,15 @@ QByteArray hashData(const QByteArray& data) { QByteArray loadFromCache(const QUrl& url) { if (auto cache = NetworkAccessManager::getInstance().cache()) { - if (auto ioDevice = cache->data(url)) { + + // caller is responsible for the deletion of the ioDevice, hence the unique_ptr + if (auto ioDevice = std::unique_ptr(cache->data(url))) { qCDebug(asset_client) << url.toDisplayString() << "loaded from disk cache."; return ioDevice->readAll(); } else { qCDebug(asset_client) << url.toDisplayString() << "not in disk cache"; } + } else { qCWarning(asset_client) << "No disk cache to load assets from."; } @@ -49,7 +54,8 @@ bool saveToCache(const QUrl& url, const QByteArray& file) { metaData.setSaveToDisk(true); metaData.setLastModified(QDateTime::currentDateTime()); metaData.setExpirationDate(QDateTime()); // Never expires - + + // ioDevice is managed by the cache and should either be passed back to insert or remove! if (auto ioDevice = cache->prepare(metaData)) { ioDevice->write(file); cache->insert(ioDevice);