mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 02:42:55 +00:00
a bit more collision-resistant QNetworkDiskCache filenames
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
2cfffe4383
commit
bf506fa473
2 changed files with 7 additions and 7 deletions
|
@ -37,7 +37,7 @@
|
|||
|
||||
#define CACHE_POSTFIX QLatin1String(".d")
|
||||
#define PREPARED_SLASH QLatin1String("prepared/")
|
||||
#define CACHE_VERSION 8
|
||||
#define CACHE_VERSION 9
|
||||
#define DATA_DIR QLatin1String("data")
|
||||
|
||||
#define MAX_COMPRESSION_SIZE (1024 * 1024 * 3)
|
||||
|
@ -572,8 +572,8 @@ QString QNetworkDiskCachePrivate::uniqueFileName(const QUrl &url)
|
|||
|
||||
QByteArray hash = QCryptographicHash::hash(cleanUrl.toEncoded(), QCryptographicHash::Sha1);
|
||||
// convert sha1 to base36 form and return first 8 bytes for use as string
|
||||
QByteArray id = QByteArray::number(*(qlonglong*)hash.data(), 36).left(8);
|
||||
// generates <one-char subdir>/<8-char filname.d>
|
||||
QByteArray id = QByteArray::number(*(qlonglong*)hash.data(), 36).left(10);
|
||||
// generates <one-char subdir>/<10-char filname.d>
|
||||
uint code = (uint)id.at(id.length()-1) % 16;
|
||||
QString pathFragment = QString::number(code, 16) + QLatin1Char('/')
|
||||
+ QLatin1String(id) + CACHE_POSTFIX;
|
||||
|
@ -584,7 +584,7 @@ QString QNetworkDiskCachePrivate::uniqueFileName(const QUrl &url)
|
|||
QString QNetworkDiskCachePrivate::tmpCacheFileName() const
|
||||
{
|
||||
//The subdirectory is presumed to be already read for use.
|
||||
return cacheDirectory + PREPARED_SLASH + QLatin1String("XXXXXX") + CACHE_POSTFIX;
|
||||
return cacheDirectory + PREPARED_SLASH + QLatin1String("XXXXXXXXXX") + CACHE_POSTFIX;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -273,7 +273,7 @@ void tst_QNetworkDiskCache::clear()
|
|||
QCOMPARE(countFiles(cacheDirectory).count(), NUM_SUBDIRECTORIES + 2);
|
||||
|
||||
// don't delete files that it didn't create
|
||||
QTemporaryFile file(cacheDirectory + "/XXXXXX");
|
||||
QTemporaryFile file(cacheDirectory + "/XXXXXXXXXX");
|
||||
if (file.open()) {
|
||||
QCOMPARE(countFiles(cacheDirectory).count(), NUM_SUBDIRECTORIES + 3);
|
||||
cache.clear();
|
||||
|
@ -436,7 +436,7 @@ void tst_QNetworkDiskCache::fileMetaData()
|
|||
}
|
||||
}
|
||||
|
||||
QTemporaryFile file(cacheDirectory + "/qt_temp.XXXXXX");
|
||||
QTemporaryFile file(cacheDirectory + "/qt_temp.XXXXXXXXXX");
|
||||
if (file.open()) {
|
||||
QNetworkCacheMetaData metaData = cache.call_fileMetaData(file.fileName());
|
||||
QVERIFY(!metaData.isValid());
|
||||
|
@ -504,7 +504,7 @@ void tst_QNetworkDiskCache::oldCacheVersionFile()
|
|||
if (pass == 0) {
|
||||
QString name;
|
||||
{
|
||||
QTemporaryFile file(cache.cacheDirectory() + "/XXXXXX.d");
|
||||
QTemporaryFile file(cache.cacheDirectory() + "/XXXXXXXXXX.d");
|
||||
file.setAutoRemove(false);
|
||||
QVERIFY(file.open());
|
||||
QDataStream out(&file);
|
||||
|
|
Loading…
Add table
Reference in a new issue