1 | /* |
2 | SPDX-FileCopyrightText: 2012-2015 Vishesh Handa <me@vhanda.in> |
3 | |
4 | SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL |
5 | */ |
6 | |
7 | #include <QFile> |
8 | |
9 | #include <KLocalizedString> |
10 | #include <QFileInfo> |
11 | #include <QTextStream> |
12 | |
13 | #include "database.h" |
14 | #include "global.h" |
15 | #include "transaction.h" |
16 | |
17 | #include "clearentry.h" |
18 | |
19 | using namespace Baloo; |
20 | |
21 | // ClearEntry Constructors |
22 | // Wraps Transaction, presuming ReadWrite access |
23 | |
24 | ClearEntry::ClearEntry(const Database &db, QTextStream &out) |
25 | : Transaction(db, TransactionType::ReadWrite) |
26 | , m_out(out) {}; |
27 | |
28 | ClearEntry::ClearEntry(Database *db, QTextStream &out) |
29 | : ClearEntry(*db, out) {}; |
30 | |
31 | // ClearEntry::clearEntryNow |
32 | // Removes the entry for the file from the index |
33 | // Done in the foreground, the user will have to wait until it's done |
34 | |
35 | bool ClearEntry::clearEntryNow(const QString &fileName) |
36 | { |
37 | const auto fileInfo = QFileInfo(fileName); |
38 | const QString canonicalPath = fileInfo.canonicalFilePath(); |
39 | quint64 id = filePathToId(filePath: QFile::encodeName(fileName: canonicalPath)); |
40 | |
41 | if (id) { |
42 | m_out << "Clearing " << canonicalPath << '\n'; |
43 | } else { |
44 | id = this->documentId(path: QFile::encodeName(fileName)); |
45 | if (id == 0) { |
46 | m_out << "File not found on filesystem or in DB: " << fileName << '\n'; |
47 | return false; |
48 | } else { |
49 | m_out << "File has been deleted, clearing from DB: " << fileName << '\n'; |
50 | } |
51 | } |
52 | |
53 | this->removeDocument(id); |
54 | return true; |
55 | } |
56 | |