From ac6167cfa0ed1599fff27c15d19cc0829f5fab21 Mon Sep 17 00:00:00 2001 From: bluebrother Date: Wed, 14 Oct 2009 20:21:23 +0000 Subject: [PATCH] Add cache index file to HttpGet class to maintain a list of hash - file origin mappings. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23174 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/base/httpget.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/rbutil/rbutilqt/base/httpget.cpp b/rbutil/rbutilqt/base/httpget.cpp index e808a6381..a412cdf7d 100644 --- a/rbutil/rbutilqt/base/httpget.cpp +++ b/rbutil/rbutilqt/base/httpget.cpp @@ -240,6 +240,7 @@ bool HttpGet::getFile(const QUrl &url) void HttpGet::getFileFinish() { m_cachefile = m_cachedir.absolutePath() + "/rbutil-cache/" + m_hash; + QString indexFile = m_cachedir.absolutePath() + "/rbutil-cache/cache.txt"; if(m_usecache) { // check if the file is present in cache QFileInfo cachefile = QFileInfo(m_cachefile); @@ -279,6 +280,23 @@ void HttpGet::getFileFinish() << cachefile.lastModified(); } qDebug() << "[HTTP] Cache: caching as" << m_cachefile; + // update cache index file + QFile idxFile(indexFile); + idxFile.open(QIODevice::ReadOnly); + QByteArray currLine; + do { + QByteArray currLine = idxFile.readLine(1000); + if(currLine.startsWith(m_hash.toUtf8())) + break; + } while(!currLine.isEmpty()); + idxFile.close(); + if(currLine.isEmpty()) { + idxFile.open(QIODevice::Append); + QString outline = m_hash + "\t" + m_header.value("Host") + "\t" + + m_path + "\t" + m_query + "\n"; + idxFile.write(outline.toUtf8()); + idxFile.close(); + } } } -- 2.11.4.GIT