provision: Make sure target directory is created early.
authorJelmer Vernooij <jelmer@samba.org>
Tue, 7 Feb 2012 00:09:41 +0000 (01:09 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 7 Feb 2012 01:45:36 +0000 (02:45 +0100)
This is necessary when using the target directory to store temporary
files.

Autobuild-User: Jelmer Vernooij <jelmer@samba.org>
Autobuild-Date: Tue Feb  7 02:45:37 CET 2012 on sn-devel-104

source4/scripting/python/samba/netcmd/domain.py
source4/scripting/python/samba/upgradehelpers.py
source4/setup/provision

index 1f2c7de9578141c2eb3414adef0c0e04eca08e61..b0c174b47008f71d5be0127e9c80565f3226ad23 100644 (file)
@@ -873,6 +873,10 @@ class cmd_domain_samba3upgrade(Command):
         if sambaopts.realm:
             s3conf.set("realm", sambaopts.realm)
 
+        if targetdir is not None:
+            if not os.path.isdir(targetdir):
+                os.mkdir(targetdir)
+
         eadb = True
         if use_xattrs == "yes":
             eadb = False
@@ -882,14 +886,16 @@ class cmd_domain_samba3upgrade(Command):
             else:
                 tmpfile = tempfile.NamedTemporaryFile(dir=os.path.abspath(os.path.dirname(lp.get("private dir"))))
             try:
-                samba.ntacls.setntacl(lp, tmpfile.name,
-                            "O:S-1-5-32G:S-1-5-32", "S-1-5-32", "native")
-                eadb = False
-            except Exception:
-                # FIXME: Don't catch all exceptions here
-                logger.info("You are not root or your system do not support xattr, using tdb backend for attributes. "
-                            "If you intend to use this provision in production, rerun the script as root on a system supporting xattrs.")
-            tmpfile.close()
+                try:
+                    samba.ntacls.setntacl(lp, tmpfile.name,
+                                "O:S-1-5-32G:S-1-5-32", "S-1-5-32", "native")
+                    eadb = False
+                except Exception:
+                    # FIXME: Don't catch all exceptions here
+                    logger.info("You are not root or your system do not support xattr, using tdb backend for attributes. "
+                                "If you intend to use this provision in production, rerun the script as root on a system supporting xattrs.")
+            finally:
+                tmpfile.close()
 
         # Set correct default values from dbdir or testparm
         paths = {}
index 2c7191e707989ec85e8acc1bfbccad1f6f060cc4..a75ab75ada87c1b58ae9ee5a271d6fbbf662f3c7 100755 (executable)
@@ -202,6 +202,8 @@ def get_paths(param, targetdir=None, smbconf=None):
     :param smbconf: Path to the smb.conf file
     :return: A list with the path of important provision objects"""
     if targetdir is not None:
+        if not os.path.exists(targetdir):
+            os.mkdir(targetdir)
         etcdir = os.path.join(targetdir, "etc")
         if not os.path.exists(etcdir):
             os.makedirs(etcdir)
index 80237058e4c4450c8a135ddf27da65919a50f129..a2327b339e98482472be555cb44abaf37bb8f8b7 100755 (executable)
@@ -218,6 +218,10 @@ if opts.blank:
 elif opts.partitions_only:
     samdb_fill = FILL_DRS
 
+if opts.targetdir is not None:
+    if not os.path.isdir(opts.targetdir):
+        os.mkdir(opts.targetdir)
+
 eadb = True
 if opts.use_xattrs == "yes":
     eadb = False
@@ -227,13 +231,15 @@ elif opts.use_xattrs == "auto" and not lp.get("posix:eadb"):
     else:
         file = tempfile.NamedTemporaryFile(dir=os.path.abspath(os.path.dirname(lp.get("private dir"))))
     try:
-        samba.ntacls.setntacl(lp, file.name,
-            "O:S-1-5-32G:S-1-5-32", "S-1-5-32", "native")
-        eadb = False
-    except Exception:
-        logger.info("You are not root or your system do not support xattr, using tdb backend for attributes. "
-                "If you intend to use this provision in production, rerun the script as root on a system supporting xattrs.")
-    file.close()
+        try:
+            samba.ntacls.setntacl(lp, file.name,
+                "O:S-1-5-32G:S-1-5-32", "S-1-5-32", "native")
+            eadb = False
+        except Exception:
+            logger.info("You are not root or your system do not support xattr, using tdb backend for attributes. "
+                    "If you intend to use this provision in production, rerun the script as root on a system supporting xattrs.")
+    finally:
+        file.close()
 
 session = system_session()
 try: