diff options
author | Minijackson <minijackson@riseup.net> | 2018-07-26 17:00:03 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-07-26 17:00:03 +0200 |
commit | 6c5d7a65899f3b322184628c2be68fd3f3fdd5da (patch) | |
tree | 2f28fea8c0f39f45b97e3277d75bfa457db7f939 /sinksh | |
parent | a49c078fde2597a05a6b9f6eb2fba5c7fa0b53c9 (diff) | |
download | sink-key-for-sinksh.tar.gz sink-key-for-sinksh.zip |
Parse Keys in SinkSH inspectkey-for-sinksh
Diffstat (limited to 'sinksh')
-rw-r--r-- | sinksh/syntax_modules/sink_inspect.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index 1b3d77c..646a8cc 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp | |||
@@ -43,6 +43,20 @@ | |||
43 | namespace SinkInspect | 43 | namespace SinkInspect |
44 | { | 44 | { |
45 | 45 | ||
46 | using Sink::Storage::Key; | ||
47 | using Sink::Storage::Identifier; | ||
48 | |||
49 | QString parse(const QByteArray &bytes) | ||
50 | { | ||
51 | if (Key::isValidInternal(bytes)) { | ||
52 | return Key::fromInternalByteArray(bytes).toDisplayString(); | ||
53 | } else if (Identifier::isValidInternal(bytes)) { | ||
54 | return Identifier::fromInternalByteArray(bytes).toDisplayString(); | ||
55 | } else { | ||
56 | return QString::fromUtf8(bytes); | ||
57 | } | ||
58 | } | ||
59 | |||
46 | bool inspect(const QStringList &args, State &state) | 60 | bool inspect(const QStringList &args, State &state) |
47 | { | 61 | { |
48 | if (args.isEmpty()) { | 62 | if (args.isEmpty()) { |
@@ -92,7 +106,7 @@ bool inspect(const QStringList &args, State &state) | |||
92 | 106 | ||
93 | QSet<QByteArray> uids; | 107 | QSet<QByteArray> uids; |
94 | db.scan("", [&] (const QByteArray &key, const QByteArray &data) { | 108 | db.scan("", [&] (const QByteArray &key, const QByteArray &data) { |
95 | uids.insert(Sink::Storage::Key::fromInternalByteArray(key).identifier().toDisplayByteArray()); | 109 | uids.insert(Key::fromInternalByteArray(key).identifier().toDisplayByteArray()); |
96 | return true; | 110 | return true; |
97 | }, | 111 | }, |
98 | [&](const Sink::Storage::DataStore::Error &e) { | 112 | [&](const Sink::Storage::DataStore::Error &e) { |
@@ -202,13 +216,16 @@ bool inspect(const QStringList &args, State &state) | |||
202 | auto count = db.scan(filter, [&] (const QByteArray &key, const QByteArray &data) { | 216 | auto count = db.scan(filter, [&] (const QByteArray &key, const QByteArray &data) { |
203 | keySizeTotal += key.size(); | 217 | keySizeTotal += key.size(); |
204 | valueSizeTotal += data.size(); | 218 | valueSizeTotal += data.size(); |
219 | |||
220 | const auto parsedKey = parse(key); | ||
221 | |||
205 | if (isMainDb) { | 222 | if (isMainDb) { |
206 | Sink::EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); | 223 | Sink::EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); |
207 | if (!buffer.isValid()) { | 224 | if (!buffer.isValid()) { |
208 | state.printError("Read invalid buffer from disk: " + key); | 225 | state.printError("Read invalid buffer from disk: " + parsedKey); |
209 | } else { | 226 | } else { |
210 | const auto metadata = flatbuffers::GetRoot<Sink::Metadata>(buffer.metadataBuffer()); | 227 | const auto metadata = flatbuffers::GetRoot<Sink::Metadata>(buffer.metadataBuffer()); |
211 | state.printLine("Key: " + key | 228 | state.printLine("Key: " + parsedKey |
212 | + " Operation: " + QString::number(metadata->operation()) | 229 | + " Operation: " + QString::number(metadata->operation()) |
213 | + " Replay: " + (metadata->replayToSource() ? "true" : "false") | 230 | + " Replay: " + (metadata->replayToSource() ? "true" : "false") |
214 | + ((metadata->modifiedProperties() && metadata->modifiedProperties()->size() != 0) ? (" [" + Sink::BufferUtils::fromVector(*metadata->modifiedProperties()).join(", ")) + "]": "") | 231 | + ((metadata->modifiedProperties() && metadata->modifiedProperties()->size() != 0) ? (" [" + Sink::BufferUtils::fromVector(*metadata->modifiedProperties()).join(", ")) + "]": "") |
@@ -216,7 +233,7 @@ bool inspect(const QStringList &args, State &state) | |||
216 | ); | 233 | ); |
217 | } | 234 | } |
218 | } else { | 235 | } else { |
219 | state.printLine("Key: " + key + "\tValue: " + QString::fromUtf8(data)); | 236 | state.printLine("Key: " + parsedKey + "\tValue: " + parse(data)); |
220 | } | 237 | } |
221 | return true; | 238 | return true; |
222 | }, | 239 | }, |