From f9b90179b7c80a170969d9ab4c77c0a311635e3f Mon Sep 17 00:00:00 2001
From: Panu Matilainen <pmatilai@redhat.com>
Date: Thu, 11 Feb 2021 14:18:37 +0200
Subject: [PATCH] Add diagnostics to archive unpacking

Conflict:NA
Reference:https://github.com/rpm-software-management/rpm/commit/f9b90179b7c80a170969d9ab4c77c0a311635e3f

Move to a clearly defined helper function, add fsmdebug output.
---
 lib/fsm.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/fsm.c b/lib/fsm.c
index bd2481a50..c065bd55a 100644
--- a/lib/fsm.c
+++ b/lib/fsm.c
@@ -297,6 +297,17 @@ static int fsmOpen(FD_t *wfdp, const char *dest)
     return rc;
 }
 
+static int fsmUnpack(rpmfi fi, FD_t fd, rpmpsm psm, int nodigest)
+{
+    int rc = rpmfiArchiveReadToFilePsm(fi, fd, nodigest, psm);
+    if (_fsm_debug) {
+	rpmlog(RPMLOG_DEBUG, " %8s (%s %lu bytes [%d]) %s\n", __func__,
+	       rpmfiFN(fi), rpmfiFSize(fi), Fileno(fd),
+	       (rc < 0 ? strerror(errno) : ""));
+    }
+    return rc;
+}
+
 static int fsmMkfile(rpmfi fi, struct filedata_s *fp, rpmfiles files,
 		     rpmpsm psm, int nodigest,
 		     struct filedata_s ** firstlink, FD_t *firstlinkfile)
@@ -324,7 +335,7 @@ static int fsmMkfile(rpmfi fi, struct filedata_s *fp, rpmfiles files,
     /* If the file has content, unpack it */
     if (rpmfiArchiveHasContent(fi)) {
 	if (!rc)
-	    rc = rpmfiArchiveReadToFilePsm(fi, fd, nodigest, psm);
+	    rc = fsmUnpack(fi, fd, psm, nodigest);
 	/* Last file of hardlink set, ensure metadata gets set */
 	if (*firstlink) {
 	    (*firstlink)->setmeta = 1;
-- 
2.27.0

