|
@@ -210,22 +210,13 @@ inline static LSUP_rc lookup_2bound(
|
|
|
MDBIterator *it, size_t *ct);
|
|
|
inline static LSUP_rc lookup_3bound(
|
|
|
MDBStore *store, MDBIterator *it, size_t *ct);
|
|
|
-
|
|
|
-inline static int check_txn_open(MDB_txn *txn, bool write);
|
|
|
-*/
|
|
|
-
|
|
|
-static int unlink_cb(
|
|
|
- const char *fpath, const struct stat *sb,
|
|
|
- int typeflag, struct FTW *ftwbuf);
|
|
|
-static int rmrf(char *path);
|
|
|
-*/
|
|
|
|
|
|
|
|
|
* API.
|
|
|
*/
|
|
|
|
|
|
LSUP_rc
|
|
|
-LSUP_mdbstore_setup(char **path)
|
|
|
+LSUP_mdbstore_setup(char **path, bool clear)
|
|
|
{
|
|
|
int rc;
|
|
|
|
|
@@ -244,15 +235,12 @@ LSUP_mdbstore_setup(char **path)
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
if (clear) {
|
|
|
- rmrf(*path);
|
|
|
- if (mkdir(*path, ENV_DIR_MODE) != 0) abort();
|
|
|
+ rm_r (*path);
|
|
|
+ if (mkdir(*path, ENV_DIR_MODE) != 0) return LSUP_IO_ERR;
|
|
|
}
|
|
|
- */
|
|
|
|
|
|
- if (mkdir_p(*path, ENV_DIR_MODE) != 0) abort();
|
|
|
+ if (mkdir_p(*path, ENV_DIR_MODE) != 0) return LSUP_IO_ERR;
|
|
|
|
|
|
|
|
|
MDB_env *env;
|
|
@@ -280,12 +268,12 @@ LSUP_mdbstore_setup(char **path)
|
|
|
MDBStore *
|
|
|
LSUP_mdbstore_new(const char *path, const LSUP_Buffer *default_ctx)
|
|
|
{
|
|
|
- int rc;
|
|
|
+ int db_rc;
|
|
|
LSUP_MDBStore *store;
|
|
|
CRITICAL(store = malloc(sizeof(LSUP_MDBStore)));
|
|
|
|
|
|
- rc = mdb_env_create(&store->env);
|
|
|
- TRACE("create rc: %d", rc);
|
|
|
+ db_rc = mdb_env_create(&store->env);
|
|
|
+ TRACE("create rc: %d", db_rc);
|
|
|
|
|
|
store->default_ctx = (
|
|
|
default_ctx ?
|
|
@@ -297,18 +285,18 @@ LSUP_mdbstore_new(const char *path, const LSUP_Buffer *default_ctx)
|
|
|
if (env_mapsize == NULL) mapsize = DEFAULT_MAPSIZE;
|
|
|
else sscanf(env_mapsize, "%lu", &mapsize);
|
|
|
|
|
|
- rc = mdb_env_set_maxdbs(store->env, N_DB);
|
|
|
- if (UNLIKELY (rc != MDB_SUCCESS)) return NULL;
|
|
|
+ db_rc = mdb_env_set_maxdbs(store->env, N_DB);
|
|
|
+ if (UNLIKELY (db_rc != MDB_SUCCESS)) return NULL;
|
|
|
|
|
|
- rc = mdb_env_open(store->env, path, 0, ENV_FILE_MODE);
|
|
|
- if (UNLIKELY (rc != MDB_SUCCESS)) return NULL;
|
|
|
+ db_rc = mdb_env_open(store->env, path, 0, ENV_FILE_MODE);
|
|
|
+ if (UNLIKELY (db_rc != MDB_SUCCESS)) return NULL;
|
|
|
|
|
|
|
|
|
MDB_txn *txn;
|
|
|
mdb_txn_begin(store->env, NULL, 0, &txn);
|
|
|
for (int i = 0; i < N_DB; i++) {
|
|
|
- rc = mdb_dbi_open(txn, db_labels[i], db_flags[i], store->dbi + i);
|
|
|
- if (UNLIKELY (rc != MDB_SUCCESS)) {
|
|
|
+ db_rc = mdb_dbi_open(txn, db_labels[i], db_flags[i], store->dbi + i);
|
|
|
+ if (UNLIKELY (db_rc != MDB_SUCCESS)) {
|
|
|
mdb_txn_abort(txn);
|
|
|
return NULL;
|
|
|
}
|
|
@@ -817,24 +805,6 @@ _remove_abort:
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-static int
|
|
|
-unlink_cb(
|
|
|
- const char *fpath, const struct stat *sb,
|
|
|
- int typeflag, struct FTW *ftwbuf)
|
|
|
-{
|
|
|
- int rv = remove(fpath);
|
|
|
-
|
|
|
- if (rv)
|
|
|
- perror(fpath);
|
|
|
-
|
|
|
- return rv;
|
|
|
-}
|
|
|
-
|
|
|
-static int rmrf(char *path)
|
|
|
-{ return nftw(path, unlink_cb, 64, FTW_DEPTH | FTW_PHYS); }
|
|
|
-*/
|
|
|
-
|
|
|
|
|
|
|
|
|
*
|