From 4603487f087fc9d15b3919d55d651e434fa3cc6a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 7 Jan 2017 18:58:19 +0100 Subject: No more normalizedPath --- common/synchronizerstore.cpp | 29 +++++++++++++++++++++++++++++ common/synchronizerstore.h | 4 ++++ 2 files changed, 33 insertions(+) (limited to 'common') diff --git a/common/synchronizerstore.cpp b/common/synchronizerstore.cpp index fcb3ed0..a9da2fe 100644 --- a/common/synchronizerstore.cpp +++ b/common/synchronizerstore.cpp @@ -54,6 +54,10 @@ void SynchronizerStore::updateRemoteId(const QByteArray &bufferType, const QByte QByteArray SynchronizerStore::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId) { + if (remoteId.isEmpty()) { + SinkWarning() << "Cannot resolve empty remote id for type: " << bufferType; + return QByteArray(); + } // Lookup local id for remote id, or insert a new pair otherwise Index index("rid.mapping." + bufferType, mTransaction); QByteArray sinkId = index.lookup(remoteId); @@ -96,8 +100,33 @@ QByteArray SynchronizerStore::readValue(const QByteArray &key) return value; } +QByteArray SynchronizerStore::readValue(const QByteArray &prefix, const QByteArray &key) +{ + return readValue(prefix + key); +} + void SynchronizerStore::writeValue(const QByteArray &key, const QByteArray &value) { mTransaction.openDatabase("values").write(key, value); } +void SynchronizerStore::writeValue(const QByteArray &prefix, const QByteArray &key, const QByteArray &value) +{ + writeValue(prefix + key, value); +} + +void SynchronizerStore::removeValue(const QByteArray &prefix, const QByteArray &key) +{ + mTransaction.openDatabase("values").remove(prefix + key, [&](const Sink::Storage::DataStore::Error &error) { + SinkWarning() << "Failed to remove the value: " << prefix + key << error; + }); +} + +void SynchronizerStore::removePrefix(const QByteArray &prefix) +{ + //FIXME remove all values matching prefix + // mTransaction.openDatabase("values").remove(prefix, [](const Sink::Storage::DataStore::Error &) { + // //Ignore errors because we may not find the value + // }); +} + diff --git a/common/synchronizerstore.h b/common/synchronizerstore.h index be33562..8aef68e 100644 --- a/common/synchronizerstore.h +++ b/common/synchronizerstore.h @@ -56,8 +56,12 @@ public: QByteArray resolveLocalId(const QByteArray &bufferType, const QByteArray &localId); QByteArrayList resolveLocalIds(const QByteArray &bufferType, const QByteArrayList &localId); + void removePrefix(const QByteArray &prefix); + void removeValue(const QByteArray &prefix, const QByteArray &key); QByteArray readValue(const QByteArray &key); + QByteArray readValue(const QByteArray &prefix, const QByteArray &key); void writeValue(const QByteArray &key, const QByteArray &value); + void writeValue(const QByteArray &prefix, const QByteArray &key, const QByteArray &value); private: Sink::Storage::DataStore::Transaction &mTransaction; -- cgit v1.2.3