Simplify rpmio flags handling in writeRPM() / cpio_doio()
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 18 May 2011 08:55:59 +0000 (11:55 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 18 May 2011 08:55:59 +0000 (11:55 +0300)
- The payload macros are already expanded in writeRPM(), no point
  re-expanding in cpio_doio() and handle fallback to default gzdio
  in writeRPM() already in case the payload is not set in config
  or is bogus. Also rpmExpand() cannot return NULL so there's no
  point in checking for that.

build/pack.c

index 5f27d24..4aedebf 100644 (file)
@@ -35,8 +35,7 @@ typedef struct cpioSourceArchive_s {
 /**
  * @todo Create transaction set *much* earlier.
  */
-static rpmRC cpio_doio(FD_t fdo, Header h, CSA_t csa,
-               const char * fmodeMacro)
+static rpmRC cpio_doio(FD_t fdo, Header h, CSA_t csa, const char * fmodeMacro)
 {
     rpmts ts = NULL;
     rpmfi fi = csa->cpioList;
@@ -46,13 +45,9 @@ static rpmRC cpio_doio(FD_t fdo, Header h, CSA_t csa,
     FD_t cfd;
     rpmRC rc = RPMRC_OK;
     int i;
-    char *fmode = rpmExpand(fmodeMacro, NULL);
 
-    if (!(fmode && fmode[0] == 'w'))
-       fmode = xstrdup("w9.gzdio");
     (void) Fflush(fdo);
-    cfd = Fdopen(fdDup(Fileno(fdo)), fmode);
-    fmode = _free(fmode);
+    cfd = Fdopen(fdDup(Fileno(fdo)), fmodeMacro);
     if (cfd == NULL)
        return RPMRC_FAIL;
 
@@ -337,8 +332,9 @@ static rpmRC writeRPM(Header *hdrp, unsigned char ** pkgidp, const char *fileNam
     else 
        rpmio_flags = rpmExpand("%{?_binary_payload}", NULL);
 
-    if (!(rpmio_flags && *rpmio_flags)) {
-       rpmio_flags = _free(rpmio_flags);
+    /* If not configured or bogus, fall back to gz */
+    if (rpmio_flags[0] != 'w') {
+       free(rpmio_flags);
        rpmio_flags = xstrdup("w9.gzdio");
     }
     s = strchr(rpmio_flags, '.');