Changeset View
Changeset View
Standalone View
Standalone View
src/file/indexcleaner.cpp
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU Lesser General Public | 14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; if not, write to the Free Software | 15 | * License along with this library; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
17 | * | 17 | * | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "indexcleaner.h" | 20 | #include "indexcleaner.h" | ||
21 | #include "fileindexerconfig.h" | 21 | #include "fileindexerconfig.h" | ||
22 | #include "storagedevices.h" | ||||
22 | 23 | | |||
23 | #include "database.h" | 24 | #include "database.h" | ||
24 | #include "transaction.h" | 25 | #include "transaction.h" | ||
25 | #include "idutils.h" | 26 | #include "idutils.h" | ||
26 | 27 | | |||
27 | #include <QDebug> | 28 | #include <QDebug> | ||
28 | #include <QFile> | 29 | #include <QFile> | ||
29 | #include <QMimeDatabase> | 30 | #include <QMimeDatabase> | ||
30 | 31 | | |||
31 | using namespace Baloo; | 32 | using namespace Baloo; | ||
32 | 33 | | |||
33 | IndexCleaner::IndexCleaner(Database* db, FileIndexerConfig* config) | 34 | IndexCleaner::IndexCleaner(Database* db, FileIndexerConfig* config) | ||
34 | : m_db(db) | 35 | : m_db(db) | ||
35 | , m_config(config) | 36 | , m_config(config) | ||
36 | { | 37 | { | ||
37 | Q_ASSERT(db); | 38 | Q_ASSERT(db); | ||
38 | Q_ASSERT(config); | 39 | Q_ASSERT(config); | ||
39 | } | 40 | } | ||
40 | 41 | | |||
41 | void IndexCleaner::run() | 42 | void IndexCleaner::run() | ||
42 | { | 43 | { | ||
43 | QMimeDatabase mimeDb; | 44 | QMimeDatabase mimeDb; | ||
michaelh: Unrelated whitespace change | |||||
44 | | ||||
45 | Transaction tr(m_db, Transaction::ReadWrite); | 45 | Transaction tr(m_db, Transaction::ReadWrite); | ||
46 | StorageDevices* devices = new StorageDevices(this); | ||||
46 | 47 | | |||
47 | auto shouldDelete = [&](quint64 id) { | 48 | auto shouldDelete = [&](quint64 id) { | ||
48 | if (!id) { | 49 | if (!id) { | ||
49 | return false; | 50 | return false; | ||
50 | } | 51 | } | ||
51 | 52 | | |||
52 | QString url = tr.documentUrl(id); | 53 | QString url = tr.documentUrl(id); | ||
53 | 54 | | |||
Show All 12 Lines | |||||
66 | if (!m_config->shouldMimeTypeBeIndexed(mimetype)) { | 67 | if (!m_config->shouldMimeTypeBeIndexed(mimetype)) { | ||
67 | qDebug() << "mimetype should not be indexed: " << url << mimetype; | 68 | qDebug() << "mimetype should not be indexed: " << url << mimetype; | ||
68 | return true; | 69 | return true; | ||
69 | } | 70 | } | ||
70 | 71 | | |||
71 | return false; | 72 | return false; | ||
72 | }; | 73 | }; | ||
73 | 74 | | |||
75 | for (const auto& device: devices->allMedia()) { | ||||
76 | if (!device.isMounted()) { | ||||
77 | qDebug() << "skipping device:" << device.udi(); | ||||
78 | } else { | ||||
74 | for (const QString& folder : m_config->includeFolders()) { | 79 | for (const QString& folder : m_config->includeFolders()) { | ||
80 | if (folder.startsWith(device.mountPath() + "/")) { | ||||
You can use QStringLiteral("%1/").arg(device.mountPath()) here and maybe define it outside the loop michaelh: You can use `QStringLiteral("%1/").arg(device.mountPath())` here and maybe define it outside… | |||||
75 | quint64 id = filePathToId(QFile::encodeName(folder)); | 81 | quint64 id = filePathToId(QFile::encodeName(folder)); | ||
bruns: Undesired detach | |||||
smithjd: Same as above. | |||||
76 | tr.removeRecursively(id, shouldDelete); | 82 | tr.removeRecursively(id, shouldDelete); | ||
77 | } | 83 | } | ||
84 | } | ||||
85 | } | ||||
bruns: Undesired detach | |||||
This example will also detach with or without a const intermediate.
smithjd: This example will also detach with or without a const intermediate.
> ...returning a copy… | |||||
No, if done correctly, it will not detach. Try to understand the linked article. bruns: No, if done correctly, it will not detach.
For iterating, you need a readonly copy of the… | |||||
86 | } | ||||
78 | tr.commit(); | 87 | tr.commit(); | ||
79 | 88 | | |||
80 | Q_EMIT done(); | 89 | Q_EMIT done(); | ||
81 | } | 90 | } |
Unrelated whitespace change