On Wed, Jul 12, 2006 at 07:33:51PM +0400, Anton wrote:
> pkgutils-3-split.patch
> pkgutils-4-cosmetic.patch
There is an inaccuracy between 3-split and 4-cosmetic.
Line "- vector<rule_t> read_config() const;"
should be done in 3-split, not 4-cosmetic. Though, it's not break
compilation, thus not caught by me in first place.
These try2 patches attached, others seems okay.
Index: pkgadd.h
===================================================================
--- pkgadd.h (revision 3)
+++ pkgadd.h (working copy)
@@ -25,6 +25,8 @@
#include "pkgutil.h"
#include <vector>
#include <set>
+#include <fstream>
+#include <regex.h>
#define PKGADD_CONF "/etc/pkgadd.conf"
#define PKGADD_CONF_MAXLINE 1024
@@ -36,13 +38,30 @@
};
class pkgadd : public pkgutil {
+ package_t package;
+ vector<rule_t> config_rules;
+ bool o_upgrade;
+ bool o_force;
+
+ class config {
+ vector<rule_t> rules;
+ unsigned int linecount;
+ const string filename;
+ ifstream in;
+
+ void parse_line(string line);
+ public:
+ config(const string &root);
+ vector<rule_t> read_config();
+ };
+
public:
- pkgadd() : pkgutil("pkgadd") {}
+ pkgadd() : pkgutil("pkgadd"), o_upgrade(false) {}
+ void resolve_conflicts();
virtual void run(int argc, char** argv);
virtual void print_help() const;
private:
- vector<rule_t> read_config() const;
template <typename in_t, typename conv_t>
filenames_t make_keep_list(const in_t& files, const vector<rule_t>&
rules) const;
};
Index: pkgadd.cc
===================================================================
--- pkgadd.cc (revision 3)
+++ pkgadd.cc (working copy)
@@ -20,12 +20,10 @@
//
#include "pkgadd.h"
-#include <fstream>
#include <iterator>
#include <cstdio>
#include <deque>
#include <ext/functional>
-#include <regex.h>
#include <unistd.h>
template <typename in_t, typename out_t>
@@ -75,6 +73,39 @@
return true;
}
+void pkgadd::resolve_conflicts()
+{
+ fileconflicts_t fileconflicts = db_find_conflicts(package.first,
+ package.second);
+
+ if (!fileconflicts.empty()) {
+ if (o_force) {
+ filenames_t keep_list;
+ // Don't remove files matching the rules in
configuration
+ if (o_upgrade) {
+ keep_list = make_keep_list<fileconflicts_t,
+ fileconflict_t>(fileconflicts,
+ config_rules);
+ }
+ // Remove unwanted conflicts
+ db_rm_fileconflicts(fileconflicts, keep_list);
+ } else {
+ typedef pair<fileconflict_t::second_type,
+ fileconflict_t::first_type> swapped_t;
+ deque<swapped_t> sorted;
+ transform(fileconflicts.begin(), fileconflicts.end(),
+ back_inserter(sorted),
+ swap_pair<fileconflict_t,swapped_t>());
+ sort(sorted.begin(), sorted.end());
+ for_each(sorted.begin(), sorted.end(),
+ compose1(print_sorted_fileconflicts(),
+ swap_pair<swapped_t,fileconflict_t>()
+ ));
+ cout << endl;
+ throw runtime_error("use -f to ignore and overwrite");
+ }
+ }
+}
void pkgadd::run(int argc, char** argv)
{
@@ -83,8 +114,6 @@
//
string o_root;
string o_package;
- bool o_upgrade = false;
- bool o_force = false;
for (int i = 1; i < argc; i++) {
string option(argv[i]);
@@ -115,61 +144,38 @@
//
// Install/upgrade package
//
- {
- db_lock lock(o_root, true);
- db_open(o_root);
+ db_lock lock(o_root, true);
+ db_open(o_root);
- pair<string, pkginfo_t> package = pkg_open(o_package);
- vector<rule_t> config_rules = read_config();
+ package = pkg_open(o_package);
- bool installed = db_find_pkg(package.first);
- if (installed && !o_upgrade)
- throw runtime_error("package " + package.first + "
already installed (use -u to upgrade)");
- else if (!installed && o_upgrade)
- throw runtime_error("package " + package.first + " not
previously installed (skip -u to install)");
+ config_rules = config(o_root).read_config();
- fileconflicts_t fileconflicts =
db_find_conflicts(package.first, package.second);
-
- if (!fileconflicts.empty()) {
- if (o_force) {
- filenames_t keep_list;
- // Don't remove files matching the rules in
configuration
- if (o_upgrade) {
- keep_list =
make_keep_list<fileconflicts_t,
-
fileconflict_t>(fileconflicts,
- config_rules);
- }
- // Remove unwanted conflicts
- db_rm_fileconflicts(fileconflicts, keep_list);
- } else {
- typedef pair<fileconflict_t::second_type,
- fileconflict_t::first_type> swapped_t;
- deque<swapped_t> sorted;
- transform(fileconflicts.begin(),
fileconflicts.end(),
- back_inserter(sorted),
- swap_pair<fileconflict_t,swapped_t>());
- sort(sorted.begin(), sorted.end());
- for_each(sorted.begin(), sorted.end(),
- compose1(print_sorted_fileconflicts(),
-
swap_pair<swapped_t,fileconflict_t>()
- ));
- cout << endl;
- throw runtime_error("use -f to ignore and
overwrite");
- }
- }
+ bool installed = db_find_pkg(package.first);
+ if (installed && !o_upgrade) {
+ throw runtime_error("package " + package.first
+ + " already installed (use -u to upgrade)");
+ }
+ else if (!installed && o_upgrade) {
+ throw runtime_error(
+ "package " + package.first + " not previously "
+ "installed (skip -u to install)");
+ }
- filenames_t keep_list;
+ resolve_conflicts();
+
+ filenames_t keep_list;
- if (o_upgrade) {
- keep_list = make_keep_list<files_t,
file_t>(package.second.files, config_rules);
- db_rm_pkg(package.first, keep_list);
- }
+ if (o_upgrade) {
+ keep_list = make_keep_list<files_t, file_t>
+ (package.second.files, config_rules);
+ db_rm_pkg(package.first, keep_list);
+ }
- db_add_pkg(package.first, package.second);
- db_commit();
- pkg_install(o_package, keep_list);
- ldconfig();
- }
+ db_add_pkg(package.first, package.second);
+ db_commit();
+ pkg_install(o_package, keep_list);
+ ldconfig();
}
void pkgadd::print_help() const
@@ -183,46 +189,59 @@
<< " -h, --help print help and exit" << endl;
}
-vector<rule_t> pkgadd::read_config() const
+pkgadd::config::config(const string &root)
+: linecount(0), filename(root + PKGADD_CONF), in(filename.c_str()) {
+}
+
+void pkgadd::config::parse_line(string line) {
+ if (!line.empty() && line[0] != '#') {
+ if (line.length() >= PKGADD_CONF_MAXLINE) {
+ throw runtime_error(filename + ":" + itos(linecount) +
+ ": line too long, aborting");
+ }
+
+ char event[PKGADD_CONF_MAXLINE];
+ char pattern[PKGADD_CONF_MAXLINE];
+ char action[PKGADD_CONF_MAXLINE];
+ char dummy[PKGADD_CONF_MAXLINE];
+ 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")) {
+ rule_t rule;
+ rule.event = rule_t::UPGRADE;
+ rule.pattern = pattern;
+ if (!strcmp(action, "YES")) {
+ rule.action = true;
+ } else if (!strcmp(action, "NO")) {
+ rule.action = false;
+ } else
+ throw runtime_error(filename + ":" +
+ itos(linecount) + ": '"
+ + string(action)
+ + "' unknown action, "
+ "should be YES or NO, "
+ "aborting");
+ rules.push_back(rule);
+ } else {
+ throw runtime_error(filename + ":" + itos(linecount)
+ + ": '" + string(event)
+ + "' unknown event, aborting");
+ }
+ }
+}
+
+vector<rule_t> pkgadd::config::read_config()
{
- vector<rule_t> rules;
- unsigned int linecount = 0;
- const string filename = root + PKGADD_CONF;
- ifstream in(filename.c_str());
-
if (in) {
while (!in.eof()) {
string line;
getline(in, line);
linecount++;
- if (!line.empty() && line[0] != '#') {
- if (line.length() >= PKGADD_CONF_MAXLINE)
- throw runtime_error(filename + ":" +
itos(linecount) + ": line too long, aborting");
-
- char event[PKGADD_CONF_MAXLINE];
- char pattern[PKGADD_CONF_MAXLINE];
- char action[PKGADD_CONF_MAXLINE];
- char dummy[PKGADD_CONF_MAXLINE];
- 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")) {
- rule_t rule;
- rule.event = rule_t::UPGRADE;
- rule.pattern = pattern;
- if (!strcmp(action, "YES")) {
- rule.action = true;
- } else if (!strcmp(action, "NO")) {
- rule.action = false;
- } else
- throw runtime_error(filename +
":" + itos(linecount) + ": '" +
-
string(action) + "' unknown action, should be YES or NO, aborting");
-
- rules.push_back(rule);
- } else
- throw runtime_error(filename + ":" +
itos(linecount) + ": '" +
- string(event) + "'
unknown event, aborting");
- }
+ parse_line(line);
}
in.close();
}
Index: pkgadd.h
===================================================================
--- pkgadd.h (revision 8)
+++ pkgadd.h (working copy)
@@ -43,6 +43,10 @@
bool o_upgrade;
bool o_force;
+ template <typename in_t, typename conv_t>
+ filenames_t make_keep_list(const in_t& files,
+ const vector<rule_t>& rules) const;
+
class config {
vector<rule_t> rules;
unsigned int linecount;
@@ -60,10 +64,6 @@
void resolve_conflicts();
virtual void run(int argc, char** argv);
virtual void print_help() const;
-
-private:
- template <typename in_t, typename conv_t>
- filenames_t make_keep_list(const in_t& files, const vector<rule_t>&
rules) const;
};
#endif /* PKGADD_H */
Index: pkginfo.cc
===================================================================
--- pkginfo.cc (revision 8)
+++ pkginfo.cc (working copy)
@@ -19,12 +19,12 @@
// USA.
//
-#include "pkginfo.h"
#include <iterator>
#include <vector>
#include <iomanip>
#include <sys/types.h>
#include <regex.h>
+#include "pkginfo.h"
void pkginfo::run(int argc, char** argv)
{
Index: pkgadd.cc
===================================================================
--- pkgadd.cc (revision 8)
+++ pkgadd.cc (working copy)
@@ -248,7 +248,8 @@
#ifndef NDEBUG
cerr << "Configuration:" << endl;
- for (vector<rule_t>::const_iterator j = rules.begin(); j !=
rules.end(); j++) {
+ vector<rule_t>::const_iterator j;
+ for (j = rules.begin(); j != rules.end(); j++) {
cerr << "\t" << (*j).pattern << "\t" << (*j).action << endl;
}
cerr << endl;
@@ -263,15 +264,20 @@
filenames_t keep_list;
for (typename in_t::const_iterator i = files.begin(); i != files.end();
i++) {
- for (vector<rule_t>::const_reverse_iterator j = rules.rbegin();
j != rules.rend(); j++) {
+ 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 (regcomp(&preg, (*j).pattern.c_str(),
REG_EXTENDED | REG_NOSUB)) {
+ throw runtime_error("error compiling
regular expression '"
+ + (*j).pattern +
"', aborting");
+ }
if (!regexec(&preg,
(extract_filename()((conv_t)(*i))).c_str(), 0, 0, 0)) {
- if (!(*j).action)
-
keep_list.insert(keep_list.end(), extract_filename()((conv_t)(*i)));
+ if (!(*j).action) {
+
keep_list.insert(keep_list.end(),
+
extract_filename()((conv_t)(*i)));
+ }
regfree(&preg);
break;
}
_______________________________________________
crux-devel mailing list
[email protected]
http://lists.crux.nu/mailman/listinfo/crux-devel