diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2010-05-28 12:57:59 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2010-05-28 12:57:59 +0300 |
commit | 1dd5b084bd86b0c18016eaa678ab83c447ec3c9d (patch) | |
tree | 66fe4191e73ad8a5f8345ea395c7f62f14ff5232 /lib/verify.c | |
parent | 00f1a6e0b1805c2c0f9ff314aabce8f9ca209f4c (diff) | |
download | librpm-tizen-1dd5b084bd86b0c18016eaa678ab83c447ec3c9d.tar.gz librpm-tizen-1dd5b084bd86b0c18016eaa678ab83c447ec3c9d.tar.bz2 librpm-tizen-1dd5b084bd86b0c18016eaa678ab83c447ec3c9d.zip |
Add internal helper for formatting file attribute strings
- Eliminates some copy-paste slopping. Verify code traditionally only
shows the first attribute, take care to keep that format to avoid
breaking scripts unnecessarily
Diffstat (limited to 'lib/verify.c')
-rw-r--r-- | lib/verify.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/lib/verify.c b/lib/verify.c index ac561da2d..8d958ae90 100644 --- a/lib/verify.c +++ b/lib/verify.c @@ -306,6 +306,21 @@ char * rpmVerifyString(uint32_t verifyResult, const char *pad) #undef aok #undef unknown +char * rpmFFlagsString(uint32_t fflags, const char *pad) +{ + char *fmt = NULL; + rasprintf(&fmt, "%s%s%s%s%s%s%s%s", + (fflags & RPMFILE_DOC) ? "d" : pad, + (fflags & RPMFILE_CONFIG) ? "c" : pad, + (fflags & RPMFILE_SPECFILE) ? "s" : pad, + (fflags & RPMFILE_MISSINGOK) ? "m" : pad, + (fflags & RPMFILE_NOREPLACE) ? "n" : pad, + (fflags & RPMFILE_GHOST) ? "g" : pad, + (fflags & RPMFILE_LICENSE) ? "l" : pad, + (fflags & RPMFILE_README) ? "r" : pad); + return fmt; +} + /** * Check file info from header against what's actually installed. * @param ts transaction set @@ -323,7 +338,8 @@ static int verifyHeader(rpmts ts, Header h, rpmVerifyAttrs omitMask, int ghosts) rpmfiInit(fi, 0); while (rpmfiNext(fi) >= 0) { rpmfileAttrs fileAttrs = rpmfiFFlags(fi); - char *buf = NULL; + char *buf = NULL, *attrFormat; + char ac; int rc; /* If not verifying %ghost, skip ghost files. */ @@ -341,16 +357,11 @@ static int verifyHeader(rpmts ts, Header h, rpmVerifyAttrs omitMask, int ghosts) rpmdbFreeIterator(mi); } + attrFormat = rpmFFlagsString(fileAttrs, ""); + ac = rstreq(attrFormat, "") ? ' ' : attrFormat[0]; if (rc) { if (!(fileAttrs & (RPMFILE_MISSINGOK|RPMFILE_GHOST)) || rpmIsVerbose()) { - rasprintf(&buf, _("missing %c %s"), - ((fileAttrs & RPMFILE_CONFIG) ? 'c' : - (fileAttrs & RPMFILE_DOC) ? 'd' : - (fileAttrs & RPMFILE_GHOST) ? 'g' : - (fileAttrs & RPMFILE_LICENSE) ? 'l' : - (fileAttrs & RPMFILE_PUBKEY) ? 'P' : - (fileAttrs & RPMFILE_README) ? 'r' : ' '), - rpmfiFN(fi)); + rasprintf(&buf, _("missing %c %s"), ac, rpmfiFN(fi)); if ((verifyResult & RPMVERIFY_LSTATFAIL) != 0 && errno != ENOENT) { char *app; @@ -362,18 +373,12 @@ static int verifyHeader(rpmts ts, Header h, rpmVerifyAttrs omitMask, int ghosts) } } else if (verifyResult || rpmIsVerbose()) { char *verifyFormat = rpmVerifyString(verifyResult, "."); - rasprintf(&buf, "%s %c %s", verifyFormat, - ((fileAttrs & RPMFILE_CONFIG) ? 'c' : - (fileAttrs & RPMFILE_DOC) ? 'd' : - (fileAttrs & RPMFILE_GHOST) ? 'g' : - (fileAttrs & RPMFILE_LICENSE) ? 'l' : - (fileAttrs & RPMFILE_PUBKEY) ? 'P' : - (fileAttrs & RPMFILE_README) ? 'r' : ' '), - rpmfiFN(fi)); + rasprintf(&buf, "%s %c %s", verifyFormat, ac, rpmfiFN(fi)); free(verifyFormat); if (verifyResult) ec = 1; } + free(attrFormat); if (buf) { rpmlog(RPMLOG_NOTICE, "%s\n", buf); |