teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone
Blob Blame History Raw
From f1e03904fc7173c772cb5795f6df30591f790b01 Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <i.gnatenko.brain@gmail.com>
Date: Fri, 28 Jul 2017 18:30:37 +0200
Subject: [PATCH] store mapping for renamed files

We will need this in next commit so we know which original name
files had, so we can reference appropriate debug file.

Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
---
 build/files.c             | 40 +++++++++++++++++++++++++++++-----------
 build/rpmbuild_internal.h | 12 ++++++++++++
 build/spec.c              |  2 ++
 3 files changed, 43 insertions(+), 11 deletions(-)

diff --git a/build/files.c b/build/files.c
index a29730998..2387a2e5b 100644
--- a/build/files.c
+++ b/build/files.c
@@ -50,6 +50,17 @@
 #define DEBUG_ID_DIR		"/usr/lib/debug/.build-id"
 #define DEBUG_DWZ_DIR 		"/usr/lib/debug/.dwz"
 
+#undef HASHTYPE
+#undef HTKEYTYPE
+#undef HTDATATYPE
+#define HASHTYPE fileRenameHash
+#define HTKEYTYPE const char *
+#define HTDATATYPE char *
+#include "lib/rpmhash.C"
+#undef HASHTYPE
+#undef HTKEYTYPE
+#undef HTDATATYPE
+
 /**
  */
 enum specfFlags_e {
@@ -982,19 +993,26 @@ static void genCpioListAndHeader(FileList fl, Package pkg, int isSrc)
     }
 
     /* Adjust paths if needed */
-    if (!isSrc && pkg->removePostfixes)
-    for (i = 0, flp = fl->files.recs; i < fl->files.used; i++, flp++) {
-	char * cpiopath = flp->cpioPath;
-
-	for (ARGV_const_t postfix_p = pkg->removePostfixes; *postfix_p; postfix_p++) {
-	    int len = strlen(*postfix_p);
-	    int plen = strlen(cpiopath);
-	    if (len <= plen && !strncmp(cpiopath+plen-len, *postfix_p, len)) {
-		cpiopath[plen-len] = '\0';
-		if (plen-len > 0 && cpiopath[plen-len-1] == '/') {
-		    cpiopath[plen-len-1] = '\0';
+    if (!isSrc && pkg->removePostfixes) {
+	pkg->fileRenameMap = fileRenameHashCreate(fl->files.used,
+	                                          rstrhash, strcmp,
+	                                          (fileRenameHashFreeKey)rfree, (fileRenameHashFreeData)rfree);
+	for (i = 0, flp = fl->files.recs; i < fl->files.used; i++, flp++) {
+	    char * cpiopath = flp->cpioPath;
+	    char * cpiopath_orig = xstrdup(cpiopath);
+
+	    for (ARGV_const_t postfix_p = pkg->removePostfixes; *postfix_p; postfix_p++) {
+		int len = strlen(*postfix_p);
+		int plen = strlen(cpiopath);
+		if (len <= plen && !strncmp(cpiopath+plen-len, *postfix_p, len)) {
+		    cpiopath[plen-len] = '\0';
+		    if (plen-len > 0 && cpiopath[plen-len-1] == '/') {
+			cpiopath[plen-len-1] = '\0';
+		    }
 		}
 	    }
+	    if (strcmp(cpiopath_orig, cpiopath))
+		fileRenameHashAddEntry(pkg->fileRenameMap, xstrdup(cpiopath), cpiopath_orig);
 	}
     }
 
diff --git a/build/rpmbuild_internal.h b/build/rpmbuild_internal.h
index 5978a6d32..b4247ae61 100644
--- a/build/rpmbuild_internal.h
+++ b/build/rpmbuild_internal.h
@@ -6,6 +6,17 @@
 #include <rpm/rpmstrpool.h>
 #include "build/rpmbuild_misc.h"
 
+#undef HASHTYPE
+#undef HTKEYTYPE
+#undef HTDATATYPE
+#define HASHTYPE fileRenameHash
+#define HTKEYTYPE const char *
+#define HTDATATYPE char *
+#include "lib/rpmhash.H"
+#undef HASHTYPE
+#undef HTKEYTYPE
+#undef HTDATATYPE
+
 struct TriggerFileEntry {
     int index;
     char * fileName;
@@ -120,6 +131,7 @@ struct Package_s {
     ARGV_t fileList;		/* If NULL, package will not be written */
     ARGV_t fileExcludeList;
     ARGV_t removePostfixes;
+    fileRenameHash fileRenameMap;
     ARGV_t policyList;
 
     Package next;
diff --git a/build/spec.c b/build/spec.c
index c33cde7eb..eaa5dce61 100644
--- a/build/spec.c
+++ b/build/spec.c
@@ -104,6 +104,7 @@ Package newPackage(const char *name, rpmstrPool pool, Package *pkglist)
     p->fileExcludeList = NULL;
     p->fileFile = NULL;
     p->policyList = NULL;
+    p->fileRenameMap = NULL;
     p->pool = rpmstrPoolLink(pool);
     p->dpaths = NULL;
 
@@ -148,6 +149,7 @@ static Package freePackage(Package pkg)
     pkg->fileFile = argvFree(pkg->fileFile);
     pkg->policyList = argvFree(pkg->policyList);
     pkg->removePostfixes = argvFree(pkg->removePostfixes);
+    pkg->fileRenameMap = fileRenameHashFree(pkg->fileRenameMap);
     pkg->cpioList = rpmfilesFree(pkg->cpioList);
     pkg->dpaths = argvFree(pkg->dpaths);