r10193: r11632@blu: tridge | 2005-08-30 23:08:27 +1000
authorAndrew Tridgell <tridge@samba.org>
Tue, 13 Sep 2005 01:02:06 +0000 (01:02 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:38:07 +0000 (13:38 -0500)
 if we fail to erase a ldb during provision by traversing
 and deleting records (an in-place erase) then just unlink it
 and start it again. This makes provisioning much more robust
 to changes in ldb that make it not backward compatible with
 old DBs.
(This used to be commit 173655aec25c462b8b90b850df65ae6f95f44efb)

source4/scripting/libjs/provision.js

index 33bfafac135e72a49768b7a7b7ac97d27758d645..d700ecd5390902f9c05012d7e7e335f3e7fa299d 100644 (file)
@@ -122,6 +122,18 @@ function hostname()
 }
 
 
+/* the ldb is in bad shape, possibly due to being built from an
+   incompatible previous version of the code, so delete it
+   completely */
+function ldb_delete(ldb)
+{
+       println("Deleting " + ldb.filename);
+       sys.unlink(ldb.filename);
+       ldb.close();
+       var ok = ldb.connect(ldb.filename);
+       assert(ok);
+}
+
 /*
   erase an ldb, removing all records
 */
@@ -138,10 +150,18 @@ function ldb_erase(ldb)
        /* and the rest */
        var res = ldb.search("(|(objectclass=*)(dn=*))", attrs);
        var i;
+       if (typeof(res) == "undefined") {
+               ldb_delete(ldb);
+               return;
+       }
        for (i=0;i<res.length;i++) {
                ldb.del(res[i].dn);
        }
        res = ldb.search("(objectclass=*)", attrs);
+       if (res.length != 0) {
+               ldb_delete(ldb);
+               return;
+       }
        assert(res.length == 0);
 }
 
@@ -170,6 +190,8 @@ function setup_ldb(ldif, dbname, subobj)
        data = data + extra;
        data = substitute_var(data, subobj);
 
+       ldb.filename = dbname;
+
        var ok = ldb.connect(dbname);
        assert(ok);