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