mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-10 05:35:20 -05:00
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
This commit is contained in:
parent
96adddaab3
commit
0fcc84f463
1 changed files with 18 additions and 0 deletions
|
|
@ -240,6 +240,7 @@ bool HttpGet::getFile(const QUrl &url)
|
||||||
void HttpGet::getFileFinish()
|
void HttpGet::getFileFinish()
|
||||||
{
|
{
|
||||||
m_cachefile = m_cachedir.absolutePath() + "/rbutil-cache/" + m_hash;
|
m_cachefile = m_cachedir.absolutePath() + "/rbutil-cache/" + m_hash;
|
||||||
|
QString indexFile = m_cachedir.absolutePath() + "/rbutil-cache/cache.txt";
|
||||||
if(m_usecache) {
|
if(m_usecache) {
|
||||||
// check if the file is present in cache
|
// check if the file is present in cache
|
||||||
QFileInfo cachefile = QFileInfo(m_cachefile);
|
QFileInfo cachefile = QFileInfo(m_cachefile);
|
||||||
|
|
@ -279,6 +280,23 @@ void HttpGet::getFileFinish()
|
||||||
<< cachefile.lastModified();
|
<< cachefile.lastModified();
|
||||||
}
|
}
|
||||||
qDebug() << "[HTTP] Cache: caching as" << m_cachefile;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue