1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-13 20:39:57 +01:00

Bump cache version; put back in its proper place, and put in a better place in headless

This commit is contained in:
Jeff Mitchell 2012-04-06 18:06:50 -04:00
parent 9d88f16aa4
commit 514d399f6b
4 changed files with 35 additions and 14 deletions

View File

@ -44,7 +44,7 @@ TomahawkSettingsGui::~TomahawkSettingsGui()
QString
TomahawkSettingsGui::storageCacheLocation() const
{
return QDesktopServices::storageLocation( QDesktopServices::CacheLocation ) + "/InfoSystemCache/";
return QDesktopServices::storageLocation( QDesktopServices::CacheLocation );
}

View File

@ -42,7 +42,7 @@ namespace InfoSystem
InfoSystemCache::InfoSystemCache( QObject* parent )
: QObject( parent )
, m_cacheBaseDir( TomahawkSettings::instance()->storageCacheLocation() + "/InfoSystemCache/" )
, m_cacheVersion( 2 )
, m_cacheVersion( 3 )
{
tDebug() << Q_FUNC_INFO;
TomahawkSettings *s = TomahawkSettings::instance();
@ -73,6 +73,27 @@ InfoSystemCache::~InfoSystemCache()
tDebug() << Q_FUNC_INFO;
}
void
InfoSystemCache::performWipe( QString directory )
{
QDir dir;
for ( int i = InfoNoInfo; i <= InfoLastInfo; i++ )
{
InfoType type = (InfoType)(i);
const QString cacheDirName = directory + QString::number( (int)type );
QFileInfoList fileList = QDir( cacheDirName ).entryInfoList( QDir::Files | QDir::NoDotAndDotDot );
foreach ( QFileInfo file, fileList )
{
if ( !QFile::remove( file.canonicalFilePath() ) )
tLog() << "During upgrade, failed to remove cache file " << file.canonicalFilePath();
}
dir.rmdir( cacheDirName );
}
dir.rmdir( directory );
}
void
InfoSystemCache::doUpgrade( uint oldVersion, uint newVersion )
{
@ -82,17 +103,16 @@ InfoSystemCache::doUpgrade( uint oldVersion, uint newVersion )
{
qDebug() << Q_FUNC_INFO << "Wiping cache";
for ( int i = InfoNoInfo; i <= InfoLastInfo; i++ )
{
InfoType type = (InfoType)(i);
const QString cacheDirName = m_cacheBaseDir + QString::number( (int)type );
QFileInfoList fileList = QDir( cacheDirName ).entryInfoList( QDir::Files | QDir::NoDotAndDotDot );
foreach ( QFileInfo file, fileList )
{
if ( !QFile::remove( file.canonicalFilePath() ) )
tLog() << "During upgrade, failed to remove cache file " << file.canonicalFilePath();
}
}
performWipe( m_cacheBaseDir );
}
if ( oldVersion == 2 )
{
qDebug() << Q_FUNC_INFO << "Wiping cache";
performWipe( m_cacheBaseDir );
performWipe( m_cacheBaseDir + "/InfoSystemCache/" );
}
}

View File

@ -56,6 +56,7 @@ private slots:
private:
void notInCache( QObject *receiver, Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
void doUpgrade( uint oldVersion, uint newVersion );
void performWipe( QString directory );
const QString criteriaMd5( const Tomahawk::InfoSystem::InfoStringHash &criteria, Tomahawk::InfoSystem::InfoType type = Tomahawk::InfoSystem::InfoNoInfo ) const;
QString m_cacheBaseDir;

View File

@ -435,7 +435,7 @@ TomahawkSettings::setInfoSystemCacheVersion( uint version )
uint
TomahawkSettings::infoSystemCacheVersion() const
{
return value( "infosystemcacheversion", 0 ).toUInt();
return value( "infosystemcacheversion", 3 ).toUInt();
}