File indexing completed on 2024-04-14 03:49:46
0001 /* 0002 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #include "migrator.h" 0008 #include "fileindexerconfig.h" 0009 0010 #include <QFile> 0011 #include <QDir> 0012 0013 using namespace Baloo; 0014 0015 Migrator::Migrator(const QString& dbPath, FileIndexerConfig* config) 0016 : m_dbPath(dbPath) 0017 , m_config(config) 0018 { 0019 Q_ASSERT(!dbPath.isEmpty()); 0020 Q_ASSERT(!dbPath.endsWith(QLatin1Char('/'))); 0021 Q_ASSERT(config); 0022 } 0023 0024 /* 0025 * Changing this version number indicates that the old index should be deleted 0026 * and the indexing should be started from scratch. 0027 */ 0028 static int s_dbVersion = 2; 0029 0030 bool Migrator::migrationRequired() const 0031 { 0032 return m_config->databaseVersion() != s_dbVersion; 0033 } 0034 0035 void Migrator::migrate() 0036 { 0037 Q_ASSERT(migrationRequired()); 0038 0039 int dbVersion = m_config->databaseVersion(); 0040 if (dbVersion == 0 && QFile::exists(m_dbPath + QStringLiteral("/file"))) { 0041 QDir dir(m_dbPath + QStringLiteral("/file")); 0042 dir.removeRecursively(); 0043 } 0044 else if (QFile::exists(m_dbPath + QStringLiteral("/index"))) { 0045 QFile::remove(m_dbPath + QStringLiteral("/index")); 0046 QFile::remove(m_dbPath + QStringLiteral("/index-lock")); 0047 } 0048 0049 m_config->setDatabaseVersion(s_dbVersion); 0050 }