Baloo

migrator.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Vishesh Handa <[email protected]>
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 
13 using namespace Baloo;
14 
15 Migrator::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  */
28 static int s_dbVersion = 2;
29 
30 bool Migrator::migrationRequired() const
31 {
32  return m_config->databaseVersion() != s_dbVersion;
33 }
34 
35 void 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 }
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
bool remove()
bool exists() const const
Implements storage for docIds without any associated data Instantiated for:
Definition: coding.cpp:11
bool isEmpty() const const
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
KSharedConfigPtr config()
KIOFILEWIDGETS_EXPORT QString dir(const QString &fileClass)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:56:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.