Blame SOURCES/0019-reflink-use-rpmpluginsCallFsmFileArchiveReader-to-pr.patch

629b27
From 5f762af17c6e72e86e4710975dcdfd71fc5d1b07 Mon Sep 17 00:00:00 2001
629b27
From: chantra <chantr4@gmail.com>
629b27
Date: Tue, 8 Feb 2022 18:24:12 -0800
629b27
Subject: [PATCH 19/30] [reflink] use `rpmpluginsCallFsmFileArchiveReader` to
629b27
 provide custom rpmfi
629b27
629b27
As the plugin can now be responsible to provide an Archive Reader to
629b27
`rpmPackageFilesInstall`, we also don't need to mutate the
629b27
`RPMTAG_PAYLOADFORMAT` header in memory, removing some special-casing.
629b27
---
629b27
 lib/depends.c     |  2 --
629b27
 lib/fsm.c         | 38 +++++++++++++++++++-------------------
629b27
 plugins/reflink.c | 18 +++++++++++++-----
629b27
 3 files changed, 32 insertions(+), 26 deletions(-)
629b27
629b27
diff --git a/lib/depends.c b/lib/depends.c
629b27
index 8998afcd3..30234df3d 100644
629b27
--- a/lib/depends.c
629b27
+++ b/lib/depends.c
629b27
@@ -81,8 +81,6 @@ static rpmRC headerCheckPayloadFormat(Header h) {
629b27
      */
629b27
     if (!payloadfmt) return rc;
629b27
 
629b27
-    if (rstreq(payloadfmt, "clon")) return rc;
629b27
-
629b27
     if (!rstreq(payloadfmt, "cpio")) {
629b27
         char *nevra = headerGetAsString(h, RPMTAG_NEVRA);
629b27
         if (payloadfmt && rstreq(payloadfmt, "drpm")) {
629b27
diff --git a/lib/fsm.c b/lib/fsm.c
629b27
index 711f553d3..6972602e0 100644
629b27
--- a/lib/fsm.c
629b27
+++ b/lib/fsm.c
629b27
@@ -19,7 +19,6 @@
629b27
 
629b27
 #include "rpmio/rpmio_internal.h"	/* fdInit/FiniDigest */
629b27
 #include "lib/fsm.h"
629b27
-#include "lib/rpmlib.h"
629b27
 #include "lib/rpmte_internal.h"	/* XXX rpmfs */
629b27
 #include "lib/rpmplugins.h"	/* rpm plugins hooks */
629b27
 #include "lib/rpmug.h"
629b27
@@ -892,14 +891,6 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
629b27
     struct filedata_s *fdata = xcalloc(fc, sizeof(*fdata));
629b27
     struct filedata_s *firstlink = NULL;
629b27
 
629b27
-    Header h = rpmteHeader(te);
629b27
-    const char *payloadfmt = headerGetString(h, RPMTAG_PAYLOADFORMAT);
629b27
-    int cpio = 1;
629b27
-
629b27
-    if (payloadfmt && rstreq(payloadfmt, "clon")) {
629b27
-	cpio = 0;
629b27
-    }
629b27
-
629b27
     /* transaction id used for temporary path suffix while installing */
629b27
     rasprintf(&tid, ";%08x", (unsigned)rpmtsGetTid(ts));
629b27
 
629b27
@@ -933,14 +924,24 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
629b27
     if (rc)
629b27
 	goto exit;
629b27
 
629b27
-    if (cpio) {
629b27
-	fi = rpmfiNewArchiveReader(payload, files, RPMFI_ITER_READ_ARCHIVE);
629b27
-	if (fi == NULL) {
629b27
-	    rc = RPMERR_BAD_MAGIC;
629b27
-	    goto exit;
629b27
-	}
629b27
-    } else {
629b27
-	fi = rpmfilesIter(files, RPMFI_ITER_FWD);
629b27
+    rpmRC plugin_rc = rpmpluginsCallFsmFileArchiveReader(plugins, payload, files, &fi);
629b27
+    switch(plugin_rc) {
629b27
+	case RPMRC_PLUGIN_CONTENTS:
629b27
+	    if(fi == NULL) {
629b27
+		rc = RPMERR_BAD_MAGIC;
629b27
+		goto exit;
629b27
+	    }
629b27
+	    rc = RPMRC_OK;
629b27
+	    break;
629b27
+	case RPMRC_OK:
629b27
+	    fi = rpmfiNewArchiveReader(payload, files, RPMFI_ITER_READ_ARCHIVE);
629b27
+	    if (fi == NULL) {
629b27
+		rc = RPMERR_BAD_MAGIC;
629b27
+		goto exit;
629b27
+	    }
629b27
+	    break;
629b27
+	default:
629b27
+	    rc = RPMRC_FAIL;
629b27
     }
629b27
 
629b27
     /* Detect and create directories not explicitly in package. */
629b27
@@ -988,7 +989,7 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
629b27
 	    } else if (S_ISREG(fp->sb.st_mode)) {
629b27
 		if (rc == RPMERR_ENOENT) {
629b27
 		    rc = fsmMkfile(fi, fp, files, psm, nodigest,
629b27
-			&firstlink, &firstlinkfile);
629b27
+				   &firstlink, &firstlinkfile);
629b27
 		}
629b27
             } else if (S_ISDIR(fp->sb.st_mode)) {
629b27
                 if (rc == RPMERR_ENOENT) {
629b27
@@ -1096,7 +1097,6 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
629b27
     rpmswAdd(rpmtsOp(ts, RPMTS_OP_DIGEST), fdOp(payload, FDSTAT_DIGEST));
629b27
 
629b27
 exit:
629b27
-    h = headerFree(h);
629b27
     fi = rpmfiFree(fi);
629b27
     Fclose(payload);
629b27
     free(tid);
629b27
diff --git a/plugins/reflink.c b/plugins/reflink.c
629b27
index 7dda06d8e..d5e6db27a 100644
629b27
--- a/plugins/reflink.c
629b27
+++ b/plugins/reflink.c
629b27
@@ -54,6 +54,7 @@ struct reflink_state_s {
629b27
     FD_t fd;
629b27
     rpmfiles files;
629b27
     inodeIndexHash inodeIndexes;
629b27
+    int transcoded;
629b27
 };
629b27
 
629b27
 typedef struct reflink_state_s * reflink_state;
629b27
@@ -116,12 +117,8 @@ static rpmRC reflink_psm_pre(rpmPlugin plugin, rpmte te) {
629b27
 	    break;
629b27
     }
629b27
     rpmlog(RPMLOG_DEBUG, _("reflink: *is* transcoded\n"));
629b27
-    Header h = rpmteHeader(te);
629b27
+    state->transcoded = 1;
629b27
 
629b27
-    /* replace/add header that main fsm.c can read */
629b27
-    headerDel(h, RPMTAG_PAYLOADFORMAT);
629b27
-    headerPutString(h, RPMTAG_PAYLOADFORMAT, "clon");
629b27
-    headerFree(h);
629b27
     state->files = rpmteFiles(te);
629b27
     /* tail of file contains offset_table, offset_checksums then magic */
629b27
     if (Fseek(state->fd, -(sizeof(rpm_loff_t) * 2 + sizeof(extents_magic_t)), SEEK_END) < 0) {
629b27
@@ -350,10 +347,21 @@ static rpmRC reflink_fsm_file_install(rpmPlugin plugin, rpmfi fi, const char* pa
629b27
     return RPMRC_OK;
629b27
 }
629b27
 
629b27
+static rpmRC reflink_fsm_file_archive_reader(rpmPlugin plugin, FD_t payload,
629b27
+					     rpmfiles files, rpmfi *fi) {
629b27
+    reflink_state state = rpmPluginGetData(plugin);
629b27
+    if(state->transcoded) {
629b27
+	*fi = rpmfilesIter(files, RPMFI_ITER_FWD);
629b27
+	return RPMRC_PLUGIN_CONTENTS;
629b27
+    }
629b27
+    return RPMRC_OK;
629b27
+}
629b27
+
629b27
 struct rpmPluginHooks_s reflink_hooks = {
629b27
     .init = reflink_init,
629b27
     .cleanup = reflink_cleanup,
629b27
     .psm_pre = reflink_psm_pre,
629b27
     .psm_post = reflink_psm_post,
629b27
     .fsm_file_install = reflink_fsm_file_install,
629b27
+    .fsm_file_archive_reader = reflink_fsm_file_archive_reader,
629b27
 };
629b27
-- 
629b27
2.35.1
629b27