aboutsummaryrefslogtreecommitdiff
path: root/src/leveldb/db/leveldbutil.cc
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2016-12-01 16:14:45 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2016-12-01 16:14:45 -0800
commit605d701471c3ee84682b0c149e41142d7cea95e7 (patch)
tree7a6af0e78ee2202f510686e9a3561c28829b8a4b /src/leveldb/db/leveldbutil.cc
parentdc6dee41f7cf2ba93fcd0fea7c157e4b2775d439 (diff)
parent634ad517037b319147816f1d112b066528e1724a (diff)
downloadbitcoin-605d701471c3ee84682b0c149e41142d7cea95e7.tar.xz
Merge in LevelDB 1.19 changes
Diffstat (limited to 'src/leveldb/db/leveldbutil.cc')
-rw-r--r--src/leveldb/db/leveldbutil.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/leveldb/db/leveldbutil.cc b/src/leveldb/db/leveldbutil.cc
new file mode 100644
index 0000000000..9f4b7dd70c
--- /dev/null
+++ b/src/leveldb/db/leveldbutil.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2012 The LevelDB Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file. See the AUTHORS file for names of contributors.
+
+#include <stdio.h>
+#include "leveldb/dumpfile.h"
+#include "leveldb/env.h"
+#include "leveldb/status.h"
+
+namespace leveldb {
+namespace {
+
+class StdoutPrinter : public WritableFile {
+ public:
+ virtual Status Append(const Slice& data) {
+ fwrite(data.data(), 1, data.size(), stdout);
+ return Status::OK();
+ }
+ virtual Status Close() { return Status::OK(); }
+ virtual Status Flush() { return Status::OK(); }
+ virtual Status Sync() { return Status::OK(); }
+};
+
+bool HandleDumpCommand(Env* env, char** files, int num) {
+ StdoutPrinter printer;
+ bool ok = true;
+ for (int i = 0; i < num; i++) {
+ Status s = DumpFile(env, files[i], &printer);
+ if (!s.ok()) {
+ fprintf(stderr, "%s\n", s.ToString().c_str());
+ ok = false;
+ }
+ }
+ return ok;
+}
+
+} // namespace
+} // namespace leveldb
+
+static void Usage() {
+ fprintf(
+ stderr,
+ "Usage: leveldbutil command...\n"
+ " dump files... -- dump contents of specified files\n"
+ );
+}
+
+int main(int argc, char** argv) {
+ leveldb::Env* env = leveldb::Env::Default();
+ bool ok = true;
+ if (argc < 2) {
+ Usage();
+ ok = false;
+ } else {
+ std::string command = argv[1];
+ if (command == "dump") {
+ ok = leveldb::HandleDumpCommand(env, argv+2, argc-2);
+ } else {
+ Usage();
+ ok = false;
+ }
+ }
+ return (ok ? 0 : 1);
+}