]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/nextid.c
Removed unnecessary definition that is already in core.schema.
[openldap] / servers / slapd / back-ldbm / nextid.c
index 25841ca86d9fdef58247e9c85c8095ef987619c7..34c7bfe5c92c6414ff7b52f7ae078c4066c50f07 100644 (file)
 #include "slap.h"
 #include "back-ldbm.h"
 
+static ID  next_id_read( Backend *be );
+static int next_id_write( Backend *be, ID id );
+static ID  next_id_get_save( Backend *be, int do_save );
+
+
 static ID
 next_id_read( Backend *be )
 {
@@ -22,6 +27,9 @@ next_id_read( Backend *be )
        char*   file = li->li_nextid_file; 
        FILE*   fp;
 
+       if ( ldbm_ignore_nextid_file )
+               return NOID;
+
        if ( (fp = fopen( file, "r" )) == NULL ) {
                Debug( LDAP_DEBUG_ANY,
                    "next_id_read: could not open \"%s\"\n",
@@ -42,7 +50,7 @@ next_id_read( Backend *be )
 
        if(id < 1) {
                Debug( LDAP_DEBUG_ANY,
-                       "next_id_read %lu: atol(%s) return non-positive integer\n",
+                       "next_id_read %ld: atol(%s) return non-positive integer\n",
                        id, buf, 0 );
                return NOID;
        }
@@ -54,13 +62,15 @@ static int
 next_id_write( Backend *be, ID id )
 {
        struct ldbminfo *li = (struct ldbminfo *) be->be_private;
-       char    buf[20];
        char*   file = li->li_nextid_file; 
        FILE*   fp;
        int             rc;
 
+       if ( ldbm_ignore_nextid_file )
+               return 0;
+
        if ( (fp = fopen( file, "w" )) == NULL ) {
-               Debug( LDAP_DEBUG_ANY, "next_id_write(%lu): could not open \"%s\"\n",
+               Debug( LDAP_DEBUG_ANY, "next_id_write(%ld): could not open \"%s\"\n",
                    id, file, 0 );
                return -1;
        } 
@@ -68,13 +78,13 @@ next_id_write( Backend *be, ID id )
        rc = 0;
 
        if ( fprintf( fp, "%ld\n", id ) == EOF ) {
-               Debug( LDAP_DEBUG_ANY, "next_id_write(%lu): cannot fprintf\n",
+               Debug( LDAP_DEBUG_ANY, "next_id_write(%ld): cannot fprintf\n",
                    id, 0, 0 );
                rc = -1;
        }
 
        if( fclose( fp ) != 0 ) {
-               Debug( LDAP_DEBUG_ANY, "next_id_write %lu: cannot fclose\n",
+               Debug( LDAP_DEBUG_ANY, "next_id_write %ld: cannot fclose\n",
                    id, 0, 0 );
                rc = -1;
        }
@@ -85,15 +95,7 @@ next_id_write( Backend *be, ID id )
 int
 next_id_save( Backend *be )
 {
-       struct ldbminfo *li = (struct ldbminfo *) be->be_private;
-       ID id = next_id_get( be );
-       int rc = next_id_write( be, id );
-
-       if (rc == 0) {
-               li->li_nextid_wrote = id;
-       }
-
-       return rc;
+       return( next_id_get_save( be, 1 ) == NOID ? -1 : 0 );
 }
 
 ID
@@ -147,7 +149,7 @@ next_id_return( Backend *be, ID id )
 
        li->li_nextid--;
 
-#if !( SLAPD_NEXTID_CHUCK > 1 )
+#if !( SLAPD_NEXTID_CHUNK > 1 )
        (void) next_id_write( be, li->li_nextid );
 #endif
 
@@ -157,6 +159,12 @@ next_id_return( Backend *be, ID id )
 
 ID
 next_id_get( Backend *be )
+{
+       return next_id_get_save( be, 0 );
+}
+
+static ID
+next_id_get_save( Backend *be, int do_save )
 {
        struct ldbminfo *li = (struct ldbminfo *) be->be_private;
        ID              id;
@@ -178,6 +186,14 @@ next_id_get( Backend *be )
 
        id = li->li_nextid;
 
+       if ( do_save ) {
+               if ( next_id_write( be, id ) == 0 ) {
+                       li->li_nextid_wrote = id;
+               } else {
+                       id = NOID;
+               }
+       }
+
        ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex );
 
        return( id );