diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2010-05-28 12:18:26 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2010-05-28 12:18:26 +0300 |
commit | ac0ab016a5ec31e65eb0c0910a5a6f1199aae3e7 (patch) | |
tree | ae924c400d0f4affe86d1cfc0482eed0b6d61d0b | |
parent | a6c8e490236bc373fcb565d30652f69218db2b84 (diff) | |
download | rpm-ac0ab016a5ec31e65eb0c0910a5a6f1199aae3e7.tar.gz rpm-ac0ab016a5ec31e65eb0c0910a5a6f1199aae3e7.tar.bz2 rpm-ac0ab016a5ec31e65eb0c0910a5a6f1199aae3e7.zip |
Add internal helper for formatting verify flags
-rw-r--r-- | lib/formats.c | 26 | ||||
-rw-r--r-- | lib/misc.h | 3 | ||||
-rw-r--r-- | lib/verify.c | 68 |
3 files changed, 42 insertions, 55 deletions
diff --git a/lib/formats.c b/lib/formats.c index 3113c8049..be8a83c05 100644 --- a/lib/formats.c +++ b/lib/formats.c @@ -15,6 +15,7 @@ #include "rpmio/digest.h" #include "lib/manifest.h" +#include "lib/misc.h" #include "debug.h" @@ -638,36 +639,15 @@ static char * fstateFormat(rpmtd td, char * formatPrefix) static char * vflagsFormat(rpmtd td, char * formatPrefix) { char * val = NULL; - char buf[15]; if (rpmtdClass(td) != RPM_NUMERIC_CLASS) { val = xstrdup(_("(not a number)")); } else { - uint64_t vflags = rpmtdGetNumber(td); - buf[0] = '\0'; - if (vflags & RPMVERIFY_FILEDIGEST) - strcat(buf, "5"); - if (vflags & RPMVERIFY_FILESIZE) - strcat(buf, "S"); - if (vflags & RPMVERIFY_LINKTO) - strcat(buf, "L"); - if (vflags & RPMVERIFY_MTIME) - strcat(buf, "T"); - if (vflags & RPMVERIFY_RDEV) - strcat(buf, "D"); - if (vflags & RPMVERIFY_USER) - strcat(buf, "U"); - if (vflags & RPMVERIFY_GROUP) - strcat(buf, "G"); - if (vflags & RPMVERIFY_MODE) - strcat(buf, "M"); - if (vflags & RPMVERIFY_CAPS) - strcat(buf, "P"); - strcat(formatPrefix, "s"); + char *buf = rpmVerifyString(rpmtdGetNumber(td), ""); rasprintf(&val, formatPrefix, buf); + buf = _free(buf); } - return val; } diff --git a/lib/misc.h b/lib/misc.h index fb78b0257..73d95c614 100644 --- a/lib/misc.h +++ b/lib/misc.h @@ -18,6 +18,9 @@ RPM_GNUC_INTERNAL int rpmIsKnownArch(const char *name); RPM_GNUC_INTERNAL +char * rpmVerifyString(uint32_t verifyResult, const char *pad); + +RPM_GNUC_INTERNAL unsigned int hashFunctionString(const char * string); /* * These may be called w/ a NULL argument to flush the cache -- they return diff --git a/lib/verify.c b/lib/verify.c index 904802112..ac561da2d 100644 --- a/lib/verify.c +++ b/lib/verify.c @@ -275,6 +275,37 @@ static int rpmVerifyScript(rpmts ts, Header h) return rc; } +#define unknown "?" +#define _verify(_RPMVERIFY_F, _C, _pad) \ + ((verifyResult & _RPMVERIFY_F) ? _C : _pad) +#define _verifylink(_RPMVERIFY_F, _C, _pad) \ + ((verifyResult & RPMVERIFY_READLINKFAIL) ? unknown : \ + (verifyResult & _RPMVERIFY_F) ? _C : _pad) +#define _verifyfile(_RPMVERIFY_F, _C, _pad) \ + ((verifyResult & RPMVERIFY_READFAIL) ? unknown : \ + (verifyResult & _RPMVERIFY_F) ? _C : _pad) +char * rpmVerifyString(uint32_t verifyResult, const char *pad) +{ + char *fmt = NULL; + rasprintf(&fmt, "%s%s%s%s%s%s%s%s%s", + _verifyfile(RPMVERIFY_FILEDIGEST, "5", pad), + _verify(RPMVERIFY_FILESIZE, "S", pad), + _verifylink(RPMVERIFY_LINKTO, "L", pad), + _verify(RPMVERIFY_MTIME, "T", pad), + _verify(RPMVERIFY_RDEV, "D", pad), + _verify(RPMVERIFY_USER, "U", pad), + _verify(RPMVERIFY_GROUP, "G", pad), + _verify(RPMVERIFY_MODE, "M", pad), + _verify(RPMVERIFY_CAPS, "P", pad)); + + return fmt; +} +#undef _verifyfile +#undef _verifylink +#undef _verify +#undef aok +#undef unknown + /** * Check file info from header against what's actually installed. * @param ts transaction set @@ -330,38 +361,8 @@ static int verifyHeader(rpmts ts, Header h, rpmVerifyAttrs omitMask, int ghosts) ec = rc; } } else if (verifyResult || rpmIsVerbose()) { - const char * size, * filedigest, * link, * mtime, * mode; - const char * group, * user, * rdev, *caps; - static const char *const aok = "."; - static const char *const unknown = "?"; - - if (verifyResult) ec = 1; - -#define _verify(_RPMVERIFY_F, _C) \ - ((verifyResult & _RPMVERIFY_F) ? _C : aok) -#define _verifylink(_RPMVERIFY_F, _C) \ - ((verifyResult & RPMVERIFY_READLINKFAIL) ? unknown : \ - (verifyResult & _RPMVERIFY_F) ? _C : aok) -#define _verifyfile(_RPMVERIFY_F, _C) \ - ((verifyResult & RPMVERIFY_READFAIL) ? unknown : \ - (verifyResult & _RPMVERIFY_F) ? _C : aok) - - filedigest = _verifyfile(RPMVERIFY_FILEDIGEST, "5"); - size = _verify(RPMVERIFY_FILESIZE, "S"); - link = _verifylink(RPMVERIFY_LINKTO, "L"); - mtime = _verify(RPMVERIFY_MTIME, "T"); - rdev = _verify(RPMVERIFY_RDEV, "D"); - user = _verify(RPMVERIFY_USER, "U"); - group = _verify(RPMVERIFY_GROUP, "G"); - mode = _verify(RPMVERIFY_MODE, "M"); - caps = _verify(RPMVERIFY_CAPS, "P"); - -#undef _verifyfile -#undef _verifylink -#undef _verify - - rasprintf(&buf, "%s%s%s%s%s%s%s%s%s %c %s", - size, mode, filedigest, rdev, link, user, group, mtime, caps, + char *verifyFormat = rpmVerifyString(verifyResult, "."); + rasprintf(&buf, "%s %c %s", verifyFormat, ((fileAttrs & RPMFILE_CONFIG) ? 'c' : (fileAttrs & RPMFILE_DOC) ? 'd' : (fileAttrs & RPMFILE_GHOST) ? 'g' : @@ -369,6 +370,9 @@ static int verifyHeader(rpmts ts, Header h, rpmVerifyAttrs omitMask, int ghosts) (fileAttrs & RPMFILE_PUBKEY) ? 'P' : (fileAttrs & RPMFILE_README) ? 'r' : ' '), rpmfiFN(fi)); + free(verifyFormat); + + if (verifyResult) ec = 1; } if (buf) { |