Create directory structure for rpmbuild prior to build if it doesn't exist
authorJindrich Novy <jnovy@redhat.com>
Mon, 1 Sep 2008 12:35:34 +0000 (14:35 +0200)
committerJindrich Novy <jnovy@redhat.com>
Mon, 1 Sep 2008 12:35:34 +0000 (14:35 +0200)
- creates all needed directories that rpmbuild uses for input and output

build.c

diff --git a/build.c b/build.c
index faa09c5..83aaf20 100644 (file)
--- a/build.c
+++ b/build.c
@@ -16,6 +16,7 @@
 #include <rpm/rpmts.h>
 #include <rpm/rpmfileutil.h>
 #include <rpm/rpmlog.h>
+#include <lib/misc.h>
 
 #include "build.h"
 #include "debug.h"
@@ -253,6 +254,28 @@ static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
        goto exit;
     }
 
+    /* Be sure all required directories exist, attempt to create them if not */
+    {
+       char *_topdir = rpmGenPath(rpmtsRootDir(ts), "%{_topdir}", ""),
+            *_builddir = rpmGenPath(rpmtsRootDir(ts), "%{_builddir}", ""),
+            *_buildrootdir = rpmGenPath(rpmtsRootDir(ts), "%{_buildrootdir}", ""),
+            *_sourcedir = rpmGenPath(rpmtsRootDir(ts), "%{_sourcedir}", ""),
+            *_rpmdir = rpmGenPath(rpmtsRootDir(ts), "%{_rpmdir}", ""),
+            *_specdir = rpmGenPath(rpmtsRootDir(ts), "%{_specdir}", ""),
+            *_srcrpmdir = rpmGenPath(rpmtsRootDir(ts), "%{_srcrpmdir}", "");
+
+       if ( rpmMkdirPath(_topdir, "_topdir") ||
+            rpmMkdirPath(_builddir, "_builddir") ||
+            rpmMkdirPath(_buildrootdir, "_buildrootdir") ||
+            rpmMkdirPath(_sourcedir, "_sourcedir") ||
+            rpmMkdirPath(_rpmdir, "_rpmdir") ||
+            rpmMkdirPath(_specdir, "_specdir") ||
+            rpmMkdirPath(_srcrpmdir, "_srcrpmdir")
+       ) {
+           goto exit;
+       }
+    }
+
     if (buildSpec(ts, spec, buildAmount, ba->noBuild)) {
        goto exit;
     }