Panu Matilainen 1a5c9c
commit 4e77d95a7856216e49453009c855cce701734b9c
Panu Matilainen 1a5c9c
Author: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen 1a5c9c
Date:   Fri Apr 3 10:28:59 2009 +0300
Panu Matilainen 1a5c9c
Panu Matilainen 1a5c9c
    Make sure installed files have state (rhbz#492947)
Panu Matilainen 1a5c9c
    - rpmfsSetState() doesn't get called for skipped files like %ghost and
Panu Matilainen 1a5c9c
      %config(noreplace), causing incorrect file state ("no state") getting
Panu Matilainen 1a5c9c
      recorded in rpmdb, leading to inapproriate removal/rename on erase, ick
Panu Matilainen 1a5c9c
    - For TR_ADDED, always default file states to RPMFILE_STATE_NORMAL, fsm
Panu Matilainen 1a5c9c
      changes it as necessary for skipped colors and such. Lazy alloc on
Panu Matilainen 1a5c9c
      rpmfsSetState() is not correct as rpmfsSetState() might not get called
Panu Matilainen 1a5c9c
      at all.
Panu Matilainen 1a5c9c
    - originally broken by commit 8d6c4b8c95b59f5a71d90c582c2e98f5c7ed7b9d
Panu Matilainen 1a5c9c
Panu Matilainen 1a5c9c
diff --git a/lib/fsm.c b/lib/fsm.c
Panu Matilainen 1a5c9c
index b892b03..752f0cc 100644
Panu Matilainen 1a5c9c
--- a/lib/fsm.c
Panu Matilainen 1a5c9c
+++ b/lib/fsm.c
Panu Matilainen 1a5c9c
@@ -663,8 +663,6 @@ static int fsmMapPath(FSM_t fsm)
Panu Matilainen 1a5c9c
 	    break;
Panu Matilainen 1a5c9c
 	case FA_COPYIN:
Panu Matilainen 1a5c9c
 	case FA_CREATE:
Panu Matilainen 1a5c9c
-	    if (rpmteType(te) == TR_ADDED)
Panu Matilainen 1a5c9c
-		rpmfsSetState(fs, i, RPMFILE_STATE_NORMAL);
Panu Matilainen 1a5c9c
 	    break;
Panu Matilainen 1a5c9c
 
Panu Matilainen 1a5c9c
 	case FA_SKIPNSTATE:
Panu Matilainen 1a5c9c
diff --git a/lib/rpmte.c b/lib/rpmte.c
Panu Matilainen 1a5c9c
index 6ff20f5..e1ef060 100644
Panu Matilainen 1a5c9c
--- a/lib/rpmte.c
Panu Matilainen 1a5c9c
+++ b/lib/rpmte.c
Panu Matilainen 1a5c9c
@@ -285,7 +285,7 @@ static void addTE(rpmts ts, rpmte p, Header h,
Panu Matilainen 1a5c9c
 	struct rpmtd_s bnames;
Panu Matilainen 1a5c9c
 	headerGet(h, RPMTAG_BASENAMES, &bnames, HEADERGET_MINMEM);
Panu Matilainen 1a5c9c
 
Panu Matilainen 1a5c9c
-	p->fs = rpmfsNew(rpmtdCount(&bnames));
Panu Matilainen 1a5c9c
+	p->fs = rpmfsNew(rpmtdCount(&bnames), p->type);
Panu Matilainen 1a5c9c
 
Panu Matilainen 1a5c9c
 	rpmtdFreeData(&bnames);
Panu Matilainen 1a5c9c
     }
Panu Matilainen 1a5c9c
@@ -896,11 +896,15 @@ rpmfs rpmteGetFileStates(rpmte te) {
Panu Matilainen 1a5c9c
     return te->fs;
Panu Matilainen 1a5c9c
 }
Panu Matilainen 1a5c9c
 
Panu Matilainen 1a5c9c
-rpmfs rpmfsNew(unsigned int fc) {
Panu Matilainen 1a5c9c
+rpmfs rpmfsNew(unsigned int fc, rpmElementType type) {
Panu Matilainen 1a5c9c
     rpmfs fs = xmalloc(sizeof(*fs));
Panu Matilainen 1a5c9c
     fs->fc = fc;
Panu Matilainen 1a5c9c
     fs->replaced = NULL;
Panu Matilainen 1a5c9c
     fs->states = NULL;
Panu Matilainen 1a5c9c
+    if (type == TR_ADDED) {
Panu Matilainen 1a5c9c
+	fs->states = xmalloc(sizeof(*fs->states) * fs->fc);
Panu Matilainen 1a5c9c
+	memset(fs->states, RPMFILE_STATE_NORMAL, fs->fc);
Panu Matilainen 1a5c9c
+    }
Panu Matilainen 1a5c9c
     fs->actions = xmalloc(fc * sizeof(*fs->actions));
Panu Matilainen 1a5c9c
     memset(fs->actions, FA_UNKNOWN, fc * sizeof(*fs->actions));
Panu Matilainen 1a5c9c
     fs->numReplaced = fs->allocatedReplaced = 0;
Panu Matilainen 1a5c9c
@@ -958,10 +962,6 @@ sharedFileInfo rpmfsNextReplaced(rpmfs fs , sharedFileInfo replaced)
Panu Matilainen 1a5c9c
 void rpmfsSetState(rpmfs fs, unsigned int ix, rpmfileState state)
Panu Matilainen 1a5c9c
 {
Panu Matilainen 1a5c9c
     assert(ix < fs->fc);
Panu Matilainen 1a5c9c
-    if (fs->states == NULL) {
Panu Matilainen 1a5c9c
-	fs->states = xmalloc(sizeof(*fs->states) * fs->fc);
Panu Matilainen 1a5c9c
-	memset(fs->states, RPMFILE_STATE_MISSING, fs->fc);
Panu Matilainen 1a5c9c
-    }
Panu Matilainen 1a5c9c
     fs->states[ix] = state;
Panu Matilainen 1a5c9c
 }
Panu Matilainen 1a5c9c
 
Panu Matilainen 1a5c9c
diff --git a/lib/rpmte_internal.h b/lib/rpmte_internal.h
Panu Matilainen 1a5c9c
index 3ce4112..60c52bd 100644
Panu Matilainen 1a5c9c
--- a/lib/rpmte_internal.h
Panu Matilainen 1a5c9c
+++ b/lib/rpmte_internal.h
Panu Matilainen 1a5c9c
@@ -81,7 +81,7 @@ int rpmteHaveTransScript(rpmte te, rpmTag tag);
Panu Matilainen 1a5c9c
 rpmfs rpmteGetFileStates(rpmte te);
Panu Matilainen 1a5c9c
 
Panu Matilainen 1a5c9c
 RPM_GNUC_INTERNAL
Panu Matilainen 1a5c9c
-rpmfs rpmfsNew(unsigned int fc);
Panu Matilainen 1a5c9c
+rpmfs rpmfsNew(unsigned int fc, rpmElementType type);
Panu Matilainen 1a5c9c
 
Panu Matilainen 1a5c9c
 RPM_GNUC_INTERNAL
Panu Matilainen 1a5c9c
 rpmfs rpmfsFree(rpmfs fs);