Commit 07cc531b authored by Bernie Innocenti's avatar Bernie Innocenti 🕶
Browse files

Don't crash when directories are created, renemed or chmodded

BUG: 435161
parent 72d67bef
Pipeline #105997 passed with stage
in 2 minutes and 7 seconds
......@@ -15,6 +15,8 @@
# include <QFileInfo>
#endif
#include <QString>
namespace Baloo {
inline quint64 devIdAndInodeToId(quint32 devId, quint32 inode)
......@@ -99,6 +101,18 @@ inline void sortedIdRemove(T& vec, const V& id)
}
}
/**
* Similar to QFileInfo::fileName(), but handles trailing slashes in paths
* (which are always present on directory names).
*/
inline QString getFileName(const QString& path) {
int end = -1;
if (path.endsWith(QLatin1Char('/'))) {
// Skip the last character.
end = -2;
}
return path.mid(path.lastIndexOf(QLatin1Char('/'), end) + 1, end);
}
}
......
......@@ -77,8 +77,6 @@ void MetadataMover::updateMetadata(Transaction* tr, const QString& from, const Q
{
qCDebug(BALOO) << from << "->" << to;
Q_ASSERT(!from.isEmpty() && !to.isEmpty());
Q_ASSERT(from[from.size()-1] != QLatin1Char('/'));
Q_ASSERT(to[to.size()-1] != QLatin1Char('/'));
const QByteArray fromPath = QFile::encodeName(from);
quint64 id = tr->documentId(fromPath);
......
......@@ -38,9 +38,7 @@ void ModifiedFileIndexer::run()
Transaction tr(m_db, Transaction::ReadWrite);
for (const QString& filePath : std::as_const(m_files)) {
Q_ASSERT(!filePath.endsWith(QLatin1Char('/')));
QString fileName = filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1);
QString fileName = getFileName(filePath);
if (!m_config->shouldFileBeIndexed(fileName)) {
continue;
}
......
......@@ -35,8 +35,6 @@ void NewFileIndexer::run()
Transaction tr(m_db, Transaction::ReadWrite);
for (const QString& filePath : std::as_const(m_files)) {
Q_ASSERT(!filePath.endsWith(QLatin1Char('/')));
QString mimetype;
QFileInfo fileInfo(filePath);
......@@ -51,7 +49,7 @@ void NewFileIndexer::run()
mimetype = QStringLiteral("inode/directory");
} else {
QString fileName = filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1);
QString fileName = getFileName(filePath);
if (!m_config->shouldFileBeIndexed(fileName)) {
continue;
}
......
......@@ -34,9 +34,7 @@ void XAttrIndexer::run()
Transaction tr(m_db, Transaction::ReadWrite);
for (const QString& filePath : std::as_const(m_files)) {
Q_ASSERT(!filePath.endsWith(QLatin1Char('/')));
QString fileName = filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1);
QString fileName = getFileName(filePath);
if (!m_config->shouldFileBeIndexed(fileName)) {
continue;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment