File fix-for-rename-bug-392793.patch of Package kf6-baloo
qt-bugs@ issue : None
Trolltech task ID : None
bugs.kde.org number : 392793
applied: no
author: Ignacio Serantes <kde@aynoa.net>
Renamed files and directories lost all File Name Terms.
--- a/src/file/metadatamover.cpp
+++ b/src/file/metadatamover.cpp
@@ -95,6 +95,23 @@ void MetadataMover::updateMetadata(Transaction* tr, const QString& from, const Q
quint64 parentId = tr->documentId(parentPath);
if (!parentId) {
qCDebug(BALOO) << "Parent directory not (yet) known, signaling newFile" << to;
+
+ auto previousSlash = toPath.lastIndexOf('/', toPath.size() - 2);
+ const QByteArray dirParentPath = toPath.left(previousSlash);
+ const quint64 dirParentId = tr->documentId(dirParentPath);
+
+ if (dirParentId) {
+ // Only if parent dir has Id.
+ Document doc;
+ TermGenerator tg(doc);
+ tg.indexFileNameText(QFile::decodeName(toPath.mid(previousSlash + 1, lastSlash - previousSlash - 1)));
+
+ doc.setId(id);
+ doc.setParentId(dirParentId);
+ doc.setUrl(toPath.left(lastSlash));
+ tr->replaceDocument(doc, DocumentUrl | FileNameTerms);
+ }
+
Q_EMIT movedWithoutData(QFile::decodeName(parentPath));
return;
}