From d0b01bb4366ca467bfd1386820fe17ae58aa3c8c Mon Sep 17 00:00:00 2001
From: Roberto Sassu <roberto.sassu@huawei.com>
Date: Wed, 17 Mar 2021 17:25:46 +0100
Subject: [PATCH] Avoid generating digest lists if they are already packaged

---
 build/files.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/build/files.c b/build/files.c
index d5c83a094..a30828e1c 100644
--- a/build/files.c
+++ b/build/files.c
@@ -51,6 +51,7 @@
 #define DEBUG_ID_DIR		"/usr/lib/debug/.build-id"
 #define DEBUG_DWZ_DIR 		"/usr/lib/debug/.dwz"
 #define DIGEST_LIST_DIR		"/.digest_lists"
+#define DEST_DIGEST_LIST_DIR	"/etc/ima/digest_lists"
 
 #undef HASHTYPE
 #undef HTKEYTYPE
@@ -993,7 +994,7 @@ static void genDigestListInput(FileList fl, Package pkg, int isSrc)
     char buf[BUFSIZ];
     char file_info[BUFSIZ];
     char file_digest[128 * 2 + 1];
-    int i;
+    int i, gen_digest_lists = 1;
     uint32_t defaultalgo = PGPHASHALGO_MD5, digestalgo;
     Header h = pkg->header; /* just a shortcut */
 
@@ -1100,9 +1101,15 @@ static void genDigestListInput(FileList fl, Package pkg, int isSrc)
 		strlen(flp->caps) ? flp->caps : "");
 	    appendStringBuf(check_fileList_bin_pkg, file_info);
 	}
+
+	if (S_ISREG(flp->fl_mode) &&
+	    !strncmp(flp->cpioPath, DEST_DIGEST_LIST_DIR,
+		     sizeof(DEST_DIGEST_LIST_DIR) - 1))
+		gen_digest_lists = 0;
     }
 
-    if (genDigestList(pkg->header, fl, check_fileList_bin_pkg) > 0)
+    if (gen_digest_lists &&
+		genDigestList(pkg->header, fl, check_fileList_bin_pkg) > 0)
 	fl->processingFailed = 1;
 }
 
-- 
2.26.2

