CRUX-ARM : Home

Home :: Documentation :: Download :: Development :: Community :: Ports :: Packages :: Bugs :: Links :: About :: Donors
Added support for alternate config file in pkgadd commands (required for us to remove...
authorJose V Beneyto <sepen@crux.nu>
Tue, 13 Aug 2013 19:59:24 +0000 (19:59 +0000)
committerJose V Beneyto <sepen@crux.nu>
Tue, 13 Aug 2013 19:59:24 +0000 (19:59 +0000)
pkgadd.cc
pkgadd.h

index 60bc65654f6a121703e584b1c1671a97b2ed46dc..2310ea05ede54e09e61bcb8637d9b44527939fc9 100644 (file)
--- a/pkgadd.cc
+++ b/pkgadd.cc
@@ -3,7 +3,9 @@
 // 
 //  Copyright (c) 2000-2005 Per Liden
 //  Copyright (c) 2006-2013 by CRUX team (http://crux.nu)
-// 
+//
+//  Patches for alternative pkgadd.conf file by Jose V Beneyto <sepen@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
 //  the Free Software Foundation; either version 2 of the License, or
@@ -33,6 +35,7 @@ void pkgadd::run(int argc, char** argv)
        // Check command line options
        //
        string o_root;
+       string o_config;
        string o_package;
        bool o_upgrade = false;
        bool o_force = false;
@@ -43,6 +46,10 @@ void pkgadd::run(int argc, char** argv)
                        assert_argument(argv, argc, i);
                        o_root = argv[i + 1];
                        i++;
+               } else if (option == "-c" || option == "--config") {
+                       assert_argument(argv, argc, i);
+                       o_config = argv[i + 1];
+                       i++;
                } else if (option == "-u" || option == "--upgrade") {
                        o_upgrade = true;
                } else if (option == "-f" || option == "--force") {
@@ -71,7 +78,7 @@ void pkgadd::run(int argc, char** argv)
                db_open(o_root);
 
                pair<string, pkginfo_t> package = pkg_open(o_package);
-               vector<rule_t> config_rules = read_config();
+               vector<rule_t> config_rules = read_config(o_config);
 
                bool installed = db_find_pkg(package.first);
                if (installed && !o_upgrade)
@@ -112,18 +119,21 @@ void pkgadd::print_help() const
 {
        cout << "usage: " << utilname << " [options] <file>" << endl
             << "options:" << endl
-            << "  -u, --upgrade       upgrade package with the same name" << endl
-            << "  -f, --force         force install, overwrite conflicting files" << endl
-            << "  -r, --root <path>   specify alternative installation root" << endl
-            << "  -v, --version       print version and exit" << endl
-            << "  -h, --help          print help and exit" << endl;
+            << "  -u, --upgrade        upgrade package with the same name" << endl
+            << "  -f, --force          force install, overwrite conflicting files" << endl
+            << "  -r, --root <path>    specify alternative installation root" << endl
+            << "  -c, --config <file>  use alternate configuration file" << endl
+            << "  -v, --version        print version and exit" << endl
+            << "  -h, --help           print help and exit" << endl;
 }
 
-vector<rule_t> pkgadd::read_config() const
+vector<rule_t> pkgadd::read_config(string file) const
 {
        vector<rule_t> rules;
        unsigned int linecount = 0;
-       const string filename = root + PKGADD_CONF;
+       string filename = root + PKGADD_CONF;
+
+       if (!file.empty()) filename = file;
        ifstream in(filename.c_str());
 
        if (in) {
index f7f9b6474e9fde19233151a7b31b2fe200503999..0879808a44698ffc6c0af38ec30b43148864bf2b 100644 (file)
--- a/pkgadd.h
+++ b/pkgadd.h
@@ -48,7 +48,7 @@ public:
        virtual void print_help() const;
 
 private:
-       vector<rule_t> read_config() const;
+       vector<rule_t> read_config(string file) const;
        set<string> make_keep_list(const set<string>& files, const vector<rule_t>& rules) const;
        set<string> apply_install_rules(const string& name, pkginfo_t& info, const vector<rule_t>& rules);
        void find_rules(const vector<rule_t>& rules, rule_event_t event, vector<rule_t>& found) const;