Add + use internal helper function for setting rpmfi file states
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 17 Nov 2008 15:29:31 +0000 (17:29 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 17 Nov 2008 15:29:31 +0000 (17:29 +0200)
- instead of directly accessing the array from fsm, use a helper function
  which lazily allocates the state array as needed and sets state
- also fixes the silly case of non-installed packages showing their files
  as "normal", ie installed (now it shows "no state" as it's not relevant)

lib/fsm.c
lib/rpmfi.c
lib/rpmfi_internal.h

index d41c54a..c760665 100644 (file)
--- a/lib/fsm.c
+++ b/lib/fsm.c
@@ -643,22 +643,23 @@ static int fsmMapPath(FSM_t fsm)
            break;
        case FA_COPYIN:
        case FA_CREATE:
-assert(rpmteType(fi->te) == TR_ADDED);
+           if (rpmteType(fi->te) == TR_ADDED)
+               rpmfiSetFState(fi, i, RPMFILE_STATE_NORMAL);
            break;
 
        case FA_SKIPNSTATE:
-           if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
-               fi->fstates[i] = RPMFILE_STATE_NOTINSTALLED;
+           if (rpmteType(fi->te) == TR_ADDED)
+               rpmfiSetFState(fi, i, RPMFILE_STATE_NOTINSTALLED);
            break;
 
        case FA_SKIPNETSHARED:
-           if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
-               fi->fstates[i] = RPMFILE_STATE_NETSHARED;
+           if (rpmteType(fi->te) == TR_ADDED)
+               rpmfiSetFState(fi, i, RPMFILE_STATE_NETSHARED);
            break;
 
        case FA_SKIPCOLOR:
-           if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
-               fi->fstates[i] = RPMFILE_STATE_WRONGCOLOR;
+           if (rpmteType(fi->te) == TR_ADDED)
+               rpmfiSetFState(fi, i, RPMFILE_STATE_WRONGCOLOR);
            break;
 
        case FA_BACKUP:
index 25a50ed..005503d 100644 (file)
@@ -1291,13 +1291,12 @@ rpmfi rpmfiNew(const rpmts ts, Header h, rpmTag tagN, rpmfiFlags flags)
        _hgfi(h, RPMTAG_FILEDEPENDSN, &td, scareFlags, fi->fddictn);
     }
 
-    /* XXX States not needed by TR_REMOVED */
+    /*
+     * For installed packages, get the states here. For to-be-installed
+     * packages fi->fstates is lazily created through rpmfiSetFState().
+     * XXX file states not needed at all by TR_REMOVED.
+     */
     _hgfi(h, RPMTAG_FILESTATES, &td, defFlags, fi->fstates);
-    if (fi->fstates == NULL) {
-       fi->fstates = xmalloc(sizeof(*fi->fstates) * fi->fc);
-       /* XXX means we show state "normal" when package not even installed */
-       memset(fi->fstates, RPMFILE_STATE_NORMAL, fi->fc);
-    }
 
     _hgfi(h, RPMTAG_FILECAPS, &td, defFlags, fi->fcaps);
 
@@ -1452,3 +1451,13 @@ rpmfi rpmfiUpdateState(rpmfi fi, rpmts ts, rpmte p)
     return fi;
 }
 
+void rpmfiSetFState(rpmfi fi, int ix, rpmfileState state)
+{
+    if (fi != NULL && ix >= 0 && ix < fi->fc) {
+       if (fi->fstates == NULL) {
+           fi->fstates = xmalloc(sizeof(*fi->fstates) * fi->fc);
+           memset(fi->fstates, RPMFILE_STATE_MISSING, fi->fc);
+       }
+       fi->fstates[ix] = state;
+    }
+}
index 7743735..929b919 100644 (file)
@@ -115,5 +115,8 @@ int nrefs;          /*!< Reference count. */
 RPM_GNUC_INTERNAL
 rpmfi rpmfiUpdateState(rpmfi fi, rpmts ts, rpmte p);
 
+RPM_GNUC_INTERNAL
+void rpmfiSetFState(rpmfi fi, int ix, rpmfileState state);
+
 #endif /* _RPMFI_INTERNAL_H */