From 2bcc5f782dc9199da7ebfa8f661f673eb6c3de65 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sun, 6 Apr 2008 17:20:13 +0000 Subject: [PATCH] make sure cachefolder is existent when enabling it using setCache(bool). Fixes cache not working properly if the cache folder didn't exist. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16991 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/httpget.cpp | 31 ++++++++++++++++++++++--------- rbutil/rbutilqt/httpget.h | 1 + 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/rbutil/rbutilqt/httpget.cpp b/rbutil/rbutilqt/httpget.cpp index c1e541391b..e3742480ab 100644 --- a/rbutil/rbutilqt/httpget.cpp +++ b/rbutil/rbutilqt/httpget.cpp @@ -61,15 +61,8 @@ HttpGet::HttpGet(QObject *parent) void HttpGet::setCache(QDir d) { m_cachedir = d; - bool result = true; - - QString p = m_cachedir.absolutePath() + "/rbutil-cache"; - if(QFileInfo(m_cachedir.absolutePath()).isDir()) - { - if(!QFileInfo(p).isDir()) - result = m_cachedir.mkdir("rbutil-cache"); - } - else result = false; + bool result; + result = initializeCache(d); qDebug() << "HttpGet::setCache(QDir)" << d.absolutePath() << result; m_usecache = result; } @@ -79,6 +72,26 @@ void HttpGet::setCache(bool c) { qDebug() << "setCache(bool)" << c; m_usecache = c; + // make sure cache is initialized + if(c) + m_usecache = initializeCache(m_cachedir); +} + + +bool HttpGet::initializeCache(const QDir& d) +{ + bool result; + QString p = d.absolutePath() + "/rbutil-cache"; + if(QFileInfo(d.absolutePath()).isDir()) + { + if(!QFileInfo(p).isDir()) + result = d.mkdir("rbutil-cache"); + } + else + result = false; + + return result; + } diff --git a/rbutil/rbutilqt/httpget.h b/rbutil/rbutilqt/httpget.h index 79522f6e8f..3ff00b4d55 100644 --- a/rbutil/rbutilqt/httpget.h +++ b/rbutil/rbutilqt/httpget.h @@ -66,6 +66,7 @@ class HttpGet : public QObject void httpStarted(int); private: + bool initializeCache(const QDir&); QHttp http; //< download object QFile *outputFile; int response; //< http response