#include <zypp/base/Gettext.h>
#include <zypp/target/store/PersistentStorage.h>
+#include <zypp/RepoManager.h>
#include "checkpatches-keyring-callbacks.h"
#include "zypper.h"
}
-#ifdef LIBZYPP_1xx
-typedef zypp::SourceManager::SourceInfo SourceInfo;
-#else
-using zypp::source::SourceInfo;
-#endif
int exit_with_error( const std::string &error_str )
{
return exit_with_error(excpt_r.msg());
}
- SourceManager_Ptr manager;
- manager = SourceManager::sourceManager();
-
+ RepoManager manager;
+
KeyRingCallbacks keyring_callbacks;
DigestCallbacks digest_callbacks;
-#ifdef LIBZYPP_1xx
- // dont add rpms
- God->initTarget("/", true);
-#else
God->initializeTarget("/");
-#endif
std::string token;
stringstream token_stream;
-#ifdef LIBZYPP_1xx
- token_stream << "[" << "target" << "| " << Date::now() << "]"; // too bad
-#else
token_stream << "[" << "target" << "| " << God->target()->timestamp() << "]";
-#endif
- std::list<SourceInfo> new_sources = manager->knownSourceInfos("/");
- MIL << "Found " << new_sources.size() << " sources." << endl;
+ std::list<RepoInfo> new_sources = manager.knownRepositories();
+ MIL << "Found " << new_sources.size() << " repos." << endl;
- for ( std::list<SourceInfo>::iterator it = new_sources.begin(); it != new_sources.end(); ++it)
+ for (std::list<RepoInfo>::iterator it = new_sources.begin(); it != new_sources.end(); ++it)
{
-#ifdef LIBZYPP_1xx
- Url url = it->url;
-#else
- Url url = it->url();
-#endif
+ Url url = *(it->baseUrlsBegin());
std::string scheme( url.getScheme());
if ( (scheme == "cd" || scheme == "dvd") )
{
- MIL << "Skipping CD/DVD source: url:[" << it->url().asString() << "] product_dir:[" << it->path() << "] alias:[" << it->alias() << "] cache_dir:[" << it->cacheDir() << "] auto_refresh:[ " << it->autorefresh() << "]" << endl;
+ MIL << "Skipping CD/DVD source: url:[" << (it->baseUrlsBegin())->asString() << "] alias:[" << it->alias() << "] auto_refresh:[ " << it->autorefresh() << "]" << endl;
continue;
}
-
+
if ( ! it->enabled() )
{
- MIL << "Skipping disabled source: url:[" << url.asString() << "] product_dir:[" << it->path() << "] alias:[" << it->alias() << "] cache_dir:[" << it->cacheDir() << "] auto_refresh:[ " << it->autorefresh() << "]" << endl;
+ MIL << "Skipping disabled source: url:[" << url.asString() << "] alias:[" << it->alias() << "] auto_refresh:[ " << it->autorefresh() << "]" << endl;
continue;
}
// Note: Url(it->url).asString() to hide password in logs
- MIL << "Creating source: url:[" << url.asString() << "] product_dir:[" << it->path() << "] alias:[" << it->alias() << "] cache_dir:[" << it->cacheDir() << "] auto_refresh:[ " << it->autorefresh() << "]" << endl;
-
+ MIL << "Creating source: url:[" << url.asString() << "] alias:[" << it->alias() << "] auto_refresh:[ " << it->autorefresh() << "]" << endl;
+
try
{
- Source_Ref src = SourceFactory().createFrom(it->type(), url, it->path(), it->alias(), it->cacheDir(), false, it->autorefresh());
- src.refresh();
- token_stream << "[" << src.alias() << "| " << src.url() << src.timestamp() << "]";
-
- MIL << "Source: " << src.alias() << " from " << src.timestamp() << std::endl;
-
- // skip sources without patches sources for now
- bool has_patches = true;
-#ifndef LIBZYPP_1xx
- has_patches = src.hasResolvablesOfKind( ResTraits<zypp::Patch>::kind );
-#endif
- if ( has_patches )
- {
- MIL << "Including source " << src.url() << std::endl;
- gData.sources.push_back(src);
- }
- else
- {
- MIL << "Excluding source " << src.url() << " ( no patches ) "<< std::endl;
- }
+ manager.refreshMetadata(*it);
+ manager.buildCache(*it);
+
+ token_stream << "[" << it->alias() << "| " << *(it->baseUrlsBegin()) << "]"; // src.timestamp() << "]";
+
+ MIL << "Source: " << it->alias() << std::endl; //" from " << src.timestamp() << std::endl;
+
+ gData.repos.push_back(*it);
}
catch (const Exception &excpt_r )
{
gData.errors.push_back(str::form(_("Couldn't restore source.\nDetail: %s"), error.c_str()));
}
}
-
+
string previous_token;
if ( PathInfo(TOKEN_FILE).isExist() )
previous_token = read_old_token();
MIL << "System has changed, recalculation of updates needed" << endl;
}
- for ( std::list<Source_Ref>::const_iterator it = gData.sources.begin(); it != gData.sources.end(); ++it )
+ for ( std::list<RepoInfo>::const_iterator it = gData.repos.begin(); it != gData.repos.end(); ++it )
{
- God->addResolvables(it->resolvables());
+ Repository repository = manager.createFromCache(*it);
+ God->addResolvables(repository.resolvables());
}
-
- if ( gData.sources.size() == 0 )
+
+ if ( gData.repos.size() == 0 )
{
gData.errors.push_back( str::form( _( "There are no update sources defined. Please add one or more update sources in order to be notified of updates.") ) );
}
-
+
God->addResolvables( God->target()->resolvables(), true);
God->resolver()->establishPool();
parsed_opts gopts;
bool ghelp = false;
-// parses global options, returns the command
-string process_globals(int argc, char **argv)
+/*
+ * parses global options, returns the command
+ *
+ * \returns ZypperCommand object representing the command or ZypperCommand::NONE
+ * if an unknown command has been given.
+ */
+ZypperCommand process_globals(int argc, char **argv)
{
// global options
gopts = parse_options (argc, argv, global_options);
if (gopts.count("_unknown"))
- return "_unknown";
+ return ZypperCommand::NONE;
+ //return "_unknown";
if (gopts.count("rug-compatible"))
gSettings.is_rug_compatible = true;
cerr << endl;
}
- string command;
+ // get command
- if (optind < argc) {
- command = argv[optind++];
- }
- if (command == "help") {
- ghelp = true;
- if (optind < argc) {
- command = argv[optind++];
- }
- else {
- command = "";
+ ZypperCommand command(ZypperCommand::NONE_e);
+ try
+ {
+ if (optind < argc)
+ command = ZypperCommand(argv[optind++]);
+
+ if (command == ZypperCommand::HELP)
+ {
+ ghelp = true;
+ if (optind < argc)
+ command = ZypperCommand(argv[optind++]);
+ else
+ command = ZypperCommand::NONE;
}
}
+ // exception from command parsing
+ catch (Exception & e)
+ {
+ cerr << e.msg() << endl;
+ command = ZypperCommand::NONE;
+ }
- if (command.empty()) {
- if (ghelp) {
- cerr << help_global_options << help_commands;
- }
- else if (gopts.count("version")) {
- cerr << PACKAGE;
-#ifdef LIBZYPP_1xx
- cerr << " (libzypp-1.x.x)";
-#endif
- cerr << endl;
- }
- else {
+ if (command == ZypperCommand::NONE)
+ {
+ if (ghelp)
+ cerr << help_global_options << endl << help_commands;
+ else if (gopts.count("version"))
+ cerr << PACKAGE << endl;
+ else
cerr << _("Try -h for help") << endl;
- }
}
- cerr_vv << "COMMAND: " << command << endl;
+ //cerr_vv << "COMMAND: " << command << endl;
return command;
}
/// process one command from the OS shell or the zypper shell
-int one_command(const string& command_str, int argc, char **argv)
+int one_command(const ZypperCommand & command, int argc, char **argv)
{
// === command-specific options ===
- ZypperCommand command(command_str);
-
struct option no_options = {0, 0, 0, 0};
struct option *specific_options = &no_options;
string specific_help;
"\t--disable-system-resolvables, -T\t\tDo not read system installed resolvables\n"
);
- if (command.toEnum() == ZypperCommand::INSTALL_e) {
+ if (command == ZypperCommand::HELP)
+ {
+ //cout << help_global_options << endl << help_commands;
+ }
+ else if (command == ZypperCommand::INSTALL) {
static struct option install_options[] = {
{"catalog", required_argument, 0, 'c'},
{"type", required_argument, 0, 't'},
"\t--no-confirm,-y\tDo not require user confirmation\n"
);
}
- else if (command.toEnum() == ZypperCommand::REMOVE_e) {
+ else if (command == ZypperCommand::REMOVE) {
static struct option remove_options[] = {
{"type", required_argument, 0, 't'},
{"no-confirm", no_argument, 0, 'y'},
"\t--no-confirm,-y\tDo not require user confirmation\n"
);
}
- else if (command.toEnum() == ZypperCommand::ADD_REPO_e) {
+ else if (command == ZypperCommand::ADD_REPO) {
static struct option service_add_options[] = {
{"type", required_argument, 0, 't'},
{"disabled", no_argument, 0, 'd'},
"\t--no-refresh,-n\t\tDo not automatically refresh the metadata\n"
);
}
- else if (command.toEnum() == ZypperCommand::LIST_REPOS_e) {
+ else if (command == ZypperCommand::LIST_REPOS) {
static struct option service_list_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"This command has no options.\n"
);
}
- else if (command.toEnum() == ZypperCommand::REMOVE_REPO_e) {
+ else if (command == ZypperCommand::REMOVE_REPO) {
static struct option service_delete_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"This command has no options.\n"
);
}
- else if (command_str == "service-rename" || command_str == "sr") {
+ else if (command == ZypperCommand::NONE) {//command_str == "service-rename" || command_str == "sr") {
static struct option service_rename_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"This command has no options.\n"
);
}
- else if (command.toEnum() == ZypperCommand::REFRESH_e) {
+ else if (command == ZypperCommand::REFRESH) {
static struct option refresh_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"Refresh all installation sources found in the system.\n"
);
}
- else if (command_str == "list-updates" || command_str == "lu") {
+ else if (command == ZypperCommand::NONE) { //command_str == "list-updates" || command_str == "lu") {
static struct option list_updates_options[] = {
{"type", required_argument, 0, 't'},
{"help", no_argument, 0, 'h'},
"\t--type,-t\t\tType of resolvable (default: patch)\n"
);
}
- else if (command_str == "update" || command_str == "up") {
+ else if (command == ZypperCommand::NONE) { //command_str == "update" || command_str == "up") {
static struct option update_options[] = {
{"type", required_argument, 0, 't'},
{"no-confirm", no_argument, 0, 'y'},
"\t--skip-interactive\t\tSkip interactive updates\n"
);
}
- else if (command_str == "search" || command_str == "se") {
+ else if (command == ZypperCommand::SEARCH) {
static struct option search_options[] = {
{"installed-only", no_argument, 0, 'i'},
{"uninstalled-only", no_argument, 0, 'u'},
"* and ? wildcards can also be used within search strings.\n"
);
}
- else if (command_str == "patch-check" || command_str == "pchk") {
+ else if (command == ZypperCommand::NONE) {//command_str == "patch-check" || command_str == "pchk") {
static struct option patch_check_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"This command has no options.\n"
);
}
- else if (command_str == "patches" || command_str == "pch") {
+ else if (command == ZypperCommand::NONE) {//command_str == "patches" || command_str == "pch") {
static struct option patches_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"This command has no options.\n"
);
}
- else if (command_str == "info" || command_str == "if") {
+ else if (command == ZypperCommand::NONE) {//command_str == "info" || command_str == "if") {
static struct option info_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"'info' -- Show full information for packages\n"
);
}
- else if (command_str == "patch-info") {
+ else if (command == ZypperCommand::NONE) {//command_str == "patch-info") {
static struct option patch_info_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"'patch-info' -- Show detailed information for patches\n"
);
}
- else if (command_str == "moo") {
+ else if (command == ZypperCommand::MOO) {
static struct option moo_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"'moo' - Show an animal\n"
);
}
- else if (!command_str.empty()) { // empty command is treated earlier
- if (command_str != "help") // #235709
- cerr << _("Unknown command") << " '" << command_str << "'." << endl << endl;
- cerr << help_commands;
- return ZYPPER_EXIT_ERR_SYNTAX;
- }
parsed_opts copts = parse_options (argc, argv, specific_options);
if (copts.count("_unknown"))
vector<string> arguments;
if (optind < argc) {
- cerr_v << _("Non-Option Program Arguments: ");
+ cerr_v << _("Non-option program arguments: ");
while (optind < argc) {
string argument = argv[optind++];
cerr_v << argument << ' ';
// here come commands that need the lock
try {
- if (command_str == "service-list" || command_str == "sl")
+ if (command == ZypperCommand::LIST_REPOS)
zypp_readonly_hack::IWantIt (); // #247001
God = zypp::getZYpp();
// --------------------------( moo )----------------------------------------
- if (command_str == "moo") {
+ if (command == ZypperCommand::MOO)
+ {
cout << " \\\\\\\\\\\n \\\\\\\\\\\\\\__o\n__\\\\\\\\\\\\\\'/_" << endl;
return ZYPPER_EXIT_OK;
}
// --------------------------( service list )-------------------------------
- else if (command.toEnum() == ZypperCommand::LIST_REPOS_e)
+ else if (command == ZypperCommand::LIST_REPOS)
{
if (ghelp) { cout << specific_help << endl; return !ghelp; }
// if (ghelp) display_command_help()
// --------------------------( service add )--------------------------------
- else if (command.toEnum() == ZypperCommand::ADD_REPO_e)
+ else if (command == ZypperCommand::ADD_REPO)
{
tribool enabled(indeterminate);
tribool refresh(indeterminate);
// --------------------------( service delete )-----------------------------
- else if (command.toEnum() == ZypperCommand::REMOVE_REPO_e)
+ else if (command == ZypperCommand::REMOVE_REPO)
{
if (ghelp || arguments.size() < 1) {
cerr << specific_help;
}
// --------------------------( service rename )-----------------------------
-
- else if (command_str == "service-rename" || command_str == "sr")
+/*
+ else if (command == ZypperCommand::NONE) //command_str == "service-rename" || command_str == "sr")
{
if (ghelp || arguments.size() < 2) {
cerr << specific_help;
return ZYPPER_EXIT_OK;
}
-
+ */
// --------------------------( refresh )------------------------------------
- else if (command.toEnum() == ZypperCommand::REFRESH_e)
+ else if (command == ZypperCommand::REFRESH)
{
if (ghelp) { cout << specific_help; return !ghelp; }
// --------------------------( remove/install )-----------------------------
- else if (command.toEnum() == ZypperCommand::INSTALL_e ||
- command.toEnum() == ZypperCommand::REMOVE_e )
+ else if (command == ZypperCommand::INSTALL ||
+ command == ZypperCommand::REMOVE)
{
- if (command.toEnum() == ZypperCommand::INSTALL_e) {
+ if (command == ZypperCommand::INSTALL) {
if (ghelp || arguments.size() < 1) {
cerr << "install [options] name...\n" << specific_help;
return !ghelp;
gData.packages_to_install = arguments;
}
- if (command.toEnum() == ZypperCommand::REMOVE_e) {
+ if (command == ZypperCommand::REMOVE) {
if (ghelp || arguments.size() < 1) {
cerr << "remove [options] name...\n"
<< specific_help
zypp::getZYpp()->addResolvables(zypp::getZYpp()->target()->resolvables(), true);
for ( vector<string>::const_iterator it = arguments.begin(); it != arguments.end(); ++it ) {
- if (command.toEnum() == ZypperCommand::INSTALL_e) {
+ if (command == ZypperCommand::INSTALL) {
mark_for_install(kind, *it);
}
else {
// TODO -c, --catalog option
- else if (command_str == "search" || command_str == "se") {
+ else if (command == ZypperCommand::SEARCH)
+ {
ZyppSearchOptions options;
if (ghelp) {
// --------------------------( patch check )--------------------------------
// TODO: rug summary
- else if (command_str == "patch-check" || command_str == "pchk") {
+ else if (command == ZypperCommand::NONE) {//command_str == "patch-check" || command_str == "pchk") {
if (ghelp) {
cerr << specific_help;
return !ghelp;
}
cond_init_target ();
- cond_init_system_sources ();
+ init_repos ();
// TODO additional_sources
// TODO warn_no_sources
// TODO calc token?
// now load resolvables:
- cond_load_resolvables ();
+ load_repo_resolvables ();
establish ();
patch_check ();
// --------------------------( patches )------------------------------------
- else if (command_str == "patches" || command_str == "pch") {
+ else if (command == ZypperCommand::NONE) {//command_str == "patches" || command_str == "pch") {
if (ghelp) {
cerr << specific_help;
return !ghelp;
}
cond_init_target ();
- cond_init_system_sources ();
- cond_load_resolvables ();
+ init_repos ();
+ load_repo_resolvables ();
establish ();
show_patches ();
return ZYPPER_EXIT_OK;
// --------------------------( list updates )-------------------------------
- else if (command_str == "list-updates" || command_str == "lu") {
+ else if (command == ZypperCommand::NONE) {//command_str == "list-updates" || command_str == "lu") {
if (ghelp) {
// FIXME catalog...
cerr << specific_help;
}
cond_init_target ();
- cond_init_system_sources ();
- cond_load_resolvables ();
+ init_repos ();
+ load_repo_resolvables ();
establish ();
list_updates (kind);
// -----------------------------( update )----------------------------------
- else if (command_str == "update" || command_str == "up") {
+ else if (command == ZypperCommand::NONE) {//command_str == "update" || command_str == "up") {
if (ghelp) {
cerr << "update [options]\n"
<< specific_help
}
cond_init_target ();
- cond_init_system_sources ();
- cond_load_resolvables ();
+ init_repos ();
+ load_repo_resolvables ();
establish ();
bool skip_interactive = copts.count("skip-interactive") || gSettings.non_interactive;
// -----------------------------( info )------------------------------------
- else if (command_str == "info" || command_str == "if" || command_str == "patch-info") {
+ else if (command == ZypperCommand::NONE) {//command_str == "info" || command_str == "if" || command_str == "patch-info") {
if (ghelp || arguments.size() == 0) {
cerr << specific_help;
return !ghelp;
}
cond_init_target ();
- cond_init_system_sources ();
- cond_load_resolvables ();
+ init_repos ();
+ load_repo_resolvables ();
establish ();
- printInfo(command_str,arguments);
+ printInfo(command,arguments);
return ZYPPER_EXIT_OK;
}
return ZYPPER_EXIT_ERR_BUG;
}
+// ----------------------------------------------------------------------------
+
/// tell to report a bug, and how
// (multiline, with endls)
ostream& report_a_bug (ostream& stm) {
<< _("See http://en.opensuse.org/Zypper#Troubleshooting for instructions.") << endl;
}
+// ----------------------------------------------------------------------------
+
/// process one command from the OS shell or the zypper shell
// catch unexpected exceptions and tell the user to report a bug (#224216)
-int safe_one_command(const string& command, int argc, char **argv)
+int safe_one_command(const ZypperCommand & command, int argc, char **argv)
{
int ret = ZYPPER_EXIT_ERR_BUG;
try {
return ret;
}
+// ----------------------------------------------------------------------------
+
// Read a string. "\004" (^D) on EOF.
string readline_getline ()
{
return "\004";
}
+// ----------------------------------------------------------------------------
+
void command_shell ()
{
string histfile;
bool loop = true;
while (loop) {
+ // reset globals
+ ghelp = false;
+
// read a line
string line = readline_getline ();
cerr_vv << "Got: " << line << endl;
int sh_argc = args.argc ();
char **sh_argv = args.argv ();
- string command = sh_argv[0]? sh_argv[0]: "";
+ string command_str = sh_argv[0]? sh_argv[0]: "";
- if (command == "\004") {
+ if (command_str == "\004") // ^D
+ {
loop = false;
- cout << endl;
+ cout << endl; // print newline after ^D
}
- else if (command == "exit" || command == "quit")
- loop = false;
else
- safe_one_command (command, sh_argc, sh_argv);
+ {
+ try
+ {
+ ZypperCommand command(command_str);
+ if (command == ZypperCommand::SHELL_QUIT)
+ loop = false;
+ else if (command == ZypperCommand::SHELL)
+ cout << _("You already are running zypper's shell.") << endl;
+ else
+ safe_one_command (command, sh_argc, sh_argv);
+ }
+ catch (Exception & e)
+ {
+ cerr << e.msg() << endl;
+ }
+ }
}
if (!histfile.empty ())
write_history (histfile.c_str ());
}
+// ----------------------------------------------------------------------------
+
int main(int argc, char **argv)
{
struct Bye {
if (logfile == NULL)
logfile = ZYPP_CHECKPATCHES_LOG;
zypp::base::LogControl::instance().logfile( logfile );
-
+
// parse global options and the command
- string command = process_globals (argc, argv);
- int ret = 0;
- if (command == "shell" || command == "sh")
- command_shell ();
- else
- ret = safe_one_command (command, argc, argv);
+ ZypperCommand command = process_globals (argc, argv);
+ switch(command.toEnum())
+ {
+ case ZypperCommand::SHELL_e:
+ command_shell();
+ return ZYPPER_EXIT_OK;
- return ret;
+ case ZypperCommand::NONE_e:
+ return ZYPPER_EXIT_ERR_SYNTAX;
+
+ default:
+ return safe_one_command(command, argc, argv);
+ }
+
+ cerr_v << "This line should never be reached." << endl;
+ return ZYPPER_EXIT_ERR_BUG;
}
+
// Local Variables:
// c-basic-offset: 2
// End: