mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-25 02:09:48 +01: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:
parent
43a1b38a49
commit
e79604b598
@ -29,6 +29,7 @@
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QThread>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
@ -197,10 +198,13 @@ private:
|
||||
inline uint qHash( Tomahawk::InfoSystem::InfoCriteriaHash hash )
|
||||
{
|
||||
QCryptographicHash md5( QCryptographicHash::Md5 );
|
||||
foreach( QString key, hash.keys() )
|
||||
QStringList keys = hash.keys();
|
||||
keys.sort();
|
||||
foreach( QString key, keys )
|
||||
{
|
||||
md5.addData( key.toUtf8() );
|
||||
foreach( QString value, hash.values() )
|
||||
md5.addData( value.toUtf8() );
|
||||
md5.addData( hash[key].toUtf8() );
|
||||
}
|
||||
|
||||
QString hexData = md5.result();
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace InfoSystem
|
||||
InfoSystemCache::InfoSystemCache( QObject* parent )
|
||||
: QObject( parent )
|
||||
, m_cacheBaseDir( QDesktopServices::storageLocation( QDesktopServices::CacheLocation ) + "/InfoSystemCache/" )
|
||||
, m_cacheVersion( 1 )
|
||||
, m_cacheVersion( 2 )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
@ -73,7 +73,7 @@ InfoSystemCache::doUpgrade( uint oldVersion, uint newVersion )
|
||||
{
|
||||
Q_UNUSED( newVersion );
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
if ( oldVersion == 0 )
|
||||
if ( oldVersion == 0 || oldVersion == 1 )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Wiping cache";
|
||||
|
||||
@ -274,14 +274,17 @@ InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteri
|
||||
const QString
|
||||
InfoSystemCache::criteriaMd5( const Tomahawk::InfoSystem::InfoCriteriaHash &criteria, Tomahawk::InfoSystem::InfoType type ) const
|
||||
{
|
||||
QCryptographicHash hash( QCryptographicHash::Md5 );
|
||||
foreach( QString key, criteria.keys() )
|
||||
hash.addData( key.toUtf8() );
|
||||
foreach( QString value, criteria.values() )
|
||||
hash.addData( value.toUtf8() );
|
||||
QCryptographicHash md5( QCryptographicHash::Md5 );
|
||||
QStringList keys = criteria.keys();
|
||||
keys.sort();
|
||||
foreach( QString key, keys )
|
||||
{
|
||||
md5.addData( key.toUtf8() );
|
||||
md5.addData( criteria[key].toUtf8() );
|
||||
}
|
||||
if ( type != Tomahawk::InfoSystem::InfoNoInfo )
|
||||
hash.addData( QString::number( (int)type ).toUtf8() );
|
||||
return hash.result().toHex();
|
||||
md5.addData( QString::number( (int)type ).toUtf8() );
|
||||
return md5.result().toHex();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user