Panu Matilainen 2bbb20
commit 1ac9e84d9a4a04df7c8f659a8df676fc4f8544f0
Panu Matilainen 2bbb20
Author: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen 2bbb20
Date:   Fri Jul 5 10:27:18 2013 +0300
Panu Matilainen 2bbb20
Panu Matilainen 2bbb20
    Ensure relocatable packages always get install-prefix(es) set (RhBug:979443)
Panu Matilainen 2bbb20
    
Panu Matilainen 2bbb20
    - Scriptlets from relocatable packages should always run with
Panu Matilainen 2bbb20
      $RPM_INSTALL_PREFIX* defined, whether actually being relocated or not.
Panu Matilainen 2bbb20
    - Fixes regression introduced by the optimization in commit
Panu Matilainen 2bbb20
      5d3018c4ed476b1b7ac18e2573af517f872cb303. We always need to call
Panu Matilainen 2bbb20
      addPrefixes() but return early from rpmRelocateFileList() when
Panu Matilainen 2bbb20
      no relocations are taking place, fixing the performance regression
Panu Matilainen 2bbb20
      introduced all the way back in cb8241dda783f7e8c143b08fecf57fe89a39c3a6
Panu Matilainen 2bbb20
      which is what 5d3018c4ed476b1b7ac18e2573af517f872cb303 was trying
Panu Matilainen 2bbb20
      to fix. Pooh :)
Panu Matilainen 2bbb20
    
Panu Matilainen 2bbb20
    (cherry picked from commit 88d24b14a8e0e33e768cb74a3487acf0925b012a)
Panu Matilainen 2bbb20
Panu Matilainen 2bbb20
diff --git a/lib/rpmfi.c b/lib/rpmfi.c
Panu Matilainen 2bbb20
index 0bfb5dd..185deae 100644
Panu Matilainen 2bbb20
--- a/lib/rpmfi.c
Panu Matilainen 2bbb20
+++ b/lib/rpmfi.c
Panu Matilainen 2bbb20
@@ -793,7 +793,8 @@ static int addPrefixes(Header h, rpmRelocation *relocations, int numRelocations)
Panu Matilainen 2bbb20
 	headerPutStringArray(h, RPMTAG_INSTPREFIXES, actualRelocations, numActual);
Panu Matilainen 2bbb20
     }
Panu Matilainen 2bbb20
     free(actualRelocations);
Panu Matilainen 2bbb20
-    return numActual;
Panu Matilainen 2bbb20
+    /* When any relocations are present there'll be more work to do */
Panu Matilainen 2bbb20
+    return 1;
Panu Matilainen 2bbb20
 }
Panu Matilainen 2bbb20
 
Panu Matilainen 2bbb20
 static void saveRelocs(Header h, rpmtd bnames, rpmtd dnames, rpmtd dindexes)
Panu Matilainen 2bbb20
@@ -835,7 +836,8 @@ void rpmRelocateFileList(rpmRelocation *relocations, int numRelocations,
Panu Matilainen 2bbb20
     int i, j;
Panu Matilainen 2bbb20
     struct rpmtd_s bnames, dnames, dindexes, fmodes;
Panu Matilainen 2bbb20
 
Panu Matilainen 2bbb20
-    addPrefixes(h, relocations, numRelocations);
Panu Matilainen 2bbb20
+    if (!addPrefixes(h, relocations, numRelocations))
Panu Matilainen 2bbb20
+	return;
Panu Matilainen 2bbb20
 
Panu Matilainen 2bbb20
     if (!_printed) {
Panu Matilainen 2bbb20
 	_printed = 1;
Panu Matilainen 2bbb20
diff --git a/lib/rpmte.c b/lib/rpmte.c
Panu Matilainen 2bbb20
index 6afd69e..87fb391 100644
Panu Matilainen 2bbb20
--- a/lib/rpmte.c
Panu Matilainen 2bbb20
+++ b/lib/rpmte.c
Panu Matilainen 2bbb20
@@ -98,7 +98,7 @@ static rpmfi getFI(rpmte p, Header h)
Panu Matilainen 2bbb20
 				      (RPMFI_NOHEADER | RPMFI_FLAGS_ERASE);
Panu Matilainen 2bbb20
 
Panu Matilainen 2bbb20
     /* relocate stuff in header if necessary */
Panu Matilainen 2bbb20
-    if (rpmteType(p) == TR_ADDED && rpmfsFC(p->fs) > 0 && p->nrelocs) {
Panu Matilainen 2bbb20
+    if (rpmteType(p) == TR_ADDED && rpmfsFC(p->fs) > 0) {
Panu Matilainen 2bbb20
 	if (!headerIsSource(h) && !headerIsEntry(h, RPMTAG_ORIGBASENAMES)) {
Panu Matilainen 2bbb20
 	    rpmRelocateFileList(p->relocs, p->nrelocs, p->fs, h);
Panu Matilainen 2bbb20
 	}