summaryrefslogtreecommitdiff
path: root/backport-Bury-rpmio-FD-use-to-fsmUnpack.patch
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2023-09-10 03:05:12 +0000
committerCoprDistGit <infra@openeuler.org>2023-09-10 03:05:12 +0000
commit2bc2b430bc4c1a9a0bfd1c01da68bd53bf7da052 (patch)
treea2af4fd609c7decacbf0ea11926ea338596fb179 /backport-Bury-rpmio-FD-use-to-fsmUnpack.patch
parent0ae9f87336a3d78d8fbc0a1e5c75cba5f9cf8597 (diff)
automatic import of rpm
Diffstat (limited to 'backport-Bury-rpmio-FD-use-to-fsmUnpack.patch')
-rw-r--r--backport-Bury-rpmio-FD-use-to-fsmUnpack.patch129
1 files changed, 129 insertions, 0 deletions
diff --git a/backport-Bury-rpmio-FD-use-to-fsmUnpack.patch b/backport-Bury-rpmio-FD-use-to-fsmUnpack.patch
new file mode 100644
index 0000000..c735909
--- /dev/null
+++ b/backport-Bury-rpmio-FD-use-to-fsmUnpack.patch
@@ -0,0 +1,129 @@
+From bbc270d78fb361bd78eac9a9117070caeb537d4a Mon Sep 17 00:00:00 2001
+From: Panu Matilainen <pmatilai@redhat.com>
+Date: Mon, 14 Feb 2022 12:35:58 +0200
+Subject: [PATCH] Bury rpmio FD use to fsmUnpack()
+
+fsmUnpack() is the only place in FSM that needs to deal with rpmio FD
+types, everywhere else they are nothing but a hindrance that need to
+be converted to OS level descriptors for use. Better deal with OS
+level descriptors to begin with.
+---
+ lib/fsm.c | 37 ++++++++++++++++---------------------
+ 1 file changed, 16 insertions(+), 21 deletions(-)
+
+diff --git a/lib/fsm.c b/lib/fsm.c
+index 13b1142..b019f57 100644
+--- a/lib/fsm.c
++++ b/lib/fsm.c
+@@ -110,14 +110,14 @@ static int fsmSetFCaps(const char *path, const char *captxt)
+ return rc;
+ }
+
+-static int fsmClose(FD_t *wfdp)
++static int fsmClose(int *wfdp)
+ {
+ int rc = 0;
+- if (wfdp && *wfdp) {
++ if (wfdp && *wfdp >= 0) {
+ int myerrno = errno;
+ static int oneshot = 0;
+ static int flush_io = 0;
+- int fdno = Fileno(*wfdp);
++ int fdno = *wfdp;
+
+ if (!oneshot) {
+ flush_io = (rpmExpandNumeric("%{?_flush_io}") > 0);
+@@ -126,61 +126,56 @@ static int fsmClose(FD_t *wfdp)
+ if (flush_io) {
+ fsync(fdno);
+ }
+- if (Fclose(*wfdp))
++ if (close(fdno))
+ rc = RPMERR_CLOSE_FAILED;
+
+ if (_fsm_debug) {
+ rpmlog(RPMLOG_DEBUG, " %8s ([%d]) %s\n", __func__,
+ fdno, (rc < 0 ? strerror(errno) : ""));
+ }
+- *wfdp = NULL;
++ *wfdp = -1;
+ errno = myerrno;
+ }
+ return rc;
+ }
+
+-static int fsmOpen(FD_t *wfdp, int dirfd, const char *dest)
++static int fsmOpen(int *wfdp, int dirfd, const char *dest)
+ {
+ int rc = 0;
+ /* Create the file with 0200 permissions (write by owner). */
+ int fd = openat(dirfd, dest, O_WRONLY|O_EXCL|O_CREAT, 0200);
+
+- if (fd >= 0) {
+- *wfdp = fdDup(fd);
+- close(fd);
+- }
+-
+- if (fd < 0 || Ferror(*wfdp))
++ if (fd < 0)
+ rc = RPMERR_OPEN_FAILED;
+
+ if (_fsm_debug) {
+ rpmlog(RPMLOG_DEBUG, " %8s (%s [%d]) %s\n", __func__,
+- dest, Fileno(*wfdp), (rc < 0 ? strerror(errno) : ""));
++ dest, fd, (rc < 0 ? strerror(errno) : ""));
+ }
+-
+- if (rc)
+- fsmClose(wfdp);
++ *wfdp = fd;
+
+ return rc;
+ }
+
+-static int fsmUnpack(rpmfi fi, FD_t fd, rpmpsm psm, int nodigest)
++static int fsmUnpack(rpmfi fi, int fdno, rpmpsm psm, int nodigest)
+ {
++ FD_t fd = fdDup(fdno);
+ int rc = rpmfiArchiveReadToFilePsm(fi, fd, nodigest, psm);
+ if (_fsm_debug) {
+ rpmlog(RPMLOG_DEBUG, " %8s (%s %" PRIu64 " bytes [%d]) %s\n", __func__,
+ rpmfiFN(fi), rpmfiFSize(fi), Fileno(fd),
+ (rc < 0 ? strerror(errno) : ""));
+ }
++ Fclose(fd);
+ return rc;
+ }
+
+ static int fsmMkfile(int dirfd, rpmfi fi, struct filedata_s *fp, rpmfiles files,
+ rpmpsm psm, int nodigest,
+- struct filedata_s ** firstlink, FD_t *firstlinkfile)
++ struct filedata_s ** firstlink, int *firstlinkfile)
+ {
+ int rc = 0;
+- FD_t fd = NULL;
++ int fd = -1;
+
+ if (*firstlink == NULL) {
+ /* First encounter, open file for writing */
+@@ -206,7 +201,7 @@ static int fsmMkfile(int dirfd, rpmfi fi, struct filedata_s *fp, rpmfiles files,
+ if (*firstlink) {
+ fp->setmeta = 1;
+ *firstlink = NULL;
+- *firstlinkfile = NULL;
++ *firstlinkfile = -1;
+ }
+ }
+
+@@ -811,7 +806,7 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
+ int fc = rpmfilesFC(files);
+ int nodigest = (rpmtsFlags(ts) & RPMTRANS_FLAG_NOFILEDIGEST) ? 1 : 0;
+ int nofcaps = (rpmtsFlags(ts) & RPMTRANS_FLAG_NOCAPS) ? 1 : 0;
+- FD_t firstlinkfile = NULL;
++ int firstlinkfile = -1;
+ char *tid = NULL;
+ struct filedata_s *fdata = xcalloc(fc, sizeof(*fdata));
+ struct filedata_s *firstlink = NULL;
+--
+1.8.3.1
+