summaryrefslogtreecommitdiff
path: root/lib/tdb2/tdb1_tdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tdb2/tdb1_tdb.c')
-rw-r--r--lib/tdb2/tdb1_tdb.c102
1 files changed, 0 insertions, 102 deletions
diff --git a/lib/tdb2/tdb1_tdb.c b/lib/tdb2/tdb1_tdb.c
index a50303c33c..2442d34785 100644
--- a/lib/tdb2/tdb1_tdb.c
+++ b/lib/tdb2/tdb1_tdb.c
@@ -791,108 +791,6 @@ failed:
return -1;
}
-struct traverse_state {
- enum TDB_ERROR error;
- struct tdb_context *dest_db;
-};
-
-/*
- traverse function for repacking
- */
-static int repack_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *private_data)
-{
- struct traverse_state *state = (struct traverse_state *)private_data;
- if (tdb1_store(state->dest_db, key, data, TDB_INSERT) != 0) {
- state->error = state->dest_db->last_error;
- return -1;
- }
- return 0;
-}
-
-/*
- repack a tdb
- */
-int tdb1_repack(struct tdb_context *tdb)
-{
- struct tdb_context *tmp_db;
- struct traverse_state state;
- union tdb_attribute hsize;
-
- hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
- hsize.base.next = NULL;
- hsize.tdb1_hashsize.hsize = tdb->tdb1.header.hash_size;
-
- if (tdb1_transaction_start(tdb) != 0) {
- tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
- __location__ " Failed to start transaction");
- return -1;
- }
-
- tmp_db = tdb_open("tmpdb", TDB_INTERNAL, O_RDWR|O_CREAT, 0, &hsize);
- if (tmp_db == NULL) {
- tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
- __location__ " Failed to create tmp_db");
- tdb1_transaction_cancel(tdb);
- return -1;
- }
-
- state.error = TDB_SUCCESS;
- state.dest_db = tmp_db;
-
- if (tdb1_traverse(tdb, repack_traverse, &state) == -1) {
- tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
- __location__ " Failed to traverse copying out");
- tdb1_transaction_cancel(tdb);
- tdb_close(tmp_db);
- return -1;
- }
-
- if (state.error != TDB_SUCCESS) {
- tdb->last_error = tdb_logerr(tdb, state.error, TDB_LOG_ERROR,
- __location__ " Error during traversal");
- tdb1_transaction_cancel(tdb);
- tdb_close(tmp_db);
- return -1;
- }
-
- if (tdb1_wipe_all(tdb) != 0) {
- tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
- __location__ " Failed to wipe database\n");
- tdb1_transaction_cancel(tdb);
- tdb_close(tmp_db);
- return -1;
- }
-
- state.error = TDB_SUCCESS;
- state.dest_db = tdb;
-
- if (tdb1_traverse(tmp_db, repack_traverse, &state) == -1) {
- tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
- __location__ " Failed to traverse copying back");
- tdb1_transaction_cancel(tdb);
- tdb_close(tmp_db);
- return -1;
- }
-
- if (state.error) {
- tdb->last_error = tdb_logerr(tdb, state.error, TDB_LOG_ERROR,
- __location__ " Error during second traversal");
- tdb1_transaction_cancel(tdb);
- tdb_close(tmp_db);
- return -1;
- }
-
- tdb_close(tmp_db);
-
- if (tdb1_transaction_commit(tdb) != 0) {
- tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
- __location__ " Failed to commit");
- return -1;
- }
-
- return 0;
-}
-
/* Even on files, we can get partial writes due to signals. */
bool tdb1_write_all(int fd, const void *buf, size_t count)
{