dbcheck: Cancel transaction if operation fails.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 1 Aug 2011 18:04:02 +0000 (20:04 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 1 Aug 2011 23:41:07 +0000 (01:41 +0200)
Autobuild-User: Jelmer Vernooij <jelmer@samba.org>
Autobuild-Date: Tue Aug  2 01:41:07 CEST 2011 on sn-devel-104

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

index 3f379c0cd4d4ea5733b864d2ed740785aaff870a..2a175f3525ea3f2a49067e337a321afc710a3bae 100644 (file)
@@ -96,16 +96,21 @@ class cmd_dbcheck(Command):
 
         if yes and fix:
             samdb.transaction_start()
-
-        chk = dbcheck(samdb, samdb_schema=samdb_schema, verbose=verbose, fix=fix, yes=yes, quiet=quiet)
-
-        if reindex:
-            print("Re-indexing...")
-            error_count = 0
-            if chk.reindex_database():
-                print("completed re-index OK")
-        else:
-            error_count = chk.check_database(DN=DN, scope=search_scope, controls=controls, attrs=attrs)
+        try:
+            chk = dbcheck(samdb, samdb_schema=samdb_schema, verbose=verbose,
+                    fix=fix, yes=yes, quiet=quiet)
+
+            if reindex:
+                print("Re-indexing...")
+                error_count = 0
+                if chk.reindex_database():
+                    print("completed re-index OK")
+            else:
+                error_count = chk.check_database(DN=DN, scope=search_scope,
+                        controls=controls, attrs=attrs)
+        except:
+            samdb.transaction_cancel()
+            raise
 
         if yes and fix:
             samdb.transaction_commit()