Changeset View
Changeset View
Standalone View
Standalone View
src/tools/balooctl/main.cpp
Show All 32 Lines | |||||
33 | #include <QTextStream> | 33 | #include <QTextStream> | ||
34 | #include <QFileInfo> | 34 | #include <QFileInfo> | ||
35 | #include <QLocale> | 35 | #include <QLocale> | ||
36 | 36 | | |||
37 | #include <QDBusMessage> | 37 | #include <QDBusMessage> | ||
38 | #include <QDBusConnection> | 38 | #include <QDBusConnection> | ||
39 | #include <QDBusConnectionInterface> | 39 | #include <QDBusConnectionInterface> | ||
40 | 40 | | |||
41 | #include <memory> | ||||
42 | | ||||
41 | #include "global.h" | 43 | #include "global.h" | ||
42 | #include "database.h" | 44 | #include "database.h" | ||
43 | #include "transaction.h" | 45 | #include "transaction.h" | ||
44 | #include "databasesize.h" | 46 | #include "databasesize.h" | ||
45 | 47 | | |||
46 | #include "indexer.h" | 48 | #include "indexer.h" | ||
47 | #include "indexerconfig.h" | 49 | #include "indexerconfig.h" | ||
48 | #include "idutils.h" | 50 | #include "idutils.h" | ||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Line(s) | 202 | if (command == QStringLiteral("index")) { | |||
204 | } | 206 | } | ||
205 | 207 | | |||
206 | Database *db = globalDatabaseInstance(); | 208 | Database *db = globalDatabaseInstance(); | ||
207 | if (!db->open(Database::ReadWriteDatabase)) { | 209 | if (!db->open(Database::ReadWriteDatabase)) { | ||
208 | out << "Baloo Index could not be opened\n"; | 210 | out << "Baloo Index could not be opened\n"; | ||
209 | return 1; | 211 | return 1; | ||
210 | } | 212 | } | ||
211 | 213 | | |||
212 | Transaction tr(db, Transaction::ReadWrite); | 214 | auto tr = std::unique_ptr<Transaction>(new Transaction(db, Transaction::ReadWrite)); | ||
213 | 215 | | |||
214 | for (int i = 1; i < parser.positionalArguments().size(); ++i) { | 216 | for (int i = 1; i < parser.positionalArguments().size(); ++i) { | ||
215 | const QString url = QFileInfo(parser.positionalArguments().at(i)).absoluteFilePath(); | 217 | const QString url = QFileInfo(parser.positionalArguments().at(i)).absoluteFilePath(); | ||
216 | quint64 id = filePathToId(QFile::encodeName(url)); | 218 | quint64 id = filePathToId(QFile::encodeName(url)); | ||
217 | if (id == 0) { | 219 | if (id == 0) { | ||
218 | out << "Could not stat file: " << url << endl; | 220 | out << "Could not stat file: " << url << endl; | ||
219 | continue; | 221 | continue; | ||
220 | } | 222 | } | ||
221 | if (tr.inPhaseOne(id)) { | 223 | if (tr->inPhaseOne(id)) { | ||
222 | out << "Skipping: " << url << " Reason: Already scheduled for indexing\n"; | 224 | out << "Skipping: " << url << " Reason: Already scheduled for indexing\n"; | ||
223 | continue; | 225 | continue; | ||
bruns: You are discarding the write transaction here withouth calling commit() or abort() | |||||
224 | } | 226 | } | ||
225 | if (!tr.documentData(id).isEmpty()) { | 227 | if (!tr->documentData(id).isEmpty()) { | ||
226 | out << "Skipping: " << url << " Reason: Already indexed\n"; | 228 | out << "Skipping: " << url << " Reason: Already indexed\n"; | ||
227 | continue; | 229 | continue; | ||
228 | } | 230 | } | ||
229 | Indexer indexer(url, &tr); | 231 | Indexer indexer(url, tr.get()); | ||
230 | out << "Indexing " << url << endl; | 232 | out << "Indexing " << url << endl; | ||
231 | indexer.index(); | 233 | indexer.index(); | ||
234 | if (i % 5 == 0) { | ||||
235 | tr->commit(); | ||||
236 | tr.reset(new Transaction(db, Transaction::ReadWrite)); | ||||
237 | } | ||||
232 | } | 238 | } | ||
233 | tr.commit(); | 239 | tr->commit(); | ||
234 | out << "File(s) indexed\n"; | 240 | out << "File(s) indexed\n"; | ||
235 | 241 | | |||
236 | return 0; | 242 | return 0; | ||
237 | } | 243 | } | ||
238 | 244 | | |||
239 | if (command == QStringLiteral("clear")) { | 245 | if (command == QStringLiteral("clear")) { | ||
240 | if (parser.positionalArguments().size() < 2) { | 246 | if (parser.positionalArguments().size() < 2) { | ||
241 | out << "Please enter a filename to index\n"; | 247 | out << "Please enter a filename to index\n"; | ||
242 | return 1; | 248 | return 1; | ||
243 | } | 249 | } | ||
244 | 250 | | |||
245 | Database *db = globalDatabaseInstance(); | 251 | Database *db = globalDatabaseInstance(); | ||
246 | if (!db->open(Database::ReadWriteDatabase)) { | 252 | if (!db->open(Database::ReadWriteDatabase)) { | ||
247 | out << "Baloo Index could not be opened\n"; | 253 | out << "Baloo Index could not be opened\n"; | ||
248 | return 1; | 254 | return 1; | ||
249 | } | 255 | } | ||
250 | 256 | | |||
251 | Transaction tr(db, Transaction::ReadWrite); | 257 | auto tr = std::unique_ptr<Transaction>(new Transaction(db, Transaction::ReadWrite)); | ||
252 | 258 | | |||
253 | for (int i = 1; i < parser.positionalArguments().size(); ++i) { | 259 | for (int i = 1; i < parser.positionalArguments().size(); ++i) { | ||
254 | const QString url = QFileInfo(parser.positionalArguments().at(i)).absoluteFilePath(); | 260 | const QString url = QFileInfo(parser.positionalArguments().at(i)).absoluteFilePath(); | ||
255 | quint64 id = filePathToId(QFile::encodeName(url)); | 261 | quint64 id = filePathToId(QFile::encodeName(url)); | ||
256 | if (id == 0) { | 262 | if (id == 0) { | ||
257 | out << "Could not stat file: " << url << endl; | 263 | out << "Could not stat file: " << url << endl; | ||
258 | continue; | 264 | continue; | ||
259 | } | 265 | } | ||
260 | if (tr.documentData(id).isEmpty()) { | 266 | if (tr->documentData(id).isEmpty()) { | ||
261 | out << "Skipping: " << url << " Reason: Not yet indexed\n"; | 267 | out << "Skipping: " << url << " Reason: Not yet indexed\n"; | ||
262 | continue; | 268 | continue; | ||
263 | } | 269 | } | ||
264 | Indexer indexer(url, &tr); | 270 | Indexer indexer(url, tr.get()); | ||
265 | out << "Clearing " << url << endl; | 271 | out << "Clearing " << url << endl; | ||
266 | tr.removeDocument(id); | 272 | tr->removeDocument(id); | ||
273 | if (i % 5 == 0) { | ||||
274 | tr->commit(); | ||||
275 | tr.reset(new Transaction(db, Transaction::ReadWrite)); | ||||
276 | } | ||||
267 | } | 277 | } | ||
268 | tr.commit(); | 278 | tr->commit(); | ||
269 | out << "File(s) cleared\n"; | 279 | out << "File(s) cleared\n"; | ||
270 | 280 | | |||
271 | return 0; | 281 | return 0; | ||
272 | } | 282 | } | ||
273 | 283 | | |||
274 | if (command == QStringLiteral("indexSize")) { | 284 | if (command == QStringLiteral("indexSize")) { | ||
275 | Database *db = globalDatabaseInstance(); | 285 | Database *db = globalDatabaseInstance(); | ||
276 | if (!db->open(Database::ReadOnlyDatabase)) { | 286 | if (!db->open(Database::ReadOnlyDatabase)) { | ||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |
You are discarding the write transaction here withouth calling commit() or abort()