summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@wiredtiger.com>2014-06-02 12:26:49 +1000
committerMichael Cahill <michael.cahill@wiredtiger.com>2014-06-02 12:26:49 +1000
commit056c3a2fa8108cc124e19eff74ba950b8f39c4ca (patch)
tree3fa0259411b8ce6372e4cafc9c96d8a352b22ba5 /api
parent8cc6281a5eee7e390e33feaf3ea5cf7862f06841 (diff)
downloadmongo-056c3a2fa8108cc124e19eff74ba950b8f39c4ca.tar.gz
Implement DestroyDB in the LevelDB API, fix Open to optionally create the directory.
Diffstat (limited to 'api')
-rw-r--r--api/leveldb/leveldb_wt.cc19
1 files changed, 17 insertions, 2 deletions
diff --git a/api/leveldb/leveldb_wt.cc b/api/leveldb/leveldb_wt.cc
index 0c3661e034e..fe6b8f0ee26 100644
--- a/api/leveldb/leveldb_wt.cc
+++ b/api/leveldb/leveldb_wt.cc
@@ -5,6 +5,7 @@
* See the file LICENSE for redistribution information.
*/
#include "leveldb_wt.h"
+#include <sys/stat.h>
#include <sstream>
using leveldb::Cache;
@@ -126,7 +127,19 @@ Cache *NewLRUCache(size_t capacity) {
Status DestroyDB(const std::string& name, const Options& options) {
fprintf(stderr, "DestroyDB %s", name.c_str());
- return Status::NotSupported("sorry!");
+ WT_CONNECTION *conn;
+ int ret = ::wiredtiger_open(name.c_str(), NULL, NULL, &conn);
+ /* If the database cannot be opened, there is nothing to destroy. */
+ if (ret != 0)
+ return Status::OK();
+ WT_SESSION *session;
+ ret = conn->open_session(conn, NULL, NULL, &session);
+ assert(ret == 0);
+ ret = session->drop(session, WT_URI, "force");
+ assert(ret == 0);
+ ret = conn->close(conn, NULL);
+ assert(ret == 0);
+ return Status::OK();
}
Status RepairDB(const std::string& dbname, const Options& options) {
@@ -318,8 +331,10 @@ leveldb::DB::Open(const Options &options, const std::string &name, leveldb::DB *
{
// Build the wiredtiger_open config.
std::stringstream s_conn;
- if (options.create_if_missing)
+ if (options.create_if_missing) {
+ (void)mkdir(name.c_str(), 0777);
s_conn << "create,";
+ }
if (options.error_if_exists)
s_conn << "exclusive,";
if (options.compression == kSnappyCompression)