From 5f917d5f177401edbe0c11fd98f2e9203136de32 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 17 Aug 2009 11:33:25 +1000 Subject: [PATCH] s4:provision Avoid one more call to ltdb_reindex The Samba4 schema code (called via samdb.set_schema_from_ldb(schema.ldb)) manages the @ATTRIBUTES and @INDEXLIST records, so don't wipe them early. The chances are that we will not change them anyway. Andrew Bartlett --- source4/scripting/python/samba/__init__.py | 19 ++++++++++++++++--- source4/scripting/python/samba/provision.py | 6 +++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py index 097d96a3f4ec..ad75f5f8f1fc 100644 --- a/source4/scripting/python/samba/__init__.py +++ b/source4/scripting/python/samba/__init__.py @@ -119,8 +119,8 @@ class Ldb(ldb.Ldb): assert len(values) == 1 return self.schema_format_value(attribute, values.pop()) - def erase(self): - """Erase this ldb, removing all records.""" + def erase_except_schema_controlled(self): + """Erase this ldb, removing all records, except those that are controlled by Samba4's schema.""" basedn = "" # Delete the 'visible' records for msg in self.search(basedn, ldb.SCOPE_SUBTREE, @@ -136,7 +136,7 @@ class Ldb(ldb.Ldb): assert len(res) == 0 # delete the specials - for attr in ["@INDEXLIST", "@ATTRIBUTES", "@SUBCLASSES", "@MODULES", + for attr in ["@SUBCLASSES", "@MODULES", "@OPTIONS", "@PARTITION", "@KLUDGEACL"]: try: self.delete(attr) @@ -144,6 +144,19 @@ class Ldb(ldb.Ldb): # Ignore missing dn errors pass + def erase(self): + """Erase this ldb, removing all records.""" + + self.erase_except_schema_controlled() + + # delete the specials + for attr in ["@INDEXLIST", "@ATTRIBUTES"]: + try: + self.delete(attr) + except ldb.LdbError, (ldb.ERR_NO_SUCH_OBJECT, _): + # Ignore missing dn errors + pass + def erase_partitions(self): """Erase an ldb, removing all records.""" diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index da1625f35de5..34af462ebfb3 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -3,7 +3,7 @@ # backend code for provisioning a Samba4 server # Copyright (C) Jelmer Vernooij 2007-2008 -# Copyright (C) Andrew Bartlett 2008 +# Copyright (C) Andrew Bartlett 2008-2009 # Copyright (C) Oliver Liebel 2008-2009 # # Based on the original in EJS: @@ -525,13 +525,13 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, samdb = Ldb(url=samdb_path, session_info=session_info, credentials=credentials, lp=lp, options=["modules:"]) # Wipes the database - samdb.erase() + samdb.erase_except_schema_controlled() except LdbError: os.unlink(samdb_path) samdb = Ldb(url=samdb_path, session_info=session_info, credentials=credentials, lp=lp, options=["modules:"]) # Wipes the database - samdb.erase() + samdb.erase_except_schema_controlled() #Add modules to the list to activate them by default -- 2.34.1