Support excluding by path or magic in file classification
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 10 Dec 2010 09:53:45 +0000 (11:53 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 10 Dec 2010 10:00:50 +0000 (12:00 +0200)
- %__foo_exclude_pattern and %__foo_exclude_magic regex'es now allow
  excluding attributes that would otherwise match.

build/rpmfc.c
macros.in

index bddb865..455a373 100644 (file)
@@ -23,6 +23,8 @@ typedef struct rpmfcAttr_s {
     char *name;
     regex_t *pattern;
     regex_t *magic;
+    regex_t *pattern_excl;
+    regex_t *magic_excl;
     ARGV_t flags;
 } * rpmfcAttr;
 
@@ -91,6 +93,8 @@ static rpmfcAttr rpmfcAttrNew(const char *name)
     attr->name = xstrdup(name);
     attr->pattern = rpmfcAttrReg(name, "pattern");
     attr->magic = rpmfcAttrReg(name, "magic");
+    attr->pattern_excl = rpmfcAttrReg(name, "exclude_pattern");
+    attr->magic_excl = rpmfcAttrReg(name, "exclude_magic");
     
     return attr;
 }
@@ -106,6 +110,14 @@ static rpmfcAttr rpmfcAttrFree(rpmfcAttr attr)
            regfree(attr->magic);
            rfree(attr->magic);
        }
+       if (attr->pattern_excl) {
+           regfree(attr->pattern_excl);
+           rfree(attr->pattern_excl);
+       }
+       if (attr->magic_excl) {
+           regfree(attr->magic_excl);
+           rfree(attr->magic_excl);
+       }
        argvFree(attr->flags);
        rfree(attr->name);
        rfree(attr);
@@ -582,6 +594,12 @@ static void rpmfcAttributes(rpmfc fc, const char *ftype, const char *fullpath)
        if (hasAttr((*attr)->flags, "exeonly") && !is_executable)
            continue;
 
+       /* Filter out path and magic exclude-matches */
+       if (regMatch((*attr)->magic_excl, ftype))
+           continue;
+       if (regMatch((*attr)->pattern_excl, path))
+           continue;
+
        /* Add attributes on libmagic type & path pattern matches */
        if (regMatch((*attr)->magic, ftype))
            argvAddTokens(&fc->fattrs[fc->ix], (*attr)->name);
index e151416..aba3647 100644 (file)
--- a/macros.in
+++ b/macros.in
@@ -489,7 +489,9 @@ print (t)\
 # %__myattr_provides   path + args to provides finder script for <myattr>
 # %__myattr_magic      libmagic classification match regex
 # %__myattr_pattern    path based classification match regex
-# %__myattr_exeonly    require file to be executable to classify
+# %__myattr_flags      flags to control behavior (just "exeonly" for now)
+# %__myattr_exclude_magic      exclude by magic regex
+# %__myattr_exclude_pattern    exclude by path regex
 #
 %_fileattrsdir         %{_rpmconfigdir}/fileattrs