Push special doc directory generation next to other special doc foobar
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 16 May 2012 14:01:29 +0000 (17:01 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 16 May 2012 14:05:26 +0000 (17:05 +0300)
- There's no need to carry the special doc directory in the
  package struct, the directory is only a fleeting thing deep down
  in the filelist parsing. Handle local-only needs locally.
- No behavior/semantic changes intended or expected.

build/files.c
build/parsePreamble.c
build/rpmbuild_internal.h
build/spec.c

index bab2256..5bd5ba6 100644 (file)
@@ -1691,6 +1691,30 @@ exit:
     return rc;
 }
 
+static char * getSpecialDocDir(Header h)
+{
+    const char *errstr, *docdir_fmt = "%{NAME}-%{VERSION}";
+    char *fmt_macro, *fmt; 
+    char *res = NULL;
+
+    fmt_macro = rpmExpand("%{?_docdir_fmt}", NULL);
+    if (fmt_macro && strlen(fmt_macro) > 0) {
+       docdir_fmt = fmt_macro;
+    }
+
+    fmt = headerFormat(h, docdir_fmt, &errstr);
+
+    if (fmt) {
+       res = rpmGetPath("%{_docdir}/", fmt, NULL);
+    } else {
+       rpmlog(RPMLOG_ERR, _("illegal _docdir_fmt: %s\n"), errstr);
+    }
+
+    free(fmt);
+    free(fmt_macro);
+    return res;
+}
+
 static rpmRC processSpecialDocs(rpmSpec spec, const char *docDir,
                                ARGV_const_t docs, int install, int test)
 {
@@ -1827,22 +1851,24 @@ static rpmRC processPackageFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags,
 
     /* Now process special doc, if there is one */
     if (specialDoc) {
-       if (processSpecialDocs(spec, pkg->specialDocDir, specialDoc,
-                              installSpecialDoc, test)) {
+       char *docDir = getSpecialDocDir(pkg->header);
+       if (docDir == NULL || processSpecialDocs(spec, docDir, specialDoc,
+                                                installSpecialDoc, test)) {
            fl.processingFailed = 1;
-       }
-
-       /* Reset for %doc */
-       FileEntryFree(&fl.cur);
+       } else {
+           /* Reset for %doc */
+           FileEntryFree(&fl.cur);
 
-       fl.cur.verifyFlags = fl.def.verifyFlags;
+           fl.cur.verifyFlags = fl.def.verifyFlags;
 
-       dupAttrRec(specialDocAttrRec, &fl.cur.ar);
-       dupAttrRec(def_specialDocAttrRec, &fl.def.ar);
-       freeAttrRec(specialDocAttrRec);
-       freeAttrRec(def_specialDocAttrRec);
+           dupAttrRec(specialDocAttrRec, &fl.cur.ar);
+           dupAttrRec(def_specialDocAttrRec, &fl.def.ar);
+           freeAttrRec(specialDocAttrRec);
+           freeAttrRec(def_specialDocAttrRec);
 
-       (void) processBinaryFile(pkg, &fl, pkg->specialDocDir);
+           (void) processBinaryFile(pkg, &fl, docDir);
+       }
+       free(docDir);
     }
     
     if (fl.processingFailed)
index 3ba035f..dd9a52b 100644 (file)
@@ -536,30 +536,6 @@ static void fillOutMainPackage(Header h)
     }
 }
 
-static int getSpecialDocDir(Package pkg)
-{
-    const char *errstr, *docdir_fmt = "%{NAME}-%{VERSION}";
-    char *fmt_macro, *fmt; 
-    int rc = -1;
-
-    fmt_macro = rpmExpand("%{?_docdir_fmt}", NULL);
-    if (fmt_macro && strlen(fmt_macro) > 0) {
-       docdir_fmt = fmt_macro;
-    }
-    fmt = headerFormat(pkg->header, docdir_fmt, &errstr);
-    if (!fmt) {
-       rpmlog(RPMLOG_ERR, _("illegal _docdir_fmt: %s\n"), errstr);
-       goto exit;
-    }
-    pkg->specialDocDir = rpmGetPath("%{_docdir}/", fmt, NULL);
-    rc = 0;
-
-exit:
-    free(fmt);
-    free(fmt_macro);
-    return rc;
-}
-
 /**
  */
 static rpmRC readIcon(Header h, const char * file)
@@ -1110,10 +1086,6 @@ int parsePreamble(rpmSpec spec, int initialPackage)
        goto exit;
     }
 
-    if (getSpecialDocDir(pkg)) {
-       goto exit;
-    }
-       
     /* if we get down here nextPart has been set to non-error */
     res = nextPart;
 
index e90e925..22a5d35 100644 (file)
@@ -101,8 +101,6 @@ struct Package_s {
     char * postTransFile;      /*!< %posttrans scriptlet. */
     char * verifyFile; /*!< %verifyscript scriptlet. */
 
-    char *specialDocDir;
-
     struct TriggerFileEntry * triggerFiles;
 
     ARGV_t fileFile;
index 8a38e80..00e4e6d 100644 (file)
@@ -134,7 +134,6 @@ static Package freePackage(Package pkg)
     pkg->policyList = argvFree(pkg->policyList);
     pkg->cpioList = rpmfiFree(pkg->cpioList);
 
-    pkg->specialDocDir = _free(pkg->specialDocDir);
     pkg->icon = freeSources(pkg->icon);
     pkg->triggerFiles = freeTriggerFiles(pkg->triggerFiles);