Baloo

migrator.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include "migrator.h"
8#include "fileindexerconfig.h"
9
10#include <QFile>
11#include <QDir>
12
13using namespace Baloo;
14
15Migrator::Migrator(const QString& dbPath, FileIndexerConfig* config)
16 : m_dbPath(dbPath)
17 , m_config(config)
18{
19 Q_ASSERT(!dbPath.isEmpty());
20 Q_ASSERT(!dbPath.endsWith(QLatin1Char('/')));
21 Q_ASSERT(config);
22}
23
24/*
25 * Changing this version number indicates that the old index should be deleted
26 * and the indexing should be started from scratch.
27 */
28static int s_dbVersion = 2;
29
30bool Migrator::migrationRequired() const
31{
32 return m_config->databaseVersion() != s_dbVersion;
33}
34
35void Migrator::migrate()
36{
37 Q_ASSERT(migrationRequired());
38
39 int dbVersion = m_config->databaseVersion();
40 if (dbVersion == 0 && QFile::exists(m_dbPath + QStringLiteral("/file"))) {
41 QDir dir(m_dbPath + QStringLiteral("/file"));
42 dir.removeRecursively();
43 }
44 else if (QFile::exists(m_dbPath + QStringLiteral("/index"))) {
45 QFile::remove(m_dbPath + QStringLiteral("/index"));
46 QFile::remove(m_dbPath + QStringLiteral("/index-lock"));
47 }
48
49 m_config->setDatabaseVersion(s_dbVersion);
50}
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
int databaseVersion() const
Returns the internal version number of the Baloo database.
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
KIOCORE_EXPORT QString dir(const QString &fileClass)
bool exists() const const
bool remove()
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.