From 1e0dfb6d09297f14827ed72e38dd48b4eb770e3f Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Thu, 24 Aug 2006 16:17:55 +0200 Subject: [PATCH] prepared the code for the addition of the INSTALL rule --- ChangeLog | 4 ++++ pkgadd.cc | 45 +++++++++++++++++++++++++++++++-------------- pkgadd.h | 8 +++++++- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4e7f542..f911441 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ +2006-08-24 Tilman Sauerbeck (tilman at crux nu) + * pkgadd.{h,cc}: Prepared the code for addition of the INSTALL rule + 2006-04-29 Simone Rota (sip at crux dot nu) * Optimized file type detection for stripping in pkgmk Thanks to Antti Nykänen + 2006-04-14 Tilman Sauerbeck (tilman at crux nu) * ChangeLog, NEWS: Moved old ChangeLog to NEWS * pkgmk.in: Write warnings and errors to stderr instead of stdout diff --git a/pkgadd.cc b/pkgadd.cc index dbc5641..8178b0a 100644 --- a/pkgadd.cc +++ b/pkgadd.cc @@ -142,7 +142,7 @@ vector pkgadd::read_config() const if (!strcmp(event, "UPGRADE")) { rule_t rule; - rule.event = rule_t::UPGRADE; + rule.event = UPGRADE; rule.pattern = pattern; if (!strcmp(action, "YES")) { rule.action = true; @@ -175,21 +175,17 @@ vector pkgadd::read_config() const set pkgadd::make_keep_list(const set& files, const vector& rules) const { set keep_list; + vector found; + + find_rules(rules, UPGRADE, found); for (set::const_iterator i = files.begin(); i != files.end(); i++) { - for (vector::const_reverse_iterator j = rules.rbegin(); j != rules.rend(); j++) { - if ((*j).event == rule_t::UPGRADE) { - regex_t preg; - if (regcomp(&preg, (*j).pattern.c_str(), REG_EXTENDED | REG_NOSUB)) - throw runtime_error("error compiling regular expression '" + (*j).pattern + "', aborting"); - - if (!regexec(&preg, (*i).c_str(), 0, 0, 0)) { - if (!(*j).action) - keep_list.insert(keep_list.end(), *i); - regfree(&preg); - break; - } - regfree(&preg); + for (vector::reverse_iterator j = found.rbegin(); j != found.rend(); j++) { + if (rule_applies_to_file(*j, *i)) { + if (!(*j).action) + keep_list.insert(keep_list.end(), *i); + + break; } } } @@ -204,3 +200,24 @@ set pkgadd::make_keep_list(const set& files, const vector& rules, rule_event_t event, vector& found) const +{ + for (vector::const_iterator i = rules.begin(); i != rules.end(); i++) + if (i->event == event) + found.push_back(*i); +} + +bool pkgadd::rule_applies_to_file(const rule_t& rule, const string& file) const +{ + regex_t preg; + bool ret; + + if (regcomp(&preg, rule.pattern.c_str(), REG_EXTENDED | REG_NOSUB)) + throw runtime_error("error compiling regular expression '" + rule.pattern + "', aborting"); + + ret = !regexec(&preg, file.c_str(), 0, 0, 0); + regfree(&preg); + + return ret; +} diff --git a/pkgadd.h b/pkgadd.h index 46e0f1b..b5b53e2 100644 --- a/pkgadd.h +++ b/pkgadd.h @@ -29,8 +29,12 @@ #define PKGADD_CONF "/etc/pkgadd.conf" #define PKGADD_CONF_MAXLINE 1024 +enum rule_event_t { + UPGRADE +}; + struct rule_t { - enum { UPGRADE } event; + rule_event_t event; string pattern; bool action; }; @@ -44,6 +48,8 @@ public: private: vector read_config() const; set make_keep_list(const set& files, const vector& rules) const; + void find_rules(const vector& rules, rule_event_t event, vector& found) const; + bool rule_applies_to_file(const rule_t& rule, const string& file) const; }; #endif /* PKGADD_H */ -- 2.26.2