summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:54:13 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:54:13 +0930
commite6cbc0f00ec9ecb4c014ee484746d565382d5f67 (patch)
treef6ae2355ebe45421ae623ee439a10d60c3f5ceaa /lib
parent10606b7e3bdad19a60953dbad9e1d541a1a3b805 (diff)
downloadsamba-e6cbc0f00ec9ecb4c014ee484746d565382d5f67.tar.gz
samba-e6cbc0f00ec9ecb4c014ee484746d565382d5f67.tar.bz2
samba-e6cbc0f00ec9ecb4c014ee484746d565382d5f67.zip
tdb2: unify tdb1_store into tdb_store
Switch on the TDB_VERSION1 flag. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit 2bba2a856a6cfdb93085b701557850bc1da99587)
Diffstat (limited to 'lib')
-rw-r--r--lib/tdb2/private.h1
-rw-r--r--lib/tdb2/tdb.c4
-rw-r--r--lib/tdb2/tdb1.h2
-rw-r--r--lib/tdb2/tdb1_tdb.c1
-rw-r--r--lib/tdb2/test/run-tdb1-nested-transactions.c8
5 files changed, 10 insertions, 6 deletions
diff --git a/lib/tdb2/private.h b/lib/tdb2/private.h
index 851e0e3a3d..20884acccf 100644
--- a/lib/tdb2/private.h
+++ b/lib/tdb2/private.h
@@ -664,6 +664,7 @@ enum TDB_ERROR tdb1_fetch(struct tdb_context *tdb, TDB_DATA key,
TDB_DATA *data);
int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
int tdb1_delete(struct tdb_context *tdb, TDB_DATA key);
+int tdb1_exists(struct tdb_context *tdb, TDB_DATA key);
/* tdb.c: */
enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
diff --git a/lib/tdb2/tdb.c b/lib/tdb2/tdb.c
index 28d0e03f7d..ac327284ef 100644
--- a/lib/tdb2/tdb.c
+++ b/lib/tdb2/tdb.c
@@ -286,6 +286,10 @@ bool tdb_exists(struct tdb_context *tdb, TDB_DATA key)
struct tdb_used_record rec;
struct hash_info h;
+ if (tdb->flags & TDB_VERSION1) {
+ return tdb1_exists(tdb, key);
+ }
+
off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL);
if (TDB_OFF_IS_ERR(off)) {
tdb->last_error = off;
diff --git a/lib/tdb2/tdb1.h b/lib/tdb2/tdb1.h
index 77d673ae08..da77e27c88 100644
--- a/lib/tdb2/tdb1.h
+++ b/lib/tdb2/tdb1.h
@@ -53,8 +53,6 @@ int tdb1_traverse(struct tdb_context *tdb, tdb1_traverse_func fn, void *private_
int tdb1_traverse_read(struct tdb_context *tdb, tdb1_traverse_func fn, void *private_data);
-int tdb1_exists(struct tdb_context *tdb, TDB_DATA key);
-
int tdb1_lockall(struct tdb_context *tdb);
int tdb1_unlockall(struct tdb_context *tdb);
diff --git a/lib/tdb2/tdb1_tdb.c b/lib/tdb2/tdb1_tdb.c
index 16e945974e..2c989bb9a4 100644
--- a/lib/tdb2/tdb1_tdb.c
+++ b/lib/tdb2/tdb1_tdb.c
@@ -275,6 +275,7 @@ int tdb1_exists(struct tdb_context *tdb, TDB_DATA key)
uint32_t hash = tdb_hash(tdb, key.dptr, key.dsize);
int ret;
+ assert(tdb->flags & TDB_VERSION1);
ret = tdb1_exists_hash(tdb, key, hash);
return ret;
}
diff --git a/lib/tdb2/test/run-tdb1-nested-transactions.c b/lib/tdb2/test/run-tdb1-nested-transactions.c
index 645b4bc147..408987b58e 100644
--- a/lib/tdb2/test/run-tdb1-nested-transactions.c
+++ b/lib/tdb2/test/run-tdb1-nested-transactions.c
@@ -54,18 +54,18 @@ int main(int argc, char *argv[])
ok1(tdb1_transaction_start(tdb) == 0);
ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
ok1(tdb1_transaction_commit(tdb) == 0);
- ok1(!tdb1_exists(tdb, key));
+ ok1(!tdb_exists(tdb, key));
ok1(tdb1_transaction_cancel(tdb) == 0);
/* Surprise! Kills inner "committed" transaction. */
- ok1(tdb1_exists(tdb, key));
+ ok1(tdb_exists(tdb, key));
ok1(tdb1_transaction_start(tdb) == 0);
ok1(tdb1_transaction_start(tdb) == 0);
ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
ok1(tdb1_transaction_commit(tdb) == 0);
- ok1(!tdb1_exists(tdb, key));
+ ok1(!tdb_exists(tdb, key));
ok1(tdb1_transaction_commit(tdb) == 0);
- ok1(!tdb1_exists(tdb, key));
+ ok1(!tdb_exists(tdb, key));
tdb_close(tdb);
return exit_status();