ldb: ensure we cancel a ldb transaction
authorAndrew Tridgell <tridge@samba.org>
Fri, 4 Sep 2009 03:59:44 +0000 (13:59 +1000)
committerAndrew Tridgell <tridge@samba.org>
Fri, 4 Sep 2009 04:40:51 +0000 (14:40 +1000)
When we fail a ldbadd or ldbedit we should cancel the transaction to
prevent ldb giving a warning about having a open transaction in the
ldb destructor

source4/lib/ldb/tools/ldbadd.c
source4/lib/ldb/tools/ldbedit.c

index 086540dfdf55e2631f2b7e3703fe1d8829e6cb7e..f022486db882788133d12b237484bb604ff24de1 100644 (file)
@@ -109,9 +109,13 @@ int main(int argc, const char **argv)
                }
        }
 
-       if (count != 0 && ldb_transaction_commit(ldb) != 0) {
-               printf("Failed to commit transaction: %s\n", ldb_errstring(ldb));
-               exit(1);
+       if (count != 0) {
+               if (ldb_transaction_commit(ldb) != 0) {
+                       printf("Failed to commit transaction: %s\n", ldb_errstring(ldb));
+                       exit(1);
+               }
+       } else {
+               ldb_transaction_cancel(ldb);
        }
 
        talloc_free(ldb);
index 9653eabcb9c3bdf92e557f68cfe7c691c4f894b5..ecadf0f61c1266c70b413910ea566dc2c468f679 100644 (file)
@@ -128,6 +128,7 @@ static int merge_edits(struct ldb_context *ldb,
                                fprintf(stderr, "failed to add %s - %s\n",
                                        ldb_dn_get_linearized(msgs2[i]->dn),
                                        ldb_errstring(ldb));
+                               ldb_transaction_cancel(ldb);
                                return -1;
                        }
                        adds++;
@@ -149,6 +150,7 @@ static int merge_edits(struct ldb_context *ldb,
                                fprintf(stderr, "failed to delete %s - %s\n",
                                        ldb_dn_get_linearized(msgs1[i]->dn),
                                        ldb_errstring(ldb));
+                               ldb_transaction_cancel(ldb);
                                return -1;
                        }
                        deletes++;