You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
![]()
12 years ago
|
// 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>
|
||
![]()
10 years ago
|
#include "leveldb/dumpfile.h"
|
||
![]()
12 years ago
|
#include "leveldb/env.h"
|
||
|
#include "leveldb/status.h"
|
||
|
|
||
|
namespace leveldb {
|
||
|
namespace {
|
||
|
|
||
![]()
10 years ago
|
class StdoutPrinter : public WritableFile {
|
||
![]()
12 years ago
|
public:
|
||
![]()
10 years ago
|
virtual Status Append(const Slice& data) {
|
||
|
fwrite(data.data(), 1, data.size(), stdout);
|
||
|
return Status::OK();
|
||
![]()
12 years ago
|
}
|
||
![]()
10 years ago
|
virtual Status Close() { return Status::OK(); }
|
||
|
virtual Status Flush() { return Status::OK(); }
|
||
|
virtual Status Sync() { return Status::OK(); }
|
||
![]()
12 years ago
|
};
|
||
|
|
||
|
bool HandleDumpCommand(Env* env, char** files, int num) {
|
||
![]()
10 years ago
|
StdoutPrinter printer;
|
||
![]()
12 years ago
|
bool ok = true;
|
||
|
for (int i = 0; i < num; i++) {
|
||
![]()
10 years ago
|
Status s = DumpFile(env, files[i], &printer);
|
||
|
if (!s.ok()) {
|
||
|
fprintf(stderr, "%s\n", s.ToString().c_str());
|
||
|
ok = false;
|
||
|
}
|
||
![]()
12 years ago
|
}
|
||
|
return ok;
|
||
|
}
|
||
|
|
||
![]()
10 years ago
|
} // namespace
|
||
![]()
12 years ago
|
} // 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);
|
||
|
}
|