9#include "metadatamover.h"
11#include "termgenerator.h"
12#include "transaction.h"
13#include "baloodebug.h"
19MetadataMover::MetadataMover(Database* db,
QObject* parent)
25MetadataMover::~MetadataMover()
29void MetadataMover::moveFileMetadata(
const QString& from,
const QString& to)
32 Q_ASSERT(!from.
isEmpty() && from != QLatin1String(
"/"));
33 Q_ASSERT(!to.
isEmpty() && to != QLatin1String(
"/"));
35 Transaction
tr(m_db, Transaction::ReadWrite);
39 removeMetadata(&
tr, to);
42 updateMetadata(&
tr, from, to);
47void MetadataMover::removeFileMetadata(
const QString& file)
49 Q_ASSERT(!file.
isEmpty() && file != QLatin1String(
"/"));
51 Transaction
tr(m_db, Transaction::ReadWrite);
52 removeMetadata(&
tr, file);
56void MetadataMover::removeMetadata(Transaction* tr,
const QString& url)
66 bool isDir = url.
endsWith(QLatin1Char(
'/'));
68 tr->removeDocument(
id);
70 tr->removeRecursively(
id);
76void MetadataMover::updateMetadata(Transaction *tr,
const QString &from,
const QString &_to)
78 qCDebug(BALOO) << from <<
"->" << _to;
85 auto normalizedFrom = from;
86 if (normalizedFrom.endsWith(QLatin1Char(
'/'))) {
87 normalizedFrom.chop(1);
91 quint64
id =
tr->documentId(fromPath);
93 qCDebug(BALOO) <<
"Document not (yet) known, signaling newFile" << to;
94 Q_EMIT movedWithoutData(to);
100 const QByteArray parentPath = toPath.
left(lastSlash + 1);
102 quint64 parentId =
tr->documentId(parentPath);
104 qCDebug(BALOO) <<
"Parent directory not (yet) known, signaling newFile" << to;
111 const QByteArray fileName = toPath.
mid(lastSlash + 1);
112 TermGenerator tg(doc);
116 doc.setParentId(parentId);
118 tr->replaceDocument(doc, DocumentUrl | FileNameTerms);
125#include "moc_metadatamover.cpp"
Implements storage for docIds without any associated data Instantiated for:
qsizetype lastIndexOf(QByteArrayView bv) const const
QByteArray left(qsizetype len) const const
QByteArray mid(qsizetype pos, qsizetype len) const const
QString decodeName(const QByteArray &localFileName)
QByteArray encodeName(const QString &fileName)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const