/* * Removes the backend database. This function shall be called only when * nothing holds the database open. * * ARGUMENTS: * path Pathname of the database directory. Shall not be NULL. * The client can free it upon return. * RETURNS: * 0 Success. * ENOMEM System error. "log_start()" called. * EIO Backend database error. "log_start()" called. */ RegStatus beRemove( const char* const path) { RegStatus status; DB_ENV* env; assert(NULL != path); /* * First, remove the database. */ if (0 == (status = openEnvironment(path, &env))) { if (status = env->dbremove(env, NULL, DB_FILENAME, NULL, 0)) { log_add("Couldn't remove database file \"%s\" in \"%s\"", DB_FILENAME, path); status = EIO; } (void)env->close(env, 0); } /* "env" allocated */ /* * Then, remove the database environment. */ if (0 == status) status = removeEnvironment(path); return status; }
static int bdb_la_storage_object_store_delete(la_storage_object_store *store) { const char *dbname; const char *seqdbname; const char *home; const char *parts[2]; DB_TXN *txn; DB_ENV *env = store->env->env; int ret; if ((ret = store->db->get_dbname(store->db, &dbname, NULL)) != 0) { syslog(LOG_NOTICE, "could not get main db name: %d", ret); return -1; } if ((ret = store->db->get_dbname(store->seq_db, &seqdbname, NULL)) != 0) { syslog(LOG_NOTICE, "could not get sequence db name: %d", ret); return -1; } if ((ret = env->get_home(env, &home)) != 0) { syslog(LOG_NOTICE, "could not get db home %d", ret); return -1; } parts[0] = home; parts[1] = dbname; dbname = string_join("/", parts, 2); parts[1] = seqdbname; seqdbname = string_join("/", parts, 2); syslog(LOG_NOTICE, "deleting db %s and sequence db %s", dbname, seqdbname); la_storage_close(store); if ((ret = txn_begin(env, NULL, &txn, DB_TXN_NOWAIT | DB_TXN_WRITE_NOSYNC)) != 0) { syslog(LOG_NOTICE, "delete db begin transaction %d", ret); free(dbname); free(seqdbname); return -1; } syslog(LOG_NOTICE, "env %p txn %p home %s name %s", env, txn, home, dbname); if ((ret = env->dbremove(env, txn, dbname, NULL, 0)) != 0) { syslog(LOG_NOTICE, "deleting main DB: %d", ret); txn_abort(txn); return -1; } syslog(LOG_NOTICE, "env %p txn %p home %s name %s", env, txn, home, seqdbname); if ((ret = env->dbremove(env, txn, seqdbname, NULL, 0)) != 0) { syslog(LOG_NOTICE, "deleting sequence DB: %d", ret); txn_abort(txn); return -1; } txn_commit(txn, DB_TXN_NOSYNC); return 0; }