Eliminate header and rpmte knowledge from rpmfs
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 24 Apr 2012 10:36:38 +0000 (13:36 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 24 Apr 2012 10:36:38 +0000 (13:36 +0300)
- rpmfs is such a low-level construct it doesn't need to know anything
  about the upper layers. Gather the necessary bits of info in the
  sole caller instead and pass only whats needed to rpmfsNew() to
  enable creating a filestate item without having rpmte/header at hand,
  which we'll be needing in the fsm shortly.

lib/rpmfs.c
lib/rpmfs.h
lib/rpmte.c

index 29b5377..764618d 100644 (file)
@@ -1,5 +1,4 @@
 #include "system.h"
-#include <rpm/header.h>
 #include "lib/rpmfs.h"
 #include "debug.h"
 
@@ -14,18 +13,13 @@ struct rpmfs_s {
     int allocatedReplaced;
 };
 
-rpmfs rpmfsNew(Header h, rpmElementType type)
+rpmfs rpmfsNew(rpm_count_t fc, int initState)
 {
-    struct rpmtd_s bnames;
     rpmfs fs = xcalloc(1, sizeof(*fs));
-    
-    headerGet(h, RPMTAG_BASENAMES, &bnames, HEADERGET_MINMEM);
-    fs->fc = rpmtdCount(&bnames);
-    rpmtdFreeData(&bnames);
-
+    fs->fc = fc;
     fs->actions = xmalloc(fs->fc * sizeof(*fs->actions));
     memset(fs->actions, FA_UNKNOWN, fs->fc * sizeof(*fs->actions));
-    if (type == TR_ADDED) {
+    if (initState) {
        fs->states = xmalloc(sizeof(*fs->states) * fs->fc);
        memset(fs->states, RPMFILE_STATE_NORMAL, fs->fc);
     }
index 4253dd2..5f74753 100644 (file)
@@ -2,7 +2,6 @@
 #define _RPMFS_H
 
 #include <rpm/rpmfi.h>
-#include <rpm/rpmte.h>
 
 /** \ingroup rpmfs
  * Transaction element file states.
@@ -24,7 +23,7 @@ extern "C" {
 #endif
 
 RPM_GNUC_INTERNAL
-rpmfs rpmfsNew(Header h, rpmElementType type);
+rpmfs rpmfsNew(rpm_count_t fc, int initState);
 
 RPM_GNUC_INTERNAL
 rpmfs rpmfsFree(rpmfs fs);
index 65d65af..9325d21 100644 (file)
@@ -201,7 +201,7 @@ static void buildRelocs(rpmte p, Header h, rpmRelocation *relocs)
  */
 static int addTE(rpmte p, Header h, fnpyKey key, rpmRelocation * relocs)
 {
-    struct rpmtd_s colls;
+    struct rpmtd_s colls, bnames;
     int rc = 1; /* assume failure */
 
     p->name = headerGetAsString(h, RPMTAG_NAME);
@@ -245,7 +245,11 @@ static int addTE(rpmte p, Header h, fnpyKey key, rpmRelocation * relocs)
     p->obsoletes = rpmdsNew(h, RPMTAG_OBSOLETENAME, 0);
     p->order = rpmdsNew(h, RPMTAG_ORDERNAME, 0);
 
-    p->fs = rpmfsNew(h, p->type);
+    /* Relocation needs to know file count before rpmfiNew() */
+    headerGet(h, RPMTAG_BASENAMES, &bnames, HEADERGET_MINMEM);
+    p->fs = rpmfsNew(rpmtdCount(&bnames), (p->type == TR_ADDED));
+    rpmtdFreeData(&bnames);
+
     p->fi = getFI(p, h);
 
     /* Packages with no files return an empty file info set, NULL is an error */