From 6fcb97ad464a346663184b27d587668c59b54361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Nicole?= Date: Fri, 27 Jul 2018 13:40:15 +0200 Subject: Use Key API in SinkSH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Depends on D14289 - Fixes the `sinksh inspect …` command - Introduces `isValid`, `isValidInternal` and `isValidDisplay` static functions in Key, Identifier and Revision I still have to do a more extensive search for induced bugs in other commands Reviewers: cmollekopf Reviewed By: cmollekopf Tags: #sink Differential Revision: https://phabricator.kde.org/D14404 --- sinksh/syntax_modules/sink_inspect.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'sinksh/syntax_modules') diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index 7a41ef0..f9cc50a 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp @@ -41,6 +41,20 @@ namespace SinkInspect { +using Sink::Storage::Key; +using Sink::Storage::Identifier; + +QString parse(const QByteArray &bytes) +{ + if (Key::isValidInternal(bytes)) { + return Key::fromInternalByteArray(bytes).toDisplayString(); + } else if (Identifier::isValidInternal(bytes)) { + return Identifier::fromInternalByteArray(bytes).toDisplayString(); + } else { + return QString::fromUtf8(bytes); + } +} + bool inspect(const QStringList &args, State &state) { if (args.isEmpty()) { @@ -90,7 +104,7 @@ bool inspect(const QStringList &args, State &state) QSet uids; db.scan("", [&] (const QByteArray &key, const QByteArray &data) { - uids.insert(Sink::Storage::Key::fromInternalByteArray(key).identifier().toDisplayByteArray()); + uids.insert(Key::fromInternalByteArray(key).identifier().toDisplayByteArray()); return true; }, [&](const Sink::Storage::DataStore::Error &e) { @@ -187,13 +201,16 @@ bool inspect(const QStringList &args, State &state) auto count = db.scan(filter, [&] (const QByteArray &key, const QByteArray &data) { keySizeTotal += key.size(); valueSizeTotal += data.size(); + + const auto parsedKey = parse(key); + if (isMainDb) { Sink::EntityBuffer buffer(const_cast(data.data()), data.size()); if (!buffer.isValid()) { - state.printError("Read invalid buffer from disk: " + key); + state.printError("Read invalid buffer from disk: " + parsedKey); } else { const auto metadata = flatbuffers::GetRoot(buffer.metadataBuffer()); - state.printLine("Key: " + key + state.printLine("Key: " + parsedKey + " Operation: " + QString::number(metadata->operation()) + " Replay: " + (metadata->replayToSource() ? "true" : "false") + ((metadata->modifiedProperties() && metadata->modifiedProperties()->size() != 0) ? (" [" + Sink::BufferUtils::fromVector(*metadata->modifiedProperties()).join(", ")) + "]": "") @@ -201,7 +218,7 @@ bool inspect(const QStringList &args, State &state) ); } } else { - state.printLine("Key: " + key + "\tValue: " + QString::fromUtf8(data)); + state.printLine("Key: " + parsedKey + "\tValue: " + parse(data)); } return true; }, -- cgit v1.2.3