|__/|_| |_|
\*---------------------------------------------------------------------------*/
#include <iostream>
+#include <stdlib.h>
#include "zypp/base/Logger.h"
#include "Zypper.h"
_last_get_result = ::aug_get(_augeas, augpath.c_str(), value);
if (_last_get_result)
{
- MIL << "Got " << augpath << " = " << value[0] << endl;
+ DBG << "Got " << augpath << " = " << value[0] << endl;
return value[0];
}
else if (_last_get_result == 0)
return string();
}
- string augpath_u = user_option_path(opt[0], opt[1], _homedir);
- string result = get(augpath_u);
- if (_last_get_result && !isCommented(opt[0], opt[1], false))
- return result;
+ if (_got_user_zypper_conf)
+ {
+ string augpath_u = user_option_path(opt[0], opt[1], _homedir);
+ string result = get(augpath_u);
+ if (_last_get_result && !isCommented(opt[0], opt[1], false))
+ return result;
+ }
- string augpath_g = global_option_path(opt[0], opt[1]);
- result = get(augpath_g);
- if (_last_get_result && !isCommented(opt[0], opt[1], true))
- return result;
+ if (_got_global_zypper_conf)
+ {
+ string augpath_g = global_option_path(opt[0], opt[1]);
+ string result = get(augpath_g);
+ if (_last_get_result && !isCommented(opt[0], opt[1], true))
+ return result;
+ }
return string();
}
// ---------------------------------------------------------------------------
-bool Augeas::isCommented(
+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) :
user_option_path(section, option, _homedir));
- path = path.dirname() + "/commented";
- if (::aug_get(_augeas, path.c_str(), NULL))
- return true;
+ 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;
+ }
+ if (matchcount)
+ ::free(matches);
- return false;
+ return result;
}
// ---------------------------------------------------------------------------
-bool Augeas::isCommented(const string & option, bool global) const
+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 false;
+ return TriBool::indeterminate_value;
}
return isCommented(opt[0], opt[1], global);
}
#include "zypp/base/NonCopyable.h"
+#include "zypp/TriBool.h"
/**
* Zypper's wrapper around Augeas.
std::string get(const std::string & augpath) const;
std::string getOption(const std::string & option) const;
- bool isCommented(const std::string & option, bool global) const;
+ zypp::TriBool isCommented(const std::string & option, bool global) const;
void comment(const std::string & option);
void uncomment(const std::string & option);
{ return _augeas; }
private:
- bool isCommented(const std::string & section, const std::string & option,
+ zypp::TriBool isCommented(const std::string & section,
+ const std::string & option,
bool global) const;
private: