1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-25 06:04:04 +03:00

tdb2: unify tdb1_append into tdb_append

Switch on the TDB_VERSION1 flag.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(Imported from CCAN commit 8bc38cb177928ef739440c32e33a8eaf23a5dd22)
This commit is contained in:
Rusty Russell 2011-09-14 07:52:13 +09:30
parent 02f5b8fef8
commit 61095999cc
5 changed files with 11 additions and 4 deletions

View File

@ -662,6 +662,7 @@ int tdb1_transaction_cancel(struct tdb_context *tdb);
int tdb1_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
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);
/* tdb.c: */
enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,

View File

@ -185,6 +185,12 @@ enum TDB_ERROR tdb_append(struct tdb_context *tdb,
struct tdb_data new_dbuf;
enum TDB_ERROR ecode;
if (tdb->flags & TDB_VERSION1) {
if (tdb1_append(tdb, key, dbuf) == -1)
return tdb->last_error;
return TDB_SUCCESS;
}
off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL);
if (TDB_OFF_IS_ERR(off)) {
return tdb->last_error = off;

View File

@ -47,8 +47,6 @@ int tdb1_parse_record(struct tdb_context *tdb, TDB_DATA key,
int tdb1_delete(struct tdb_context *tdb, TDB_DATA key);
int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
TDB_DATA tdb1_firstkey(struct tdb_context *tdb);
TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key);

View File

@ -627,6 +627,8 @@ int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf)
TDB_DATA dbuf;
int ret = -1;
assert(tdb->flags & TDB_VERSION1);
/* find which hash bucket it is in */
hash = tdb_hash(tdb, key.dptr, key.dsize);
if (tdb1_lock(tdb, TDB1_BUCKET(hash), F_WRLCK) == -1)

View File

@ -25,8 +25,8 @@ int main(int argc, char *argv[])
data.dptr = (void *)"world";
data.dsize = 0;
ok1(tdb1_append(tdb, key, data) == 0);
ok1(tdb1_append(tdb, key, data) == 0);
ok1(tdb_append(tdb, key, data) == TDB_SUCCESS);
ok1(tdb_append(tdb, key, data) == TDB_SUCCESS);
ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
ok1(data.dsize == 0);
free(data.dptr);