mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
Modify qHash/criteriamd5 algorithm to guarantee order of adding values
to the md5sum, since order matters in md5 and isn't guaranteed by default in a QHash. Requires a cache clear, which is done automatically.
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
#include <QtCore/QVariant>
|
#include <QtCore/QVariant>
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
|
#include <QtCore/QStringList>
|
||||||
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
|
||||||
@@ -197,10 +198,13 @@ private:
|
|||||||
inline uint qHash( Tomahawk::InfoSystem::InfoCriteriaHash hash )
|
inline uint qHash( Tomahawk::InfoSystem::InfoCriteriaHash hash )
|
||||||
{
|
{
|
||||||
QCryptographicHash md5( QCryptographicHash::Md5 );
|
QCryptographicHash md5( QCryptographicHash::Md5 );
|
||||||
foreach( QString key, hash.keys() )
|
QStringList keys = hash.keys();
|
||||||
|
keys.sort();
|
||||||
|
foreach( QString key, keys )
|
||||||
|
{
|
||||||
md5.addData( key.toUtf8() );
|
md5.addData( key.toUtf8() );
|
||||||
foreach( QString value, hash.values() )
|
md5.addData( hash[key].toUtf8() );
|
||||||
md5.addData( value.toUtf8() );
|
}
|
||||||
|
|
||||||
QString hexData = md5.result();
|
QString hexData = md5.result();
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@ namespace InfoSystem
|
|||||||
InfoSystemCache::InfoSystemCache( QObject* parent )
|
InfoSystemCache::InfoSystemCache( QObject* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_cacheBaseDir( QDesktopServices::storageLocation( QDesktopServices::CacheLocation ) + "/InfoSystemCache/" )
|
, m_cacheBaseDir( QDesktopServices::storageLocation( QDesktopServices::CacheLocation ) + "/InfoSystemCache/" )
|
||||||
, m_cacheVersion( 1 )
|
, m_cacheVersion( 2 )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ InfoSystemCache::doUpgrade( uint oldVersion, uint newVersion )
|
|||||||
{
|
{
|
||||||
Q_UNUSED( newVersion );
|
Q_UNUSED( newVersion );
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
if ( oldVersion == 0 )
|
if ( oldVersion == 0 || oldVersion == 1 )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Wiping cache";
|
qDebug() << Q_FUNC_INFO << "Wiping cache";
|
||||||
|
|
||||||
@@ -274,14 +274,17 @@ InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteri
|
|||||||
const QString
|
const QString
|
||||||
InfoSystemCache::criteriaMd5( const Tomahawk::InfoSystem::InfoCriteriaHash &criteria, Tomahawk::InfoSystem::InfoType type ) const
|
InfoSystemCache::criteriaMd5( const Tomahawk::InfoSystem::InfoCriteriaHash &criteria, Tomahawk::InfoSystem::InfoType type ) const
|
||||||
{
|
{
|
||||||
QCryptographicHash hash( QCryptographicHash::Md5 );
|
QCryptographicHash md5( QCryptographicHash::Md5 );
|
||||||
foreach( QString key, criteria.keys() )
|
QStringList keys = criteria.keys();
|
||||||
hash.addData( key.toUtf8() );
|
keys.sort();
|
||||||
foreach( QString value, criteria.values() )
|
foreach( QString key, keys )
|
||||||
hash.addData( value.toUtf8() );
|
{
|
||||||
|
md5.addData( key.toUtf8() );
|
||||||
|
md5.addData( criteria[key].toUtf8() );
|
||||||
|
}
|
||||||
if ( type != Tomahawk::InfoSystem::InfoNoInfo )
|
if ( type != Tomahawk::InfoSystem::InfoNoInfo )
|
||||||
hash.addData( QString::number( (int)type ).toUtf8() );
|
md5.addData( QString::number( (int)type ).toUtf8() );
|
||||||
return hash.result().toHex();
|
return md5.result().toHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user