- set exit code inside functions instead of returning it
authorJan Kupec <jkupec@suse.cz>
Fri, 23 Nov 2007 14:33:03 +0000 (14:33 +0000)
committerJan Kupec <jkupec@suse.cz>
Fri, 23 Nov 2007 14:33:03 +0000 (14:33 +0000)
src/zypper-repos.cc
src/zypper-repos.h
src/zypper.cc

index ddb1127..c907434 100644 (file)
@@ -205,7 +205,7 @@ static bool build_cache(const RepoInfo &repo, bool force_build)
 
 // ---------------------------------------------------------------------------
 
-static int do_init_repos(const Zypper & zypper)
+static void do_init_repos(Zypper & zypper)
 {
   // load gpg keys
   cond_init_target ();
@@ -227,7 +227,8 @@ static int do_init_repos(const Zypper & zypper)
     {
       cerr << format(_("Repository '%s' not found.")) % specific_repo << endl;
       ERR << specific_repo << " not found";
-      return ZYPPER_EXIT_ERR_INVALID_ARGS;
+      zypper.setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
+      return;
     }
     catch (const Exception & ex)
     {
@@ -235,7 +236,8 @@ static int do_init_repos(const Zypper & zypper)
           % specific_repo << endl;
       cerr_v << _("Reason: ") << ex.asUserString() << endl;
       ZYPP_CAUGHT(ex);
-      return ZYPPER_EXIT_ERR_ZYPP;
+      zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+      return;
     }
   }
   else
@@ -290,26 +292,23 @@ static int do_init_repos(const Zypper & zypper)
       }
     }
   }
-
-  return ZYPPER_EXIT_OK;
 }
 
 // ----------------------------------------------------------------------------
 
-int init_repos(const Zypper & zypper)
+void init_repos(Zypper & zypper)
 {
   static bool done = false;
   //! \todo this has to be done so that it works in zypper shell
   if (done)
-    return ZYPPER_EXIT_OK;
+    return;
 
   if ( !gSettings.disable_system_sources )
   {
-    return do_init_repos(zypper);
+    do_init_repos(zypper);
   }
 
   done = true;
-  return ZYPPER_EXIT_OK;
 }
 
 // ----------------------------------------------------------------------------
index a5112c2..a270671 100644 (file)
  * 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.
+ * sets exit status to
+ *  - ZYPPER_EXIT_ERR_INVALID_ARGS if --repo does not specify a valid repository,
+ *  - ZYPPER_EXIT_ERR_ZYPP on error
  */
-int init_repos(const Zypper & zypper);
+void init_repos(Zypper & zypper);
 
 /**
  * List defined repositories.
index e6dcb3d..dce7fa1 100644 (file)
@@ -1406,12 +1406,9 @@ void Zypper::doCommand()
       return;
     }
 
-    int initret = init_repos(*this);
-    if (initret != ZYPPER_EXIT_OK)
-    {
-      setExitCode(initret);
+    init_repos(*this);
+    if (exitCode() != ZYPPER_EXIT_OK)
       return;
-    }
 
     //! \todo support temporary additional repos
     /*
@@ -1484,12 +1481,10 @@ void Zypper::doCommand()
       return;
     }
 
-    int initret = init_repos(*this);
-    if (initret != ZYPPER_EXIT_OK)
-    {
-      setExitCode(initret);
+    init_repos(*this);
+    if (exitCode() != ZYPPER_EXIT_OK)
       return;
-    }
+
     cond_init_target();
     // load only repo resolvables, we don't need the installed ones
     load_repo_resolvables(*this, false /* don't load to pool */);
@@ -1549,12 +1544,10 @@ void Zypper::doCommand()
 
     options.resolveConflicts();
 
-    int initret = init_repos(*this);
-    if (initret != ZYPPER_EXIT_OK)
-    {
-      setExitCode(initret);
+    init_repos(*this);
+    if (exitCode() != ZYPPER_EXIT_OK)
       return;
-    }
+
     cond_init_target();         // calls ZYpp::initializeTarget("/");
     
     establish();
@@ -1603,12 +1596,9 @@ void Zypper::doCommand()
 
     cond_init_target ();
 
-    int initret = init_repos(*this);
-    if (initret != ZYPPER_EXIT_OK)
-    {
-      setExitCode(initret);
+    init_repos(*this);
+    if (exitCode() != ZYPPER_EXIT_OK)
       return;
-    }
 
     // TODO additional_sources
     // TODO warn_no_sources
@@ -1653,12 +1643,9 @@ void Zypper::doCommand()
     }
 
     cond_init_target ();
-    int initret = init_repos(*this);
-    if (initret != ZYPPER_EXIT_OK)
-    {
-      setExitCode(initret);
+    init_repos(*this);
+    if (exitCode() != ZYPPER_EXIT_OK)
       return;
-    }
     cond_load_resolvables(*this);
     establish ();
     show_patches ();
@@ -1702,12 +1689,9 @@ void Zypper::doCommand()
        cerr << _("Running as 'rug', can't do 'best-effort' approach to update.") << endl;
     }
     cond_init_target ();
-    int initret = init_repos(*this);
-    if (initret != ZYPPER_EXIT_OK)
-    {
-      setExitCode(initret);
+    init_repos(*this);
+    if (exitCode() != ZYPPER_EXIT_OK)
       return;
-    }
     cond_load_resolvables(*this);
     establish ();
 
@@ -1729,12 +1713,9 @@ void Zypper::doCommand()
     }
 
     cond_init_target ();
-    int initret = init_repos(*this);
-    if (initret != ZYPPER_EXIT_OK)
-    {
-      setExitCode(initret);
+    init_repos(*this);
+    if (exitCode() != ZYPPER_EXIT_OK)
       return;
-    }
     cond_load_resolvables(*this);
     establish ();
 
@@ -1802,12 +1783,9 @@ void Zypper::doCommand()
        cerr << _("Running as 'rug', can't do 'best-effort' approach to update.") << endl;
     }
     cond_init_target ();
-    int initret = init_repos(*this);
-    if (initret != ZYPPER_EXIT_OK)
-    {
-      setExitCode(initret);
+    init_repos(*this);
+    if (exitCode() != ZYPPER_EXIT_OK)
       return;
-    }
     cond_load_resolvables(*this);
     establish ();
 
@@ -1866,12 +1844,9 @@ void Zypper::doCommand()
       gSettings.license_auto_agree = true;
 
     cond_init_target ();
-    int initret = init_repos(*this);
-    if (initret != ZYPPER_EXIT_OK)
-    {
-      setExitCode(initret);
+    init_repos(*this);
+    if (exitCode() != ZYPPER_EXIT_OK)
       return;
-    }
     cond_load_resolvables(*this);
     establish ();
     zypp::UpgradeStatistics opt_stats;
@@ -1920,12 +1895,9 @@ void Zypper::doCommand()
     }
 
     cond_init_target ();
-    int initret = init_repos(*this);
-    if (initret != ZYPPER_EXIT_OK)
-    {
-      setExitCode(initret);
+    init_repos(*this);
+    if (exitCode() != ZYPPER_EXIT_OK)
       return;
-    }
     cond_load_resolvables(*this);
     establish ();