- command global variable removed, Zypper object passed where needed
authorJan Kupec <jkupec@suse.cz>
Fri, 23 Nov 2007 12:52:09 +0000 (12:52 +0000)
committerJan Kupec <jkupec@suse.cz>
Fri, 23 Nov 2007 12:52:09 +0000 (12:52 +0000)
src/zypper-misc.cc
src/zypper-misc.h
src/zypper-repos.cc
src/zypper-repos.h
src/zypper.cc
src/zypper.h

index 0f387c6..8893267 100644 (file)
@@ -186,7 +186,9 @@ struct NewerVersionGetter
 };
 
 // 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>]
@@ -208,7 +210,7 @@ Capability safe_parse_cap (const ResObject::Kind &kind, const string & capstr) {
     // 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;
@@ -371,11 +373,12 @@ bool mark_by_name_edition (...)
 
 */
 
-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;
index a6e2dcc..773edbc 100644 (file)
@@ -22,7 +22,8 @@
 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);
@@ -34,7 +35,8 @@ void mark_for_uninstall( const zypp::ResObject::Kind &kind,
 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 );
 
index 75c336c..ddb1127 100644 (file)
@@ -36,7 +36,9 @@ extern RuntimeData gData;
 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;
 
@@ -62,11 +64,12 @@ static bool refresh_raw_metadata(const RepoInfo & repo, bool force_download)
           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;
           }
@@ -202,7 +205,7 @@ static bool build_cache(const RepoInfo &repo, bool force_build)
 
 // ---------------------------------------------------------------------------
 
-static int do_init_repos()
+static int do_init_repos(const Zypper & zypper)
 {
   // load gpg keys
   cond_init_target ();
@@ -255,7 +258,7 @@ static int do_init_repos()
       // 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;
@@ -293,7 +296,7 @@ static int do_init_repos()
 
 // ----------------------------------------------------------------------------
 
-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
@@ -302,7 +305,7 @@ int init_repos()
 
   if ( !gSettings.disable_system_sources )
   {
-    return do_init_repos();
+    return do_init_repos(zypper);
   }
 
   done = true;
@@ -482,7 +485,7 @@ void safe_lexical_cast (Source s, Target &tr) {
 
 // ----------------------------------------------------------------------------
 
-int refresh_repos(vector<string> & arguments)
+int refresh_repos(const Zypper & zypper, vector<string> & arguments)
 {
   // need gpg keys when downloading (#304672)
   cond_init_target();
@@ -585,7 +588,7 @@ int refresh_repos(vector<string> & arguments)
       MIL << "calling refreshMetadata" << (force_download ? ", forced" : "")
           << endl;
 
-      error = refresh_raw_metadata(repo, force_download);
+      error = refresh_raw_metadata(zypper, repo, force_download);
     }
 
     // db rebuild
@@ -674,7 +677,7 @@ std::string timestamp ()
 // ----------------------------------------------------------------------------
 
 static
-int add_repo(RepoInfo & repo)
+int add_repo(const Zypper & zypper, RepoInfo & repo)
 {
   RepoManager manager(gSettings.rm_options);
 
@@ -763,7 +766,7 @@ int add_repo(RepoInfo & repo)
   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)
@@ -779,7 +782,8 @@ int add_repo(RepoInfo & repo)
 
 // ----------------------------------------------------------------------------
 
-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)
 {
@@ -800,13 +804,14 @@ int add_repo_by_url( const zypp::Url & url, const string & alias,
   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
@@ -857,7 +862,7 @@ int add_repo_from_file(const std::string & repo_file_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;
@@ -1047,16 +1052,16 @@ void modify_repo(const string & alias)
 
 // ---------------------------------------------------------------------------
 
-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);
 
@@ -1077,7 +1082,7 @@ void load_repo_resolvables(bool to_pool)
       {
         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))
index 57a0dfb..a5112c2 100644 (file)
@@ -5,6 +5,8 @@
 
 #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.
@@ -12,7 +14,7 @@
  * \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.
@@ -22,7 +24,7 @@ void list_repos();
 /**
  * Refresh all enabled repositories.
  */
-int refresh_repos(std::vector<std::string> & arguments);
+int refresh_repos(const Zypper & zypper, std::vector<std::string> & arguments);
 
 
 /**
@@ -36,10 +38,12 @@ int refresh_repos(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
@@ -52,8 +56,10 @@ int add_repo_by_url( const zypp::Url & url,
  * \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.
@@ -85,7 +91,7 @@ void modify_repo(const std::string & 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.
@@ -103,7 +109,7 @@ void load_target_resolvables(bool to_pool = true);
  *        <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);
 
 
 /**
index 535a41f..e6dcb3d 100644 (file)
@@ -50,7 +50,6 @@ RuntimeData gData;
 Settings gSettings;
 parsed_opts gopts; // global options
 parsed_opts copts; // command options
-ZypperCommand command(ZypperCommand::NONE);
 
 
 Zypper::Zypper()
@@ -311,25 +310,25 @@ void Zypper::processGlobalOptions()
   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;
@@ -338,12 +337,12 @@ void Zypper::processGlobalOptions()
     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;
 }
@@ -353,7 +352,7 @@ void Zypper::commandShell()
 {
   MIL << "Entering the shell" << endl;
 
-  _running_shell = true;
+  setRunningShell(true);
 
   string histfile;
   try {
@@ -393,10 +392,10 @@ void Zypper::commandShell()
     {
       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();
@@ -412,6 +411,7 @@ void Zypper::commandShell()
     write_history (histfile.c_str ());
 
   MIL << "Leaving the shell" << endl;
+  setRunningShell(false);
 }
 
 
@@ -423,7 +423,7 @@ void Zypper::safeDoCommand()
   {
     processCommandOptions();
     doCommand();
-    ::command = _command = ZypperCommand::NONE;
+    setCommand(ZypperCommand::NONE);
   }
   catch (const AbortRequestException & ex)
   {
@@ -467,7 +467,7 @@ void Zypper::processCommandOptions()
   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
@@ -1117,7 +1117,7 @@ void Zypper::doCommand()
       // 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;
       }
   
@@ -1146,7 +1146,7 @@ void Zypper::doCommand()
       // 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;
     }
@@ -1354,7 +1354,7 @@ void Zypper::doCommand()
       return;
     }
 
-    setExitCode(refresh_repos(_arguments));
+    setExitCode(refresh_repos(*this, _arguments));
     return;
   }
 
@@ -1406,7 +1406,7 @@ void Zypper::doCommand()
       return;
     }
 
-    int initret = init_repos();
+    int initret = init_repos(*this);
     if (initret != ZYPPER_EXIT_OK)
     {
       setExitCode(initret);
@@ -1429,7 +1429,7 @@ void Zypper::doCommand()
     }
 
     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
@@ -1438,7 +1438,7 @@ void Zypper::doCommand()
     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);
     }
@@ -1484,7 +1484,7 @@ void Zypper::doCommand()
       return;
     }
 
-    int initret = init_repos();
+    int initret = init_repos(*this);
     if (initret != ZYPPER_EXIT_OK)
     {
       setExitCode(initret);
@@ -1492,7 +1492,7 @@ void Zypper::doCommand()
     }
     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;
@@ -1549,7 +1549,7 @@ void Zypper::doCommand()
 
     options.resolveConflicts();
 
-    int initret = init_repos();
+    int initret = init_repos(*this);
     if (initret != ZYPPER_EXIT_OK)
     {
       setExitCode(initret);
@@ -1603,7 +1603,7 @@ void Zypper::doCommand()
 
     cond_init_target ();
 
-    int initret = init_repos();
+    int initret = init_repos(*this);
     if (initret != ZYPPER_EXIT_OK)
     {
       setExitCode(initret);
@@ -1615,7 +1615,7 @@ void Zypper::doCommand()
     // TODO calc token?
 
     // now load resolvables:
-    cond_load_resolvables();
+    cond_load_resolvables(*this);
 
     establish ();
     patch_check ();
@@ -1653,13 +1653,13 @@ void Zypper::doCommand()
     }
 
     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);
@@ -1702,13 +1702,13 @@ void Zypper::doCommand()
        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 );
@@ -1729,13 +1729,13 @@ void Zypper::doCommand()
     }
 
     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;
@@ -1802,13 +1802,13 @@ void Zypper::doCommand()
        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;
@@ -1866,13 +1866,13 @@ void Zypper::doCommand()
       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);
@@ -1920,13 +1920,13 @@ void Zypper::doCommand()
     }
 
     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);
index 453fc0e..18e3f4b 100644 (file)
@@ -39,6 +39,7 @@ public:
   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; }
 
@@ -125,7 +126,6 @@ struct RuntimeData
 extern RuntimeData gData;
 extern Settings gSettings;
 extern std::ostream no_stream;
-extern ZypperCommand command;
 
 #endif /*ZYPPER_H*/