From 177deafe2f7a638759575bac6e22add177b08b3a Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 10 Dec 2010 11:53:45 +0200 Subject: Support excluding by path or magic in file classification - %__foo_exclude_pattern and %__foo_exclude_magic regex'es now allow excluding attributes that would otherwise match. (cherry picked from commit f5a657112a8f9a107314dcd02767146e64953abe) --- build/rpmfc.c | 18 ++++++++++++++++++ macros.in | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/build/rpmfc.c b/build/rpmfc.c index bddb86529..455a37351 100644 --- a/build/rpmfc.c +++ b/build/rpmfc.c @@ -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); diff --git a/macros.in b/macros.in index e1514168b..aba3647fb 100644 --- a/macros.in +++ b/macros.in @@ -489,7 +489,9 @@ print (t)\ # %__myattr_provides path + args to provides finder script for # %__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 -- cgit v1.2.3