From edca5a4600580eda6c180efefcb77cc99cf98f3d Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 5 Apr 2000 06:37:30 +0000 Subject: added TDB_MODIFY flag. this says, "if it don't already exist, fail to update". --- source/tdb/tdb.c | 14 +++++++++++--- source/tdb/tdb.h | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/source/tdb/tdb.c b/source/tdb/tdb.c index 388f4f419fe..7d99773e6f8 100644 --- a/source/tdb/tdb.c +++ b/source/tdb/tdb.c @@ -2,7 +2,8 @@ Unix SMB/Netbios implementation. Version 3.0 Samba database functions - Copyright (C) Andrew Tridgell 1999 + Copyright (C) Andrew Tridgell 1999-2000 + Copyright (C) Luke Kenneth Casson Leighton 2000 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -600,6 +601,7 @@ char *tdb_error(TDB_CONTEXT *tdb) {TDB_ERR_LOCK, "Locking error"}, {TDB_ERR_OOM, "Out of memory"}, {TDB_ERR_EXISTS, "Record exists"}, + {TDB_ERR_NOEXIST, "Record does not exist"}, {-1, NULL}}; if (tdb != NULL) { for (i=0;emap[i].estring;i++) { @@ -1025,13 +1027,19 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag) /* find which hash bucket it is in */ hash = tdb_hash(&key); - /* check for it existing */ + /* check for it existing, on insert. */ if (flag == TDB_INSERT && tdb_exists(tdb, key)) { tdb->ecode = TDB_ERR_EXISTS; return -1; } - /* first try in-place update */ + /* check for it _not_ existing, on modify. */ + if (flag == TDB_MODIFY && !tdb_exists(tdb, key)) { + tdb->ecode = TDB_ERR_NOEXIST; + return -1; + } + + /* first try in-place update, on modify or replace. */ if (flag != TDB_INSERT && tdb_update(tdb, key, dbuf) == 0) { return 0; } diff --git a/source/tdb/tdb.h b/source/tdb/tdb.h index b24f08b648f..405b2014d42 100644 --- a/source/tdb/tdb.h +++ b/source/tdb/tdb.h @@ -51,13 +51,14 @@ typedef struct { /* flags to tdb_store() */ #define TDB_REPLACE 1 #define TDB_INSERT 2 +#define TDB_MODIFY 3 /* flags for tdb_open() */ #define TDB_CLEAR_IF_FIRST 1 /* error codes */ enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK, - TDB_ERR_OOM, TDB_ERR_EXISTS}; + TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOEXIST }; #if STANDALONE TDB_CONTEXT *tdb_open(char *name, int hash_size, int tdb_flags, -- cgit v1.2.1