*/
struct fsm_s {
char * path; /*!< Current file name. */
- rpmcpio_t archive; /*!< cpio archive */
char * buf; /*!< read: Buffer. */
size_t bufsize; /*!< read: Buffer allocated size. */
FSMI_t iter; /*!< File iterator. */
}
static int fsmSetup(FSM_t fsm, fileStage goal,
- rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
+ rpmts ts, rpmte te, rpmfi fi,
char ** failedFile)
{
int rc = 0;
if (isSrc) {
fsm->mapFlags |= CPIO_FOLLOW_SYMLINKS;
}
- fsm->archive = rpmcpioOpen(cfd, O_WRONLY);
} else {
if (!isSrc) {
fsm->mapFlags |= CPIO_SBIT_CHECK;
}
- fsm->archive = rpmcpioOpen(cfd, O_RDONLY);
}
if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
if (fsm->failedFile)
*fsm->failedFile = NULL;
- if (cfd != NULL && fsm->archive == NULL)
- rc = 1;
-
return rc;
}
fsm->buf = _free(fsm->buf);
fsm->bufsize = 0;
- rc = rpmcpioClose(fsm->archive) || rc;
-
fsm->iter = mapFreeIterator(fsm->iter);
fsm->failedFile = NULL;
/** \ingroup payload
* Create file from payload stream.
* @param fsm file state machine data
+ * @param archive payload archive
* @return 0 on success
*/
-static int expandRegular(FSM_t fsm, rpmpsm psm)
+static int expandRegular(FSM_t fsm, rpmpsm psm, rpmcpio_t archive)
{
FD_t wfd = NULL;
const struct stat * st = &fsm->sb;
while (left) {
size_t len;
len = (left > fsm->bufsize ? fsm->bufsize : left);
- if (rpmcpioRead(fsm->archive, fsm->buf, len) != len) {
+ if (rpmcpioRead(archive, fsm->buf, len) != len) {
rc = CPIOERR_READ_FAILED;
goto exit;
}
/* don't call this with fileSize == fileComplete */
if (!rc && left)
- rpmpsmNotify(psm, RPMCALLBACK_INST_PROGRESS, rpmcpioTell(fsm->archive));
+ rpmpsmNotify(psm, RPMCALLBACK_INST_PROGRESS, rpmcpioTell(archive));
}
if (st->st_size > 0 && fidigest) {
* Write next item to payload stream.
* @param fsm file state machine data
* @param writeData should data be written?
+ * @param archive payload archive
* @return 0 on success
*/
-static int writeFile(FSM_t fsm, int writeData)
+static int writeFile(FSM_t fsm, int writeData, rpmcpio_t archive)
{
FD_t rfd = NULL;
char * path = fsm->path;
rpmfiBNIndex(fi, fsm->ix)));
}
- rc = rpmcpioHeaderWrite(fsm->archive, fsm->path, st);
+ rc = rpmcpioHeaderWrite(archive, fsm->path, st);
_free(fsm->path);
fsm->path = path;
}
}
- if (rpmcpioWrite(fsm->archive, fsm->buf, len) != len) {
+ if (rpmcpioWrite(archive, fsm->buf, len) != len) {
rc = CPIOERR_WRITE_FAILED;
goto exit;
}
} else if (writeData && S_ISLNK(st->st_mode)) {
size_t len = strlen(symbuf);
- if (rpmcpioWrite(fsm->archive, symbuf, len) != len) {
+ if (rpmcpioWrite(archive, symbuf, len) != len) {
rc = CPIOERR_WRITE_FAILED;
goto exit;
}
/** \ingroup payload
* Write set of linked files to payload stream.
* @param fsm file state machine data
+ * @param archive payload archive
* @return 0 on success
*/
-static int writeLinkedFile(FSM_t fsm)
+static int writeLinkedFile(FSM_t fsm, rpmcpio_t archive)
{
char * path = fsm->path;
const char * nsuffix = fsm->nsuffix;
rc = fsmMapPath(fsm);
/* Write data after last link. */
- rc = writeFile(fsm, (i == 0));
+ rc = writeFile(fsm, (i == 0), archive);
if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
ec = rc;
*fsm->failedFile = xstrdup(fsm->path);
return ec;
}
-static int writeLinks(FSM_t fsm)
+static int writeLinks(FSM_t fsm, rpmcpio_t archive)
{
int j, rc = 0;
nlink_t i, nlink;
fsm->sb = fsm->li->sb; /* structure assignment */
fsm->osb = fsm->sb; /* structure assignment */
- if (!rc) rc = writeLinkedFile(fsm);
+ if (!rc) rc = writeLinkedFile(fsm, archive);
fsm->li = freeHardLink(fsm->li);
}
int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
rpmpsm psm, char ** failedFile)
{
+ rpmcpio_t archive = NULL;
struct fsm_s fsm_;
FSM_t fsm = &fsm_;
struct stat * st = &fsm->sb;
int rc = 0;
int ec = 0;
- rc = fsmSetup(fsm, FSM_PKGINSTALL, ts, te, fi, cfd, failedFile);
+ rc = fsmSetup(fsm, FSM_PKGINSTALL, ts, te, fi, failedFile);
+
+ if (!rc)
+ archive = rpmcpioOpen(cfd, O_RDONLY);
/* transaction id used for temporary path suffix while installing */
rasprintf(&fsm->suffix, ";%08x", (unsigned)rpmtsGetTid(ts));
fsmReset(fsm);
/* Read next payload header. */
- rc = rpmcpioHeaderRead(fsm->archive, &(fsm->path), &(fsm->sb));
+ rc = rpmcpioHeaderRead(archive, &(fsm->path), &(fsm->sb));
/* Detect and exit on end-of-payload. */
if (!rc && rstreq(fsm->path, CPIO_TRAILER))
fsm->path = path;
if (!(rc == CPIOERR_ENOENT)) return rc;
- rc = expandRegular(fsm, psm);
+ rc = expandRegular(fsm, psm, archive);
} else if (S_ISDIR(st->st_mode)) {
rc = fsmVerify(fsm);
if (rc == CPIOERR_ENOENT) {
} else if (S_ISLNK(st->st_mode)) {
if ((st->st_size + 1) > fsm->bufsize) {
rc = CPIOERR_HDR_SIZE;
- } else if (rpmcpioRead(fsm->archive, fsm->buf, st->st_size) != st->st_size) {
+ } else if (rpmcpioRead(archive, fsm->buf, st->st_size) != st->st_size) {
rc = CPIOERR_READ_FAILED;
} else {
}
/* Notify on success. */
- rpmpsmNotify(psm, RPMCALLBACK_INST_PROGRESS, rpmcpioTell(fsm->archive));
+ rpmpsmNotify(psm, RPMCALLBACK_INST_PROGRESS, rpmcpioTell(archive));
if (!fsm->postpone) {
rc = ((S_ISREG(st->st_mode) && st->st_nlink > 1)
}
}
- ec = fsmTeardown(fsm);
+ ec = rpmcpioClose(archive);
+ fsmTeardown(fsm);
/* Return the relevant code: if setup failed, teardown doesn't matter */
return (rc ? rc : ec);
int rc = 0;
int ec = 0;
- rc = fsmSetup(fsm, FSM_PKGERASE, ts, te, fi, NULL, failedFile);
+ rc = fsmSetup(fsm, FSM_PKGERASE, ts, te, fi, failedFile);
while (!rc) {
/* Clean fsm, free'ing memory. */
int rpmPackageFilesArchive(rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
rpm_loff_t * archiveSize, char ** failedFile)
{
+ rpmcpio_t archive = NULL;
struct fsm_s fsm_;
FSM_t fsm = &fsm_;
int rc = 0;
int ec = 0;
- rc = fsmSetup(fsm, FSM_PKGBUILD, ts, te, fi, cfd, failedFile);
+ rc = fsmSetup(fsm, FSM_PKGBUILD, ts, te, fi, failedFile);
+ if (!rc)
+ archive = rpmcpioOpen(cfd, O_WRONLY);
while (!rc) {
fsmReset(fsm);
/* Hardlinks are handled later */
if (!(S_ISREG(fsm->sb.st_mode) && fsm->sb.st_nlink > 1)) {
/* Copy file into archive. */
- rc = writeFile(fsm, 1);
+ rc = writeFile(fsm, 1, archive);
}
if (rc) {
/* Flush partial sets of hard linked files. */
if (!rc)
- rc = writeLinks(fsm);
+ rc = writeLinks(fsm, archive);
if (archiveSize)
- *archiveSize = (rc == 0) ? rpmcpioTell(fsm->archive) : 0;
+ *archiveSize = (rc == 0) ? rpmcpioTell(archive) : 0;
- ec = fsmTeardown(fsm);
+ ec = rpmcpioClose(archive);
+ fsmTeardown(fsm);
/* Return the relevant code: if setup failed, teardown doesn't matter */
return (rc ? rc : ec);