summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/pack.c16
-rw-r--r--lib/fsm.c65
-rw-r--r--lib/fsm.h36
-rw-r--r--lib/psm.c9
-rw-r--r--lib/rpmfi.c25
-rw-r--r--lib/rpmfi_internal.h5
6 files changed, 51 insertions, 105 deletions
diff --git a/build/pack.c b/build/pack.c
index 194cc675d..494b13230 100644
--- a/build/pack.c
+++ b/build/pack.c
@@ -42,8 +42,7 @@ static rpmRC cpio_doio(FD_t fdo, Header h, CSA_t csa, const char * fmodeMacro)
rpmfs fs = NULL;
char *failedFile = NULL;
FD_t cfd;
- rpmRC rc = RPMRC_OK;
- int i;
+ int i, fsmrc;
(void) Fflush(fdo);
cfd = Fdopen(fdDup(Fileno(fdo)), fmodeMacro);
@@ -64,24 +63,21 @@ static rpmRC cpio_doio(FD_t fdo, Header h, CSA_t csa, const char * fmodeMacro)
rpmfsSetAction(fs, i, FA_COPYOUT);
}
- if (fsmSetup(rpmfiFSM(fi), FSM_PKGBUILD, ts, te, fi, cfd, NULL,
- &csa->cpioArchiveSize, &failedFile))
- rc = RPMRC_FAIL;
-
- (void) Fclose(cfd);
+ fsmrc = rpmfsmRun(FSM_PKGBUILD, ts, te, fi, cfd, NULL,
+ &csa->cpioArchiveSize, &failedFile);
- if (fsmTeardown(rpmfiFSM(fi)) || rc == RPMRC_FAIL) {
+ if (fsmrc) {
if (failedFile)
rpmlog(RPMLOG_ERR, _("create archive failed on file %s\n"), failedFile);
else
rpmlog(RPMLOG_ERR, _("create archive failed\n"));
- rc = RPMRC_FAIL;
}
free(failedFile);
+ Fclose(cfd);
rpmtsFree(ts);
- return rc;
+ return (fsmrc == 0) ? RPMRC_OK : RPMRC_FAIL;
}
static rpmRC addFileToTag(rpmSpec spec, const char * file,
diff --git a/lib/fsm.c b/lib/fsm.c
index 075e1348f..d3c0c1715 100644
--- a/lib/fsm.c
+++ b/lib/fsm.c
@@ -551,30 +551,6 @@ static hardLink_t freeHardLink(hardLink_t li)
return NULL;
}
-FSM_t newFSM(cpioMapFlags mapflags)
-{
- FSM_t fsm = xcalloc(1, sizeof(*fsm));
- fsm->mapFlags = mapflags;
- return fsm;
-}
-
-FSM_t freeFSM(FSM_t fsm)
-{
- if (fsm) {
- fsm->path = _free(fsm->path);
- while ((fsm->li = fsm->links) != NULL) {
- fsm->links = fsm->li->next;
- fsm->li->next = NULL;
- fsm->li = freeHardLink(fsm->li);
- }
- fsm->dnlx = _free(fsm->dnlx);
- fsm->ldn = _free(fsm->ldn);
- fsm->iter = mapFreeIterator(fsm->iter);
- _free(fsm);
- }
- return NULL;
-}
-
/* forward declaration*/
static int fsmMkdirs(FSM_t fsm);
@@ -612,11 +588,12 @@ static int fsmCreate(FSM_t fsm)
return rc;
}
-int fsmSetup(FSM_t fsm, fileStage goal,
+static int fsmSetup(FSM_t fsm, fileStage goal,
rpmts ts, rpmte te, rpmfi fi, FD_t cfd, rpmpsm psm,
rpm_loff_t * archiveSize, char ** failedFile)
{
int rc, ec = 0;
+ int isSrc = rpmteIsSource(te);
fsm->goal = goal;
if (cfd != NULL) {
@@ -627,6 +604,18 @@ int fsmSetup(FSM_t fsm, fileStage goal,
fsm->digestalgo = rpmfiDigestAlgo(fi);
fsm->psm = psm;
+ fsm->mapFlags = CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
+ if (goal == FSM_PKGBUILD) {
+ fsm->mapFlags |= CPIO_MAP_TYPE;
+ if (isSrc) {
+ fsm->mapFlags |= CPIO_FOLLOW_SYMLINKS;
+ }
+ } else {
+ if (!isSrc) {
+ fsm->mapFlags |= CPIO_SBIT_CHECK;
+ }
+ }
+
fsm->archiveSize = archiveSize;
if (fsm->archiveSize)
*fsm->archiveSize = 0;
@@ -654,7 +643,7 @@ int fsmSetup(FSM_t fsm, fileStage goal,
return ec;
}
-int fsmTeardown(FSM_t fsm)
+static int fsmTeardown(FSM_t fsm)
{
int rc = fsm->rc;
@@ -667,6 +656,15 @@ int fsmTeardown(FSM_t fsm)
fsm->cfd = NULL;
}
fsm->failedFile = NULL;
+
+ fsm->path = _free(fsm->path);
+ while ((fsm->li = fsm->links) != NULL) {
+ fsm->links = fsm->li->next;
+ fsm->li->next = NULL;
+ fsm->li = freeHardLink(fsm->li);
+ }
+ fsm->dnlx = _free(fsm->dnlx);
+ fsm->ldn = _free(fsm->ldn);
return rc;
}
@@ -2321,3 +2319,18 @@ static const char * fileStageString(fileStage a)
default: return "???";
}
}
+
+int rpmfsmRun(fileStage goal, rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
+ rpmpsm psm, rpm_loff_t * archiveSize, char ** failedFile)
+{
+ struct fsm_s fsm;
+ int sc = 0;
+ int ec = 0;
+
+ memset(&fsm, 0, sizeof(fsm));
+ sc = fsmSetup(&fsm, goal, ts, te, fi, cfd, psm, archiveSize, failedFile);
+ ec = fsmTeardown(&fsm);
+
+ /* Return the relevant code: if setup failed, teardown doesn't matter */
+ return (sc ? sc : ec);
+}
diff --git a/lib/fsm.h b/lib/fsm.h
index f98ff8a81..c2cae5bb3 100644
--- a/lib/fsm.h
+++ b/lib/fsm.h
@@ -173,24 +173,7 @@ extern "C" {
#endif
/**
- * Create file state machine instance.
- * @param mapflags CPIO map flags to use
- * @return file state machine
- */
-RPM_GNUC_INTERNAL
-FSM_t newFSM(cpioMapFlags mapflags);
-
-/**
- * Destroy file state machine instance.
- * @param fsm file state machine
- * @return always NULL
- */
-RPM_GNUC_INTERNAL
-FSM_t freeFSM(FSM_t fsm);
-
-/**
- * Load external data into file state machine.
- * @param fsm file state machine
+ * Execute a file state machine goal
* @param goal
* @param ts transaction set
* @param fi transaction element file info
@@ -200,21 +183,8 @@ FSM_t freeFSM(FSM_t fsm);
* @retval failedFile pointer to first file name that failed (malloced)
* @return 0 on success
*/
-int fsmSetup(FSM_t fsm, fileStage goal,
- rpmts ts,
- rpmte te,
- rpmfi fi,
- FD_t cfd,
- rpmpsm psm,
- rpm_loff_t * archiveSize,
- char ** failedFile);
-
-/**
- * Clean file state machine.
- * @param fsm file state machine
- * @return 0 on success
- */
-int fsmTeardown(FSM_t fsm);
+int rpmfsmRun(fileStage goal, rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
+ rpmpsm psm, rpm_loff_t * archiveSize, char ** failedFile);
/**
* File state machine driver.
diff --git a/lib/psm.c b/lib/psm.c
index 53ffda446..1f1bbbb01 100644
--- a/lib/psm.c
+++ b/lib/psm.c
@@ -675,10 +675,9 @@ void rpmpsmNotify(rpmpsm psm, int what, rpm_loff_t amount)
static int runFsm(rpmpsm psm, FD_t payload)
{
- int sc, ec;
+ int rc;
- sc = fsmSetup(rpmfiFSM(psm->fi),
- (psm->goal == PKG_INSTALL) ? FSM_PKGINSTALL : FSM_PKGERASE,
+ rc = rpmfsmRun((psm->goal == PKG_INSTALL) ? FSM_PKGINSTALL : FSM_PKGERASE,
psm->ts, psm->te, psm->fi, payload, psm,
NULL, &psm->failedFile);
if (psm->goal == PKG_INSTALL) {
@@ -687,10 +686,8 @@ static int runFsm(rpmpsm psm, FD_t payload)
rpmswAdd(rpmtsOp(psm->ts, RPMTS_OP_DIGEST),
fdOp(payload, FDSTAT_DIGEST));
}
- ec = fsmTeardown(rpmfiFSM(psm->fi));
- /* Return the relevant code: if setup failed, teardown doesn't matter */
- return (sc ? sc : ec);
+ return rc;
}
/*
diff --git a/lib/rpmfi.c b/lib/rpmfi.c
index 641c924b8..1995541d5 100644
--- a/lib/rpmfi.c
+++ b/lib/rpmfi.c
@@ -15,7 +15,6 @@
#include "lib/rpmfi_internal.h"
#include "lib/rpmte_internal.h" /* relocations */
#include "lib/cpio.h" /* XXX CPIO_FOO */
-#include "lib/fsm.h" /* XXX newFSM() */
#include "debug.h"
@@ -1085,8 +1084,6 @@ rpmfi rpmfiFree(rpmfi fi)
}
}
- fi->fsm = freeFSM(fi->fsm);
-
fi->fn = _free(fi->fn);
fi->apath = _free(fi->apath);
@@ -1279,28 +1276,6 @@ void rpmfiFpLookup(rpmfi fi, fingerPrintCache fpc)
fpLookupList(fpc, fi->dnl, fi->bnl, fi->dil, fi->fc, fi->fps);
}
-FSM_t rpmfiFSM(rpmfi fi)
-{
- if (fi != NULL && fi->fsm == NULL) {
- cpioMapFlags mapflags;
- /* Figure out mapflags:
- * - path, mode, uid and gid are used by everything
- * - all binary packages get SBIT_CHECK set
- * - if archive size is not known, we're only building this package,
- * different rules apply
- */
- mapflags = CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
- if (fi->fiflags & RPMFI_ISBUILD) {
- mapflags |= CPIO_MAP_TYPE;
- if (fi->fiflags & RPMFI_ISSOURCE) mapflags |= CPIO_FOLLOW_SYMLINKS;
- } else {
- if (!(fi->fiflags & RPMFI_ISSOURCE)) mapflags |= CPIO_SBIT_CHECK;
- }
- fi->fsm = newFSM(mapflags);
- }
- return (fi != NULL) ? fi->fsm : NULL;
-}
-
/*
* Generate iterator accessors function wrappers, these do nothing but
* call the corresponding rpmfiFooIndex(fi, fi->[ij])
diff --git a/lib/rpmfi_internal.h b/lib/rpmfi_internal.h
index 5d66fb989..7e1293b85 100644
--- a/lib/rpmfi_internal.h
+++ b/lib/rpmfi_internal.h
@@ -3,7 +3,6 @@
#include <rpm/header.h>
#include <rpm/rpmfi.h>
-#include "lib/fsm.h" /* for FSM_t */
#include "lib/fprint.h"
/*
@@ -72,7 +71,6 @@ struct rpmfi_s {
char * fn; /*!< File name buffer. */
char ** apath;
- FSM_t fsm; /*!< File state machine data. */
rpm_off_t * replacedSizes; /*!< (TR_ADDED) */
int magic;
int nrefs; /*!< Reference count. */
@@ -160,9 +158,6 @@ rpm_loff_t rpmfiFReplacedSize(rpmfi fi);
RPM_GNUC_INTERNAL
void rpmfiFpLookup(rpmfi fi, fingerPrintCache fpc);
-/* XXX can't be internal as build code needs this */
-FSM_t rpmfiFSM(rpmfi fi);
-
#ifdef __cplusplus
}
#endif