summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2012-01-17 09:01:38 +0200
committerPanu Matilainen <pmatilai@redhat.com>2012-01-17 09:03:55 +0200
commitff743250885123fc6666be38df59818fcb60cf82 (patch)
treef2d6dadcaa7a7996092690d1075bac0da1f92fff
parent9834b743d61a2c996a99cc6f1451d3b00e78fabe (diff)
downloadrpm-ff743250885123fc6666be38df59818fcb60cf82.tar.gz
rpm-ff743250885123fc6666be38df59818fcb60cf82.tar.bz2
rpm-ff743250885123fc6666be38df59818fcb60cf82.zip
Eliminate file digest related members from fsm struct
- Both digest algo and the current file digest from header are only needed inside expandRegular(), push the stuff down there.
-rw-r--r--lib/fsm.c43
-rw-r--r--lib/fsm.h2
2 files changed, 16 insertions, 29 deletions
diff --git a/lib/fsm.c b/lib/fsm.c
index 2ca32a6c9..21b9c9a6b 100644
--- a/lib/fsm.c
+++ b/lib/fsm.c
@@ -597,7 +597,6 @@ static int fsmSetup(FSM_t fsm, fileStage goal,
}
fsm->cpioPos = 0;
fsm->iter = mapInitIterator(ts, te, fi);
- fsm->digestalgo = rpmfiDigestAlgo(fi);
fsm->psm = psm;
fsm->sehandle = rpmtsSELabelHandle(ts);
@@ -753,18 +752,6 @@ static int fsmMapAttrs(FSM_t fsm)
st->st_uid = uid;
if (fsm->mapFlags & CPIO_MAP_GID)
st->st_gid = gid;
-
- { rpmts ts = fsmGetTs(fsm);
-
- /*
- * Set file digest (if not disabled).
- */
- if (ts != NULL && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOFILEDIGEST)) {
- fsm->digest = rpmfiFDigestIndex(fi, i, NULL, NULL);
- } else {
- fsm->digest = NULL;
- }
- }
}
return 0;
}
@@ -778,14 +765,22 @@ static int expandRegular(FSM_t fsm)
{
const struct stat * st = &fsm->sb;
rpm_loff_t left = st->st_size;
+ const unsigned char * fidigest = NULL;
+ pgpHashAlgo digestalgo = 0;
int rc = 0;
rc = fsmNext(fsm, FSM_WOPEN);
if (rc)
goto exit;
- if (st->st_size > 0 && fsm->digest != NULL)
- fdInitDigest(fsm->wfd, fsm->digestalgo, 0);
+ if (!(rpmtsFlags(fsmGetTs(fsm)) & RPMTRANS_FLAG_NOFILEDIGEST)) {
+ rpmfi fi = fsmGetFi(fsm);
+ digestalgo = rpmfiDigestAlgo(fi);
+ fidigest = rpmfiFDigestIndex(fi, fsm->ix, NULL, NULL);
+ }
+
+ if (st->st_size > 0 && fidigest)
+ fdInitDigest(fsm->wfd, digestalgo, 0);
while (left) {
@@ -805,26 +800,20 @@ static int expandRegular(FSM_t fsm)
(void) fsmNext(fsm, FSM_NOTIFY);
}
- if (st->st_size > 0 && fsm->digest) {
+ if (st->st_size > 0 && fidigest) {
void * digest = NULL;
- int asAscii = (fsm->digest == NULL ? 1 : 0);
(void) Fflush(fsm->wfd);
- fdFiniDigest(fsm->wfd, fsm->digestalgo, &digest, NULL, asAscii);
-
- if (digest == NULL) {
- rc = CPIOERR_DIGEST_MISMATCH;
- goto exit;
- }
+ fdFiniDigest(fsm->wfd, digestalgo, &digest, NULL, 0);
- if (fsm->digest != NULL) {
- size_t diglen = rpmDigestLength(fsm->digestalgo);
- if (memcmp(digest, fsm->digest, diglen))
+ if (digest != NULL && fidigest != NULL) {
+ size_t diglen = rpmDigestLength(digestalgo);
+ if (memcmp(digest, fidigest, diglen))
rc = CPIOERR_DIGEST_MISMATCH;
} else {
rc = CPIOERR_DIGEST_MISMATCH;
}
- digest = _free(digest);
+ free(digest);
}
exit:
diff --git a/lib/fsm.h b/lib/fsm.h
index a8f8c5a4f..a589bfddb 100644
--- a/lib/fsm.h
+++ b/lib/fsm.h
@@ -144,9 +144,7 @@ struct fsm_s {
cpioMapFlags mapFlags; /*!< Bit(s) to control mapping. */
const char * dirName; /*!< File directory name. */
const char * baseName; /*!< File base name. */
- const unsigned char * digest; /*!< Binary digest (NULL disables). */
struct selabel_handle *sehandle; /*!< SELinux label handle (if any). */
- pgpHashAlgo digestalgo; /*!< File digest algorithm */
unsigned fflags; /*!< File flags. */
rpmFileAction action; /*!< File disposition. */