X-Git-Url: http://gitweb/?a=blobdiff_plain;f=pkgadd.cc;h=60bc65654f6a121703e584b1c1671a97b2ed46dc;hb=b32745f7236abb00789b9535260f739899a26cd3;hp=dbc564157e28f3a68c1140f40ed883a83d12cc91;hpb=9ac667e68d3e36eb99272eac57219002ee2318e6;p=pkgutils-cross.git diff --git a/pkgadd.cc b/pkgadd.cc index dbc5641..60bc656 100644 --- a/pkgadd.cc +++ b/pkgadd.cc @@ -2,6 +2,7 @@ // pkgutils // // Copyright (c) 2000-2005 Per Liden +// Copyright (c) 2006-2013 by CRUX team (http://crux.nu) // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -78,6 +79,7 @@ void pkgadd::run(int argc, char** argv) else if (!installed && o_upgrade) throw runtime_error("package " + package.first + " not previously installed (skip -u to install)"); + set non_install_files = apply_install_rules(package.first, package.second, config_rules); set conflicting_files = db_find_conflicts(package.first, package.second); if (!conflicting_files.empty()) { @@ -101,7 +103,7 @@ void pkgadd::run(int argc, char** argv) db_add_pkg(package.first, package.second); db_commit(); - pkg_install(o_package, keep_list); + pkg_install(o_package, keep_list, non_install_files); ldconfig(); } } @@ -140,9 +142,9 @@ vector pkgadd::read_config() const if (sscanf(line.c_str(), "%s %s %s %s", event, pattern, action, dummy) != 3) throw runtime_error(filename + ":" + itos(linecount) + ": wrong number of arguments, aborting"); - if (!strcmp(event, "UPGRADE")) { + if (!strcmp(event, "UPGRADE") || !strcmp(event, "INSTALL")) { rule_t rule; - rule.event = rule_t::UPGRADE; + rule.event = strcmp(event, "UPGRADE") ? INSTALL : UPGRADE; rule.pattern = pattern; if (!strcmp(action, "YES")) { rule.action = true; @@ -175,21 +177,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 +202,69 @@ set pkgadd::make_keep_list(const set& files, const vector pkgadd::apply_install_rules(const string& name, pkginfo_t& info, const vector& rules) +{ + // TODO: better algo(?) + set install_set; + set non_install_set; + vector found; + + find_rules(rules, INSTALL, found); + + for (set::const_iterator i = info.files.begin(); i != info.files.end(); i++) { + bool install_file = true; + + for (vector::reverse_iterator j = found.rbegin(); j != found.rend(); j++) { + if (rule_applies_to_file(*j, *i)) { + install_file = (*j).action; + break; + } + } + + if (install_file) + install_set.insert(install_set.end(), *i); + else + non_install_set.insert(*i); + } + + info.files.clear(); + info.files = install_set; + +#ifndef NDEBUG + cerr << "Install set:" << endl; + for (set::iterator j = info.files.begin(); j != info.files.end(); j++) { + cerr << " " << (*j) << endl; + } + cerr << endl; + + cerr << "Non-Install set:" << endl; + for (set::iterator j = non_install_set.begin(); j != non_install_set.end(); j++) { + cerr << " " << (*j) << endl; + } + cerr << endl; +#endif + + return non_install_set; +} + +void pkgadd::find_rules(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; +}