Add file verifyflags format extension
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 30 Oct 2009 07:33:26 +0000 (09:33 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 30 Oct 2009 07:33:26 +0000 (09:33 +0200)
lib/formats.c
lib/rpmtd.h

index e984a00..8e7cb4c 100644 (file)
@@ -655,6 +655,41 @@ static char * fstateFormat(rpmtd td, char * formatPrefix)
     return val;
 }
 
+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");
+       rasprintf(&val, formatPrefix, buf);
+    }
+
+    return val;
+}
 void *rpmHeaderFormatFuncByName(const char *fmt)
 {
     const struct headerFormatFunc_s * ext;
@@ -702,5 +737,6 @@ static const struct headerFormatFunc_s rpmHeaderFormats[] = {
     { RPMTD_FORMAT_SHESCAPE,   "shescape",     shescapeFormat },
     { RPMTD_FORMAT_ARRAYSIZE,  "arraysize",    arraysizeFormat },
     { RPMTD_FORMAT_FSTATE,     "fstate",       fstateFormat },
+    { RPMTD_FORMAT_VFLAGS,     "vflags",       vflagsFormat },
     { -1,                      NULL,           NULL }
 };
index fef040c..2291442 100644 (file)
@@ -215,6 +215,7 @@ typedef enum rpmtdFormats_e {
     RPMTD_FORMAT_ARRAYSIZE     = 14,   /* size of contained array (any type) */
     RPMTD_FORMAT_DEPTYPE       = 15,   /* dependency types (int types) */
     RPMTD_FORMAT_FSTATE                = 16,   /* file states (int types) */
+    RPMTD_FORMAT_VFLAGS                = 17,   /* file verify flags (int types) */
 } rpmtdFormats;
 
 /** \ingroup rpmtd