CRUX-ARM : Home

Home :: Documentation :: Download :: Development :: Community :: Ports :: Packages :: Bugs :: Links :: About :: Donors
prepared the code for the addition of the INSTALL rule
authorTilman Sauerbeck <tilman@code-monkey.de>
Thu, 24 Aug 2006 14:17:55 +0000 (16:17 +0200)
committerTilman Sauerbeck <tilman@code-monkey.de>
Thu, 24 Aug 2006 14:17:55 +0000 (16:17 +0200)
ChangeLog
pkgadd.cc
pkgadd.h

index 4e7f5423b5bf3aec7d82f50713aa820631a58a11..f91144127be38f03207f5727048ae0fa95041c80 100644 (file)
--- 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
index dbc564157e28f3a68c1140f40ed883a83d12cc91..8178b0adbc404a3b5dd02ac262ef51e20c7a3de4 100644 (file)
--- a/pkgadd.cc
+++ b/pkgadd.cc
@@ -142,7 +142,7 @@ vector<rule_t> 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<rule_t> pkgadd::read_config() const
 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");
-
-                               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<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);
+
+                               break;
                        }
                }
        }
@@ -204,3 +200,24 @@ set<string> pkgadd::make_keep_list(const set<string>& files, const vector<rule_t
 
        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;
+}
index 46e0f1bef99dcc62e2465cc529b05d86107352aa..b5b53e2343f44aac791425a9226c60f52e41c889 100644 (file)
--- a/pkgadd.h
+++ b/pkgadd.h
 #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<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 */