};
// on error print a message and return noCap
-Capability safe_parse_cap (const ResObject::Kind &kind, const string & capstr) {
+Capability safe_parse_cap (const Zypper & zypper,
+ const ResObject::Kind &kind, const string & capstr)
+{
Capability cap;
try {
// expect named caps as NAME[OP<EDITION>]
// if we are about to install stuff and
// if this is not a candidate for a versioned capability, take it like
// a package name and check if it is already installed
- else if (command == ZypperCommand::INSTALL)
+ else if (zypper.command() == ZypperCommand::INSTALL)
{
using namespace zypp::functor;
using namespace zypp::resfilter;
*/
-void mark_by_capability (bool install_not_delete,
+void mark_by_capability (const Zypper & zypper,
+ bool install_not_delete,
const ResObject::Kind &kind,
const string &capstr )
{
- Capability cap = safe_parse_cap (kind, capstr);
+ Capability cap = safe_parse_cap (zypper, kind, capstr);
if (cap != Capability::noCap) {
cout_vv << "Capability: " << cap << endl;
void cond_init_target();
/// Parse a capability string. On error print a message and return noCap
-zypp::Capability safe_parse_cap (const zypp::ResObject::Kind &kind,
+zypp::Capability safe_parse_cap (const Zypper & zypper,
+ const zypp::ResObject::Kind &kind,
const std::string &capstr);
zypp::ResObject::Kind string_to_kind (const std::string &skind);
void mark_by_name (bool install_not_delete,
const zypp::ResObject::Kind &kind,
const std::string &name );
-void mark_by_capability (bool install_not_delete,
+void mark_by_capability (const Zypper & zypper,
+ bool install_not_delete,
const zypp::ResObject::Kind &kind,
const std::string &capstr );
extern Settings gSettings;
-static bool refresh_raw_metadata(const RepoInfo & repo, bool force_download)
+static bool refresh_raw_metadata(const Zypper & zypper,
+ const RepoInfo & repo,
+ bool force_download)
{
gData.current_repo = repo;
if (manager.checkIfToRefreshMetadata(repo, *it))
{
cout_n << format(_("Refreshing '%s'")) % repo.name();
- if (command == ZypperCommand::REFRESH && copts.count("force"))
+ if (zypper.command() == ZypperCommand::REFRESH &&
+ zypper.cOpts().count("force"))
cout_n << " " << _("(forced)");
cout_n << endl;
}
- else if (command == ZypperCommand::REFRESH)
+ else if (zypper.command() == ZypperCommand::REFRESH)
{
cout_n << format(_("Repository '%s' is up to date.")) % repo.name() << endl;
}
// ---------------------------------------------------------------------------
-static int do_init_repos()
+static int do_init_repos(const Zypper & zypper)
{
// load gpg keys
cond_init_target ();
// handle root user differently
if (geteuid() == 0)
{
- if (refresh_raw_metadata(repo, false) || build_cache(repo, false))
+ if (refresh_raw_metadata(zypper, repo, false) || build_cache(repo, false))
{
cerr << format(_("Disabling repository '%s' because of the above error."))
% repo.name() << endl;
// ----------------------------------------------------------------------------
-int init_repos()
+int init_repos(const Zypper & zypper)
{
static bool done = false;
//! \todo this has to be done so that it works in zypper shell
if ( !gSettings.disable_system_sources )
{
- return do_init_repos();
+ return do_init_repos(zypper);
}
done = true;
// ----------------------------------------------------------------------------
-int refresh_repos(vector<string> & arguments)
+int refresh_repos(const Zypper & zypper, vector<string> & arguments)
{
// need gpg keys when downloading (#304672)
cond_init_target();
MIL << "calling refreshMetadata" << (force_download ? ", forced" : "")
<< endl;
- error = refresh_raw_metadata(repo, force_download);
+ error = refresh_raw_metadata(zypper, repo, force_download);
}
// db rebuild
// ----------------------------------------------------------------------------
static
-int add_repo(RepoInfo & repo)
+int add_repo(const Zypper & zypper, RepoInfo & repo)
{
RepoManager manager(gSettings.rm_options);
if(is_cd)
{
cout_n << format(_("Reading data from '%s' media")) % repo.name() << endl;
- bool error = refresh_raw_metadata(repo, false);
+ bool error = refresh_raw_metadata(zypper, repo, false);
if (!error)
error = build_cache(repo, false);
if (error)
// ----------------------------------------------------------------------------
-int add_repo_by_url( const zypp::Url & url, const string & alias,
+int add_repo_by_url( const Zypper & zypper,
+ const zypp::Url & url, const string & alias,
const string & type,
tribool enabled, tribool autorefresh)
{
if ( !indeterminate(autorefresh) )
repo.setAutorefresh((autorefresh == true));
- return add_repo(repo);
+ return add_repo(zypper, repo);
}
// ----------------------------------------------------------------------------
//! \todo handle zypp exceptions
-int add_repo_from_file(const std::string & repo_file_url,
+int add_repo_from_file(const Zypper & zypper,
+ const std::string & repo_file_url,
tribool enabled, tribool autorefresh)
{
//! \todo handle local .repo files, validate the URL
if ( !indeterminate(autorefresh) )
repo.setAutorefresh((autorefresh == true));
MIL << "enabled: " << repo.enabled() << " autorefresh: " << repo.autorefresh() << endl;
- add_repo(repo);
+ add_repo(zypper, repo);
}
return ZYPPER_EXIT_OK;
// ---------------------------------------------------------------------------
-void cond_load_resolvables(bool to_pool)
+void cond_load_resolvables(const Zypper & zypper, bool to_pool)
{
- load_repo_resolvables(to_pool);
+ load_repo_resolvables(zypper, to_pool);
if (!gSettings.disable_system_resolvables && to_pool)
load_target_resolvables();
}
// ---------------------------------------------------------------------------
-void load_repo_resolvables(bool to_pool)
+void load_repo_resolvables(const Zypper & zypper, bool to_pool)
{
RepoManager manager(gSettings.rm_options);
{
cout_v << format(_("Retrieving repository '%s' data..."))
% repo.name() << endl;
- error = refresh_raw_metadata(repo, false);
+ error = refresh_raw_metadata(zypper, repo, false);
}
if (!error && !manager.isCached(repo))
#include "zypp/Url.h"
+#include "zypper.h"
+
/**
* Reads known enabled repositories and stores them in gData.
* This command also refreshes repos with auto-refresh enabled.
* \return ZYPPER_EXIT_ERR_INVALID_ARGS if --repo does not specify a valid repository,
* ZYPPER_EXIT_ERR_ZYPP on error, ZYPPER_EXIT_OK otherwise.
*/
-int init_repos();
+int init_repos(const Zypper & zypper);
/**
* List defined repositories.
/**
* Refresh all enabled repositories.
*/
-int refresh_repos(std::vector<std::string> & arguments);
+int refresh_repos(const Zypper & zypper, std::vector<std::string> & arguments);
/**
* \return ZYPPER_EXIT_ERR_ZYPP on unexpected zypp exception,
* ZYPPER_EXIT_OK otherwise
*/
-int add_repo_by_url( const zypp::Url & url,
- const std::string & alias,
- const std::string & type = "",
- boost::tribool enabled = boost::indeterminate, boost::tribool autorefresh = boost::indeterminate);
+int add_repo_by_url(const Zypper & zypper,
+ const zypp::Url & url,
+ const std::string & alias,
+ const std::string & type = "",
+ boost::tribool enabled = boost::indeterminate,
+ boost::tribool autorefresh = boost::indeterminate);
/**
* Add repository specified in given repo file on \a repo_file_url. All repos
* \return ZYPPER_EXIT_ERR_ZYPP on unexpected zypp exception,
* ZYPPER_EXIT_OK otherwise
*/
-int add_repo_from_file(const std::string & repo_file_url,
- boost::tribool enabled = boost::indeterminate, boost::tribool autorefresh = boost::indeterminate);
+int add_repo_from_file(const Zypper & zypper,
+ const std::string & repo_file_url,
+ boost::tribool enabled = boost::indeterminate,
+ boost::tribool autorefresh = boost::indeterminate);
/**
* Delte repository specified by \a alias.
* \see load_repo_resolvables(bool)
* \see load_target_resolvables(bool)
*/
-void cond_load_resolvables(bool to_pool = true);
+void cond_load_resolvables(const Zypper & zypper, bool to_pool = true);
/**
* Reads resolvables from the RPM database (installed resolvables) into the pool.
* <tt>false</tt> they will be stored in \ref gData.repo_resolvables
* (global ResStore vector).
*/
-void load_repo_resolvables(bool to_pool = true);
+void load_repo_resolvables(const Zypper & zypper, bool to_pool = true);
/**
Settings gSettings;
parsed_opts gopts; // global options
parsed_opts copts; // command options
-ZypperCommand command(ZypperCommand::NONE);
Zypper::Zypper()
try
{
if (optind < _argc)
- ::command = _command = ZypperCommand(_argv[optind++]);
+ setCommand(ZypperCommand(_argv[optind++]));
- if (_command == ZypperCommand::HELP)
+ if (command() == ZypperCommand::HELP)
{
setRunningHelp(true);
if (optind < _argc)
- _command = ZypperCommand(_argv[optind++]);
+ setCommand(ZypperCommand(_argv[optind++]));
else
- _command = ZypperCommand::NONE;
+ setCommand(ZypperCommand::NONE);
}
}
// exception from command parsing
catch (Exception & e)
{
cerr << e.msg() << endl;
- _command = ZypperCommand::NONE;
+ setCommand(ZypperCommand::NONE);
}
- if (_command == ZypperCommand::NONE)
+ if (command() == ZypperCommand::NONE)
{
if (runningHelp())
cout << help_global_options << endl << help_commands;
else
{
cerr << _("Try -h for help.") << endl;
- _exit_code = ZYPPER_EXIT_ERR_SYNTAX;
+ setExitCode(ZYPPER_EXIT_ERR_SYNTAX);
return;
}
}
- _exit_code = ZYPPER_EXIT_OK;
+ setExitCode(ZYPPER_EXIT_OK);
MIL << "DONE" << endl;
}
{
MIL << "Entering the shell" << endl;
- _running_shell = true;
+ setRunningShell(true);
string histfile;
try {
{
try
{
- ::command = _command = ZypperCommand(command_str);
- if (_command == ZypperCommand::SHELL_QUIT)
+ setCommand(ZypperCommand(command_str));
+ if (command() == ZypperCommand::SHELL_QUIT)
loop = false;
- else if (_command == ZypperCommand::SHELL)
+ else if (command() == ZypperCommand::SHELL)
cout << _("You already are running zypper's shell.") << endl;
else
safeDoCommand();
write_history (histfile.c_str ());
MIL << "Leaving the shell" << endl;
+ setRunningShell(false);
}
{
processCommandOptions();
doCommand();
- ::command = _command = ZypperCommand::NONE;
+ setCommand(ZypperCommand::NONE);
}
catch (const AbortRequestException & ex)
{
if ( (command() == ZypperCommand::HELP) && (argc() > 1) )
try {
setRunningHelp(true);
- _command = ZypperCommand(argv()[1]);
+ setCommand(ZypperCommand(argv()[1]));
}
catch (Exception & ex) {
// in case of an unknown command specified to help, an exception is thrown
// add repository specified in .repo file
if (copts.count("repo"))
{
- setExitCode(add_repo_from_file(copts["repo"].front(), enabled, refresh));
+ setExitCode(add_repo_from_file(*this,copts["repo"].front(), enabled, refresh));
return;
}
// load gpg keys
cond_init_target ();
- setExitCode(add_repo_by_url(
+ setExitCode(add_repo_by_url(*this,
url, _arguments[1]/*alias*/, type, enabled, refresh));
return;
}
return;
}
- setExitCode(refresh_repos(_arguments));
+ setExitCode(refresh_repos(*this, _arguments));
return;
}
return;
}
- int initret = init_repos();
+ int initret = init_repos(*this);
if (initret != ZYPPER_EXIT_OK)
{
setExitCode(initret);
}
cond_init_target ();
- cond_load_resolvables();
+ cond_load_resolvables(*this);
bool install_not_remove = command() == ZypperCommand::INSTALL;
bool by_capability = false; // install by name by default
for ( vector<string>::const_iterator it = _arguments.begin();
it != _arguments.end(); ++it ) {
if (by_capability)
- mark_by_capability (install_not_remove, kind, *it);
+ mark_by_capability (*this, install_not_remove, kind, *it);
else
mark_by_name (install_not_remove, kind, *it);
}
return;
}
- int initret = init_repos();
+ int initret = init_repos(*this);
if (initret != ZYPPER_EXIT_OK)
{
setExitCode(initret);
}
cond_init_target();
// load only repo resolvables, we don't need the installed ones
- load_repo_resolvables(false /* don't load to pool */);
+ load_repo_resolvables(*this, false /* don't load to pool */);
setExitCode(source_install(_arguments));
return;
options.resolveConflicts();
- int initret = init_repos();
+ int initret = init_repos(*this);
if (initret != ZYPPER_EXIT_OK)
{
setExitCode(initret);
cond_init_target ();
- int initret = init_repos();
+ int initret = init_repos(*this);
if (initret != ZYPPER_EXIT_OK)
{
setExitCode(initret);
// TODO calc token?
// now load resolvables:
- cond_load_resolvables();
+ cond_load_resolvables(*this);
establish ();
patch_check ();
}
cond_init_target ();
- int initret = init_repos();
+ int initret = init_repos(*this);
if (initret != ZYPPER_EXIT_OK)
{
setExitCode(initret);
return;
}
- cond_load_resolvables();
+ cond_load_resolvables(*this);
establish ();
show_patches ();
setExitCode(ZYPPER_EXIT_OK);
cerr << _("Running as 'rug', can't do 'best-effort' approach to update.") << endl;
}
cond_init_target ();
- int initret = init_repos();
+ int initret = init_repos(*this);
if (initret != ZYPPER_EXIT_OK)
{
setExitCode(initret);
return;
}
- cond_load_resolvables();
+ cond_load_resolvables(*this);
establish ();
list_updates( kind, best_effort );
}
cond_init_target ();
- int initret = init_repos();
+ int initret = init_repos(*this);
if (initret != ZYPPER_EXIT_OK)
{
setExitCode(initret);
return;
}
- cond_load_resolvables();
+ cond_load_resolvables(*this);
establish ();
cout << "<update-status version=\"0.6\">" << endl;
cerr << _("Running as 'rug', can't do 'best-effort' approach to update.") << endl;
}
cond_init_target ();
- int initret = init_repos();
+ int initret = init_repos(*this);
if (initret != ZYPPER_EXIT_OK)
{
setExitCode(initret);
return;
}
- cond_load_resolvables ();
+ cond_load_resolvables(*this);
establish ();
bool skip_interactive = copts.count("skip-interactive") || gSettings.non_interactive;
gSettings.license_auto_agree = true;
cond_init_target ();
- int initret = init_repos();
+ int initret = init_repos(*this);
if (initret != ZYPPER_EXIT_OK)
{
setExitCode(initret);
return;
}
- cond_load_resolvables ();
+ cond_load_resolvables(*this);
establish ();
zypp::UpgradeStatistics opt_stats;
God->resolver()->doUpgrade(opt_stats);
}
cond_init_target ();
- int initret = init_repos();
+ int initret = init_repos(*this);
if (initret != ZYPPER_EXIT_OK)
{
setExitCode(initret);
return;
}
- cond_load_resolvables ();
+ cond_load_resolvables(*this);
establish ();
printInfo(command(),_arguments);
char ** argv() { return _running_shell ? _sh_argv : _argv; }
private:
+ void setCommand(const ZypperCommand & command) { _command = command; }
void setRunningShell(bool value) { _running_shell = value; }
void setRunningHelp(bool value) { _running_help = value; }
extern RuntimeData gData;
extern Settings gSettings;
extern std::ostream no_stream;
-extern ZypperCommand command;
#endif /*ZYPPER_H*/