{
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;
}
{
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;
}
}
// ---------------------------------------------------------------------------
-
-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<string> 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);
-}
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;
(* 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.
(* 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 )*************** *)