Make sure installed files have state (rhbz#492947)
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 3 Apr 2009 07:28:59 +0000 (10:28 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 3 Apr 2009 11:39:40 +0000 (14:39 +0300)
- rpmfsSetState() doesn't get called for skipped files like %ghost and
  %config(noreplace), causing incorrect file state ("no state") getting
  recorded in rpmdb, leading to inapproriate removal/rename on erase, ick
- For TR_ADDED, always default file states to RPMFILE_STATE_NORMAL, fsm
  changes it as necessary for skipped colors and such. Lazy alloc on
  rpmfsSetState() is not correct as rpmfsSetState() might not get called
  at all.
- originally broken by commit 8d6c4b8c95b59f5a71d90c582c2e98f5c7ed7b9d
(cherry picked from commit c40f6d5dcabfe0b68b830d96b01eaedac0b2d18d)

lib/fsm.c
lib/rpmte.c
lib/rpmte_internal.h

index b892b03..752f0cc 100644 (file)
--- a/lib/fsm.c
+++ b/lib/fsm.c
@@ -663,8 +663,6 @@ static int fsmMapPath(FSM_t fsm)
            break;
        case FA_COPYIN:
        case FA_CREATE:
-           if (rpmteType(te) == TR_ADDED)
-               rpmfsSetState(fs, i, RPMFILE_STATE_NORMAL);
            break;
 
        case FA_SKIPNSTATE:
index bda5411..284cdd7 100644 (file)
@@ -286,7 +286,7 @@ static void addTE(rpmts ts, rpmte p, Header h,
        struct rpmtd_s bnames;
        headerGet(h, RPMTAG_BASENAMES, &bnames, HEADERGET_MINMEM);
 
-       p->fs = rpmfsNew(rpmtdCount(&bnames));
+       p->fs = rpmfsNew(rpmtdCount(&bnames), p->type);
 
        rpmtdFreeData(&bnames);
     }
@@ -912,11 +912,15 @@ rpmfs rpmteGetFileStates(rpmte te) {
     return te->fs;
 }
 
-rpmfs rpmfsNew(unsigned int fc) {
+rpmfs rpmfsNew(unsigned int fc, rpmElementType type) {
     rpmfs fs = xmalloc(sizeof(*fs));
     fs->fc = fc;
     fs->replaced = NULL;
     fs->states = NULL;
+    if (type == TR_ADDED) {
+       fs->states = xmalloc(sizeof(*fs->states) * fs->fc);
+       memset(fs->states, RPMFILE_STATE_NORMAL, fs->fc);
+    }
     fs->actions = xmalloc(fc * sizeof(*fs->actions));
     memset(fs->actions, FA_UNKNOWN, fc * sizeof(*fs->actions));
     fs->numReplaced = fs->allocatedReplaced = 0;
@@ -974,10 +978,6 @@ sharedFileInfo rpmfsNextReplaced(rpmfs fs , sharedFileInfo replaced)
 void rpmfsSetState(rpmfs fs, unsigned int ix, rpmfileState state)
 {
     assert(ix < fs->fc);
-    if (fs->states == NULL) {
-       fs->states = xmalloc(sizeof(*fs->states) * fs->fc);
-       memset(fs->states, RPMFILE_STATE_MISSING, fs->fc);
-    }
     fs->states[ix] = state;
 }
 
index 3ce4112..60c52bd 100644 (file)
@@ -81,7 +81,7 @@ int rpmteHaveTransScript(rpmte te, rpmTag tag);
 rpmfs rpmteGetFileStates(rpmte te);
 
 RPM_GNUC_INTERNAL
-rpmfs rpmfsNew(unsigned int fc);
+rpmfs rpmfsNew(unsigned int fc, rpmElementType type);
 
 RPM_GNUC_INTERNAL
 rpmfs rpmfsFree(rpmfs fs);