|
15 | 15 | #include <memenv.h>
|
16 | 16 | #include <stdint.h>
|
17 | 17 |
|
18 |
| -void HandleError(const leveldb::Status& status) |
19 |
| -{ |
20 |
| - if (status.ok()) |
21 |
| - return; |
22 |
| - LogPrintf("%s\n", status.ToString()); |
23 |
| - if (status.IsCorruption()) |
24 |
| - throw dbwrapper_error("Database corrupted"); |
25 |
| - if (status.IsIOError()) |
26 |
| - throw dbwrapper_error("Database I/O error"); |
27 |
| - if (status.IsNotFound()) |
28 |
| - throw dbwrapper_error("Database entry missing"); |
29 |
| - throw dbwrapper_error("Unknown database error"); |
30 |
| -} |
31 |
| - |
32 | 18 | static leveldb::Options GetOptions(size_t nCacheSize)
|
33 | 19 | {
|
34 | 20 | leveldb::Options options;
|
@@ -61,13 +47,13 @@ CDBWrapper::CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, b
|
61 | 47 | if (fWipe) {
|
62 | 48 | LogPrintf("Wiping LevelDB in %s\n", path.string());
|
63 | 49 | leveldb::Status result = leveldb::DestroyDB(path.string(), options);
|
64 |
| - HandleError(result); |
| 50 | + dbwrapper_private::HandleError(result); |
65 | 51 | }
|
66 | 52 | TryCreateDirectory(path);
|
67 | 53 | LogPrintf("Opening LevelDB in %s\n", path.string());
|
68 | 54 | }
|
69 | 55 | leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
|
70 |
| - HandleError(status); |
| 56 | + dbwrapper_private::HandleError(status); |
71 | 57 | LogPrintf("Opened LevelDB successfully\n");
|
72 | 58 |
|
73 | 59 | // The base-case obfuscation key, which is a noop.
|
@@ -105,7 +91,7 @@ CDBWrapper::~CDBWrapper()
|
105 | 91 | bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync)
|
106 | 92 | {
|
107 | 93 | leveldb::Status status = pdb->Write(fSync ? syncoptions : writeoptions, &batch.batch);
|
108 |
| - HandleError(status); |
| 94 | + dbwrapper_private::HandleError(status); |
109 | 95 | return true;
|
110 | 96 | }
|
111 | 97 |
|
@@ -143,6 +129,20 @@ void CDBIterator::Next() { piter->Next(); }
|
143 | 129 |
|
144 | 130 | namespace dbwrapper_private {
|
145 | 131 |
|
| 132 | +void HandleError(const leveldb::Status& status) |
| 133 | +{ |
| 134 | + if (status.ok()) |
| 135 | + return; |
| 136 | + LogPrintf("%s\n", status.ToString()); |
| 137 | + if (status.IsCorruption()) |
| 138 | + throw dbwrapper_error("Database corrupted"); |
| 139 | + if (status.IsIOError()) |
| 140 | + throw dbwrapper_error("Database I/O error"); |
| 141 | + if (status.IsNotFound()) |
| 142 | + throw dbwrapper_error("Database entry missing"); |
| 143 | + throw dbwrapper_error("Unknown database error"); |
| 144 | +} |
| 145 | + |
146 | 146 | const std::vector<unsigned char>& GetObfuscateKey(const CDBWrapper &w)
|
147 | 147 | {
|
148 | 148 | return w.obfuscate_key;
|
|
0 commit comments