Panu Matilainen 5a40a0
commit 4a16d55f1f689ab06e8dd45c50b86e478a732367
Panu Matilainen 5a40a0
Author: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen 5a40a0
Date:   Tue Mar 8 13:28:32 2011 +0200
Panu Matilainen 5a40a0
Panu Matilainen 5a40a0
    Preferred color pkgs should be erased last
Panu Matilainen 5a40a0
    - On install we need to queue preferred colored pkgs before others
Panu Matilainen 5a40a0
      to account for the way colored files get laid on disk. On erase,
Panu Matilainen 5a40a0
      we need to revert this for the same reason. Most of the time
Panu Matilainen 5a40a0
      dependencies take care of this, but the queue placement matters in
Panu Matilainen 5a40a0
      cases such as RhBug:680261 where the order is not dependency-driven.
Panu Matilainen 5a40a0
Panu Matilainen 5a40a0
diff --git a/lib/order.c b/lib/order.c
Panu Matilainen 5a40a0
index 3b0849d..18fe05c 100644
Panu Matilainen 5a40a0
--- a/lib/order.c
Panu Matilainen 5a40a0
+++ b/lib/order.c
Panu Matilainen 5a40a0
@@ -208,6 +208,8 @@ static void addQ(tsortInfo p, tsortInfo * qp, tsortInfo * rp,
Panu Matilainen 5a40a0
 		rpm_color_t prefcolor)
Panu Matilainen 5a40a0
 {
Panu Matilainen 5a40a0
     tsortInfo q, qprev;
Panu Matilainen 5a40a0
+    rpm_color_t pcolor = rpmteColor(p->te);
Panu Matilainen 5a40a0
+    int tailcond;
Panu Matilainen 5a40a0
 
Panu Matilainen 5a40a0
     /* Mark the package as queued. */
Panu Matilainen 5a40a0
     p->tsi_reqx = 1;
Panu Matilainen 5a40a0
@@ -218,13 +220,18 @@ static void addQ(tsortInfo p, tsortInfo * qp, tsortInfo * rp,
Panu Matilainen 5a40a0
 	return;
Panu Matilainen 5a40a0
     }
Panu Matilainen 5a40a0
 
Panu Matilainen 5a40a0
-    /* Find location in queue using metric tsi_qcnt. */
Panu Matilainen 5a40a0
+    if (rpmteType(p->te) == TR_ADDED)
Panu Matilainen 5a40a0
+	tailcond = (pcolor && pcolor != prefcolor);
Panu Matilainen 5a40a0
+    else
Panu Matilainen 5a40a0
+	tailcond = (pcolor && pcolor == prefcolor);
Panu Matilainen 5a40a0
+
Panu Matilainen 5a40a0
+    /* Find location in queue using metric tsi_qcnt and color. */
Panu Matilainen 5a40a0
     for (qprev = NULL, q = (*qp);
Panu Matilainen 5a40a0
 	 q != NULL;
Panu Matilainen 5a40a0
 	 qprev = q, q = q->tsi_suc)
Panu Matilainen 5a40a0
     {
Panu Matilainen 5a40a0
-	/* XXX Insure preferred color first. */
Panu Matilainen 5a40a0
-	if (rpmteColor(p->te) != prefcolor && rpmteColor(p->te) != rpmteColor(q->te))
Panu Matilainen 5a40a0
+	/* Place preferred color towards queue head on install, tail on erase */
Panu Matilainen 5a40a0
+	if (tailcond && (pcolor != rpmteColor(q->te)))
Panu Matilainen 5a40a0
 	    continue;
Panu Matilainen 5a40a0
 
Panu Matilainen 5a40a0
 	if (q->tsi_qcnt <= p->tsi_qcnt)