API for accessing and creating fi->replaced
authorFlorian Festi <ffesti@redhat.com>
Wed, 19 Nov 2008 16:09:57 +0000 (17:09 +0100)
committerFlorian Festi <ffesti@redhat.com>
Mon, 24 Nov 2008 13:03:16 +0000 (14:03 +0100)
 - new API is not compatible with accessing fi->replaced directly!

lib/rpmfi.c
lib/rpmfi_internal.h

index 858c793..e77b078 100644 (file)
@@ -1257,6 +1257,8 @@ fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, fi->Type, fi->fc);
     fi->actions = _free(fi->actions);
     fi->replacedSizes = _free(fi->replacedSizes);
     fi->replaced = _free(fi->replaced);
+    fi->numReplaced = 0;
+    fi->allocatedReplaced = 0;
 
     fi->h = headerFree(fi->h);
 
@@ -1313,6 +1315,9 @@ rpmfi rpmfiNew(const rpmts ts, Header h, rpmTag tagN, rpmfiFlags flags)
     if (fi == NULL)    /* XXX can't happen */
        goto exit;
 
+    fi->replaced = NULL;
+    fi->numReplaced = fi->allocatedReplaced = 0;
+
     fi->magic = RPMFIMAGIC;
     fi->Type = Type;
     fi->i = -1;
@@ -1557,6 +1562,41 @@ rpm_loff_t rpmfiFReplacedSize(rpmfi fi)
     return rsize;
 }
 
+void rpmfiAddReplaced(rpmfi fi, int pkgFileNum, int otherPkg, int otherFileNum)
+{
+    if (!fi->replaced) {
+       fi->replaced = xcalloc(3, sizeof(*fi->replaced));
+       fi->allocatedReplaced = 3;
+    }
+    if (fi->numReplaced>=fi->allocatedReplaced) {
+       fi->allocatedReplaced += (fi->allocatedReplaced>>1) + 2;
+       fi->replaced = xrealloc(fi->replaced, fi->allocatedReplaced*sizeof(*fi->replaced));
+    }
+    fi->replaced[fi->numReplaced].pkgFileNum = pkgFileNum;
+    fi->replaced[fi->numReplaced].otherPkg = otherPkg;
+    fi->replaced[fi->numReplaced].otherFileNum = otherFileNum;
+
+    fi->numReplaced++;
+}
+
+sharedFileInfo rpmfiGetReplaced(rpmfi fi)
+{
+    if (fi && fi->numReplaced)
+        return fi->replaced;
+    else
+        return NULL;
+}
+
+sharedFileInfo rpmfiNextReplaced(rpmfi fi , sharedFileInfo replaced)
+{
+    if (fi && replaced) {
+        replaced++;
+       if (replaced - fi->replaced < fi->numReplaced)
+           return replaced;
+    }
+    return NULL;
+}
+
 FSM_t rpmfiFSM(rpmfi fi)
 {
     if (fi != NULL && fi->fsm == NULL) {
index 31d2f21..38d916c 100644 (file)
@@ -13,9 +13,8 @@ typedef struct sharedFileInfo_s *             sharedFileInfo;
  */
 struct sharedFileInfo_s {
     int pkgFileNum;
-    int otherFileNum;
     int otherPkg;
-    int isRemoved;
+    int otherFileNum;
 };
 
 /* 
@@ -106,6 +105,8 @@ struct rpmfi_s {
     char ** apath;
     FSM_t fsm;                 /*!< File state machine data. */
     sharedFileInfo replaced;   /*!< (TR_ADDED) */
+    int numReplaced;
+    int allocatedReplaced;
     rpm_off_t * replacedSizes; /*!< (TR_ADDED) */
     int magic;
 #define        RPMFIMAGIC      0x09697923
@@ -126,6 +127,15 @@ void rpmfiSetFReplacedSize(rpmfi fi, rpm_loff_t newsize);
 RPM_GNUC_INTERNAL
 rpm_loff_t rpmfiFReplacedSize(rpmfi fi);
 
+RPM_GNUC_INTERNAL
+void rpmfiAddReplaced(rpmfi fi, int pkgFileNum, int otherPkg, int otherFileNum);
+
+RPM_GNUC_INTERNAL
+sharedFileInfo rpmfiGetReplaced(rpmfi fi);
+
+RPM_GNUC_INTERNAL
+sharedFileInfo rpmfiNextReplaced(rpmfi fi , sharedFileInfo replaced);
+
 /* XXX can't be internal as build code needs this */
 FSM_t rpmfiFSM(rpmfi fi);
 #endif /* _RPMFI_INTERNAL_H */