]> git.sur5r.net Git - openldap/commitdiff
Reorganize, attempt some fault tolerance...
authorHoward Chu <hyc@openldap.org>
Wed, 3 Dec 2003 12:30:28 +0000 (12:30 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 3 Dec 2003 12:30:28 +0000 (12:30 +0000)
servers/slapd/back-ldbm/modrdn.c

index ea5e71ee824a105779be98946c1d3ef70b72a23e..1707dadb3e268608f419e7bd54ec0e30a4550557 100644 (file)
@@ -582,23 +582,13 @@ ldbm_back_modrdn(
                goto return_results;
        }
 
-
        /* check for abandon */
        if ( op->o_abandon ) {
                goto return_results;
        }
 
-       /* delete old one */
-       if ( dn2id_delete( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
-               send_ldap_error( op, rs, LDAP_OTHER,
-                       "DN index delete fail" );
-               goto return_results;
-       }
-
        (void) cache_delete_entry( &li->li_cache, e );
 
-       /* XXX: there is no going back! */
-
        free( e->e_dn );
        old_ndn = e->e_nname;
        e->e_name = new_dn;
@@ -610,13 +600,6 @@ ldbm_back_modrdn(
         * They are used by cache.
         */
 
-       /* add new one */
-       if ( dn2id_add( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
-               send_ldap_error( op, rs, LDAP_OTHER,
-                       "DN index add failed" );
-               goto return_results;
-       }
-
        /* modify memory copy of entry */
        rs->sr_err = ldbm_modify_internal( op, &mod[0], e,
                &rs->sr_text, textbuf, textlen );
@@ -624,30 +607,40 @@ ldbm_back_modrdn(
        case LDAP_SUCCESS:
                break;
 
-       case SLAPD_ABANDON:
-               /* too late ... */
-               goto return_results;
-       
        default:
-               /* here we may try to delete the newly added dn */
-               if ( dn2id_delete( op->o_bd, &e->e_nname, e->e_id ) != 0 ||
-                       dn2id_add( op->o_bd, &old_ndn, e->e_id ) != 0 ) {
-                       /* we already are in trouble ... */
-                       ;
-               }
                send_ldap_result( op, rs );
+               /* FALLTHRU */
+       case SLAPD_ABANDON:
                goto return_results;
        }
        
-       (void) cache_update_entry( &li->li_cache, e );
+       /* add new one */
+       if ( dn2id_add( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
+               send_ldap_error( op, rs, LDAP_OTHER,
+                       "DN index add failed" );
+               goto return_results;
+       }
+       /* delete old one */
+       if ( dn2id_delete( op->o_bd, &old_ndn, e->e_id ) != 0 ) {
+               /* undo add of new one */
+               dn2id_delete( op->o_bd, &e->e_nname, e->e_id );
+               send_ldap_error( op, rs, LDAP_OTHER,
+                       "DN index delete fail" );
+               goto return_results;
+       }
 
        /* id2entry index */
        if ( id2entry_add( op->o_bd, e ) != 0 ) {
+               /* Try to undo */
+               dn2id_delete( op->o_bd, &e->e_nname, e->e_id );
+               dn2id_add( op->o_bd, &old_ndn, e->e_id );
                send_ldap_error( op, rs, LDAP_OTHER,
                        "entry update failed" );
                goto return_results;
        }
 
+       (void) cache_update_entry( &li->li_cache, e );
+
        rs->sr_err = LDAP_SUCCESS;
        rs->sr_text = NULL;
        send_ldap_result( op, rs );