s4-dbcheck: fixed transaction nesting in dbcheck
authorAndrew Tridgell <tridge@samba.org>
Wed, 21 Sep 2011 23:58:39 +0000 (09:58 +1000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 22 Sep 2011 01:39:59 +0000 (03:39 +0200)
ensure we don't cancel a transaction we didn't start

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

Autobuild-User: Andrew Tridgell <tridge@samba.org>
Autobuild-Date: Thu Sep 22 03:39:59 CEST 2011 on sn-devel-104

source4/scripting/python/samba/netcmd/dbcheck.py

index 92d27a11893d752f0b16fdbb6aa9907cf3a15ccf..7840a61725741ae6ed048eb92aa7b179172f12c1 100644 (file)
@@ -94,8 +94,11 @@ class cmd_dbcheck(Command):
         else:
             attrs = attrs.split()
 
+        started_transaction = False
+
         if yes and fix:
             samdb.transaction_start()
+            started_transaction = True
         try:
             chk = dbcheck(samdb, samdb_schema=samdb_schema, verbose=verbose,
                     fix=fix, yes=yes, quiet=quiet)
@@ -109,10 +112,11 @@ class cmd_dbcheck(Command):
                 error_count = chk.check_database(DN=DN, scope=search_scope,
                         controls=controls, attrs=attrs)
         except:
-            samdb.transaction_cancel()
+            if started_transaction:
+                samdb.transaction_cancel()
             raise
 
-        if yes and fix:
+        if started_transaction:
             samdb.transaction_commit()
 
         if error_count != 0: