Author: tilman Date: 2006-08-24 18:17:54 +0200 (Thu, 24 Aug 2006) New Revision: 1767 Modified: tools/pkgutils/trunk/ChangeLog tools/pkgutils/trunk/pkgadd.cc tools/pkgutils/trunk/pkgadd.h Log: prepared the code for the addition of the INSTALL rule Modified: tools/pkgutils/trunk/ChangeLog =================================================================== --- tools/pkgutils/trunk/ChangeLog 2006-08-23 20:29:01 UTC (rev 1766) +++ tools/pkgutils/trunk/ChangeLog 2006-08-24 16:17:54 UTC (rev 1767) @@ -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 Modified: tools/pkgutils/trunk/pkgadd.cc =================================================================== --- tools/pkgutils/trunk/pkgadd.cc 2006-08-23 20:29:01 UTC (rev 1766) +++ tools/pkgutils/trunk/pkgadd.cc 2006-08-24 16:17:54 UTC (rev 1767) @@ -142,7 +142,7 @@ 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 @@ set<string> pkgadd::make_keep_list(const set<string>& files, const vector<rule_t>& rules) const { set<string> keep_list; + vector<rule_t> found; + find_rules(rules, UPGRADE, found); + for (set<string>::const_iterator i = files.begin(); i != files.end(); i++) { - for (vector<rule_t>::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"); + for (vector<rule_t>::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); - if (!regexec(&preg, (*i).c_str(), 0, 0, 0)) { - if (!(*j).action) - keep_list.insert(keep_list.end(), *i); - regfree(&preg); - break; - } - regfree(&preg); + break; } } } @@ -204,3 +200,24 @@ return keep_list; } + +void pkgadd::find_rules(const vector<rule_t>& rules, rule_event_t event, vector<rule_t>& found) const +{ + for (vector<rule_t>::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; +} Modified: tools/pkgutils/trunk/pkgadd.h =================================================================== --- tools/pkgutils/trunk/pkgadd.h 2006-08-23 20:29:01 UTC (rev 1766) +++ tools/pkgutils/trunk/pkgadd.h 2006-08-24 16:17:54 UTC (rev 1767) @@ -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 @@ private: vector<rule_t> read_config() const; set<string> make_keep_list(const set<string>& files, const vector<rule_t>& rules) const; + void find_rules(const vector<rule_t>& rules, rule_event_t event, vector<rule_t>& found) const; + bool rule_applies_to_file(const rule_t& rule, const string& file) const; }; #endif /* PKGADD_H */