From e6d7f5bae351eacf99e49fb8462c4fee3c40ccbe Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Tue, 8 Nov 2011 16:39:01 +0100 Subject: [PATCH] Fix zypp.conf lense to ignore commented option values --- src/utils/Augeas.cc | 57 ++-------------------------------------------------- src/utils/Augeas.h | 16 ++++----------- src/utils/zypper.aug | 21 ++++++------------- 3 files changed, 12 insertions(+), 82 deletions(-) diff --git a/src/utils/Augeas.cc b/src/utils/Augeas.cc index 57b9d43..238d84c 100644 --- a/src/utils/Augeas.cc +++ b/src/utils/Augeas.cc @@ -173,7 +173,7 @@ string Augeas::getOption(const string & option) const { string augpath_u = userOptionPath(opt[0], opt[1]); string result = get(augpath_u); - if (_last_get_result == 1 && !isCommented(opt[0], opt[1], false)) + if (_last_get_result == 1) return result; } @@ -181,7 +181,7 @@ string Augeas::getOption(const string & option) const { string augpath_g = global_option_path(opt[0], opt[1]); string result = get(augpath_g); - if (_last_get_result == 1 && !isCommented(opt[0], opt[1], true)) + if (_last_get_result == 1) return result; } @@ -189,56 +189,3 @@ string Augeas::getOption(const string & option) const } // --------------------------------------------------------------------------- - -TriBool Augeas::isCommented( - const string & section, const string & option, bool global) const -{ - // don't bother calling aug_get if we don't have the config read - if ((global && !_got_global_zypper_conf) || - (!global && !_got_user_zypper_conf)) - return TriBool::indeterminate_value; - - Pathname path(global ? - global_option_path(section, option) : - userOptionPath(section, option)); - - TriBool result; - - char ** matches; - int matchcount = ::aug_match(_augeas, path.c_str(), &matches); - if (matchcount == 1) - { - path = Pathname(matches[0]); - // the 'commented' flag is a sibling of the key=value node - path = path.dirname() + "/commented"; - DBG << path << ": "; - int res = ::aug_get(_augeas, path.c_str(), NULL); - if (res) - result = true; - else if (res == 0) - result = false; - DBG << result << endl; - } - for (int i = 0; i < matchcount; ++i) - ::free(matches[i]); - if (matchcount) - ::free(matches); - - return result; -} - -// --------------------------------------------------------------------------- - -TriBool Augeas::isCommented(const string & option, bool global) const -{ - vector opt; - str::split(option, back_inserter(opt), "/"); - - if (opt.size() != 2 || opt[0].empty() || opt[1].empty()) - { - ERR << "invalid option " << option << endl; - return TriBool::indeterminate_value; - } - - return isCommented(opt[0], opt[1], global); -} diff --git a/src/utils/Augeas.h b/src/utils/Augeas.h index 61451b2..af951df 100644 --- a/src/utils/Augeas.h +++ b/src/utils/Augeas.h @@ -24,26 +24,18 @@ extern "C" class Augeas : private zypp::base::NonCopyable { public: - Augeas(const std::string & file = ""); + Augeas( const std::string & file = "" ); ~Augeas(); - std::string get(const std::string & augpath) const; + std::string get( const std::string & augpath ) const; - std::string getOption(const std::string & option) const; - zypp::TriBool isCommented(const std::string & option, bool global) const; - void comment(const std::string & option); - void uncomment(const std::string & option); + std::string getOption( const std::string & option ) const; ::augeas * getAugPtr() { return _augeas; } private: - std::string userOptionPath( - const std::string & section, const std::string & option) const; - - zypp::TriBool isCommented(const std::string & section, - const std::string & option, - bool global) const; + std::string userOptionPath( const std::string & section, const std::string & option ) const; private: ::augeas * _augeas; diff --git a/src/utils/zypper.aug b/src/utils/zypper.aug index d8bf27b..7ea74db 100644 --- a/src/utils/zypper.aug +++ b/src/utils/zypper.aug @@ -33,9 +33,9 @@ module ZYpper = (* Matches an empty line and creates a node for it *) let empty = [ eol ] - + (* Deletes optional whitespace and stores the rest 'till the end of line *) - let store_to_eol = del_opt_ws " " . store /([^ \t\n].*[^ \t\n])/ + let store_to_eol = del_opt_ws " " . store /([^ \t\n].*[^ \t\n])/ (* Keyword regex. @@ -49,23 +49,14 @@ module ZYpper = (* Matches one line of ## description and creates a node for it *) let description = [ label "description" . del /##/ "##" . store_to_eol? . eol ] - (* - Matches '#' and whitespace, creates a 'commented' note for it. - Used in 'option' to mark the option as commented. - *) - let commented = [ label "commented" . del /#[ \t]*/ "# " ] + (* Matches '#' and whitespace, creates a 'commented' note for it. *) + let commented = [ label "commented" . del /#[ \t]*/ "# " . store_to_eol? . eol ] (* Matches key=value, creates a new node out of key and stores the value *) let kv = [ key kw_re . del /[ \t]*=[ \t]*/ " = " . store /[^# \t\n][^#\n]*/ ] - (* - An option consists of ## description, and an (optionally commented) - key=value pair. - - This could be relaxed a bit in the future to allow more commented - keys, arbitrary comments, etc. - *) - let option = [ seq "option" . description* . commented? . del_opt_ws "" . kv . del_str "\n" ] + (* An option consists of ## description, # commented lines and an optionall key=value pair. *) + let option = [ seq "option" . description* . commented* . del_opt_ws "" . kv? . del_str "\n" ] (* ****************( section )*************** *) -- 2.7.4