From 4e6583fe23b372829108ad0b4f8d9beaff5600bd Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 9 Dec 2016 11:12:36 +0200 Subject: Refactor package component sizes debug printing out of rpmReadSignature() The big block in rpmReadSignature() was only used for RPMLOG_DEBUG level printing, obfuscating a rather important function needlessly. Move all the data retrieval into printSize() and eliminate the rather pointless return code based on fstat() success. --- lib/signature.c | 57 ++++++++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/lib/signature.c b/lib/signature.c index a01f286cb..10fd95973 100644 --- a/lib/signature.c +++ b/lib/signature.c @@ -120,31 +120,39 @@ exit: } /** - * Print package size. - * @todo rpmio: use fdSize rather than fstat(2) to get file size. + * Print package size (debug purposes only) * @param fd package file handle - * @param siglen signature header size - * @param pad signature padding - * @param datalen length of header+payload - * @return rpmRC return code + * @param sigh signature header */ -static inline rpmRC printSize(FD_t fd, size_t siglen, size_t pad, rpm_loff_t datalen) +static void printSize(FD_t fd, Header sigh) { struct stat st; int fdno = Fileno(fd); - - if (fstat(fdno, &st) < 0) - return RPMRC_FAIL; + size_t siglen = headerSizeof(sigh, HEADER_MAGIC_YES); + size_t pad = (8 - (siglen % 8)) % 8; /* 8-byte pad */ + struct rpmtd_s sizetag; + rpm_loff_t datalen = 0; + + /* Print package component sizes. */ + if (headerGet(sigh, RPMSIGTAG_LONGSIZE, &sizetag, HEADERGET_DEFAULT)) { + rpm_loff_t *tsize = rpmtdGetUint64(&sizetag); + datalen = (tsize) ? *tsize : 0; + } else if (headerGet(sigh, RPMSIGTAG_SIZE, &sizetag, HEADERGET_DEFAULT)) { + rpm_off_t *tsize = rpmtdGetUint32(&sizetag); + datalen = (tsize) ? *tsize : 0; + } + rpmtdFreeData(&sizetag); rpmlog(RPMLOG_DEBUG, "Expected size: %12" PRIu64 \ " = lead(%d)+sigs(%zd)+pad(%zd)+data(%" PRIu64 ")\n", RPMLEAD_SIZE+siglen+pad+datalen, RPMLEAD_SIZE, siglen, pad, datalen); - rpmlog(RPMLOG_DEBUG, - " Actual size: %12" PRIu64 "\n", (rpm_loff_t) st.st_size); - return RPMRC_OK; + if (fstat(fdno, &st) == 0) { + rpmlog(RPMLOG_DEBUG, + " Actual size: %12" PRIu64 "\n", (rpm_loff_t) st.st_size); + } } rpmRC rpmReadSignature(FD_t fd, Header * sighp, char ** msg) @@ -164,28 +172,7 @@ rpmRC rpmReadSignature(FD_t fd, Header * sighp, char ** msg) if (hdrblobImport(&blob, 0, &sigh, &buf) != RPMRC_OK) goto exit; - /* XXX the padding calculation here is only for debug printing */ - { size_t sigSize = headerSizeof(sigh, HEADER_MAGIC_YES); - size_t pad = (8 - (sigSize % 8)) % 8; /* 8-byte pad */ - struct rpmtd_s sizetag; - rpm_loff_t archSize = 0; - - /* Print package component sizes. */ - if (headerGet(sigh, RPMSIGTAG_LONGSIZE, &sizetag, HEADERGET_DEFAULT)) { - rpm_loff_t *tsize = rpmtdGetUint64(&sizetag); - archSize = (tsize) ? *tsize : 0; - } else if (headerGet(sigh, RPMSIGTAG_SIZE, &sizetag, HEADERGET_DEFAULT)) { - rpm_off_t *tsize = rpmtdGetUint32(&sizetag); - archSize = (tsize) ? *tsize : 0; - } - rpmtdFreeData(&sizetag); - rc = printSize(fd, sigSize, pad, archSize); - if (rc != RPMRC_OK) { - rasprintf(&buf, - _("sigh sigSize(%zd): BAD, fstat(2) failed"), sigSize); - goto exit; - } - } + printSize(fd, sigh); rc = RPMRC_OK; exit: -- cgit v1.2.1