- addrepo --refresh/-f added to enable autorefresh upon adding the repo
authorJan Kupec <jkupec@suse.cz>
Tue, 29 Jul 2008 08:57:56 +0000 (08:57 +0000)
committerJan Kupec <jkupec@suse.cz>
Tue, 29 Jul 2008 08:57:56 +0000 (08:57 +0000)
  (bnc #406006)

src/Zypper.cc
src/repos.cc
src/repos.h

index f08ef09..ae5fd98 100644 (file)
@@ -1080,6 +1080,7 @@ void Zypper::processCommandOptions()
       {"name", required_argument, 0, 'n'},
       {"keep-packages", no_argument, 0, 'k'},
       {"no-keep-packages", no_argument, 0, 'K'},
+      {"refresh", no_argument, 0, 'f'},
       {0, 0, 0, 0}
     };
     specific_options = service_add_options;
@@ -1092,7 +1093,7 @@ void Zypper::processCommandOptions()
       " or can be read from specified .repo file (even remote).\n"
       "\n"
       "  Command options:\n"
-      "-r, --repo <FILE.repo>  Read the URI and alias from a file (even remote).\n"
+      "-r, --repo <FILE.repo>  Just another means to specify a .repo file to read.\n"
       "-t, --type <TYPE>       Type of repository (%s).\n"
       "-d, --disable           Add the repository as disabled.\n"
       "-c, --check             Probe URI.\n"
@@ -1100,6 +1101,7 @@ void Zypper::processCommandOptions()
       "-n, --name              Specify descriptive name for the repository.\n"
       "-k, --keep-packages     Enable RPM files caching.\n"
       "-K, --no-keep-packages  Disable RPM files caching.\n"
+      "-f, --refresh           Enable autorefresh of the repository.\n"
     ), "yast2, rpm-md, plaindir");
     break;
   }
@@ -2233,12 +2235,16 @@ void Zypper::doCommand()
     }
 
     // indeterminate indicates the user has not specified the values
-    tribool enabled(indeterminate);
 
+    TriBool enabled = indeterminate;
     if (copts.count("disable") || copts.count("disabled"))
       enabled = false;
 
-    tribool keep_pkgs;
+    TriBool autorefresh = indeterminate;
+    if (copts.count("refresh"))
+      autorefresh = true;
+
+    TriBool keep_pkgs;
     if (copts.count("keep-packages"))
       keep_pkgs = true;
     else if (copts.count("no-keep-packages"))
@@ -2249,7 +2255,7 @@ void Zypper::doCommand()
       // add repository specified in .repo file
       if (copts.count("repo"))
       {
-        add_repo_from_file(*this,copts["repo"].front(), enabled, false, keep_pkgs);
+        add_repo_from_file(*this,copts["repo"].front(), enabled, autorefresh, keep_pkgs);
         return;
       }
 
@@ -2296,7 +2302,7 @@ void Zypper::doCommand()
         }
         else
         {
-          add_repo_from_file(*this,_arguments[0], enabled, false, keep_pkgs);
+          add_repo_from_file(*this,_arguments[0], enabled, autorefresh, keep_pkgs);
           break;
         }
       case 2:
@@ -2307,8 +2313,6 @@ void Zypper::doCommand()
           return;
         }
 
-        // by default, enable the repo and set autorefresh to false
-        if (indeterminate(enabled)) enabled = true;
         if (copts.count("check"))
         {
           if (!copts.count("no-check"))
@@ -2328,7 +2332,7 @@ void Zypper::doCommand()
         init_target(*this);
 
         add_repo_by_url(
-           *this, url, _arguments[1]/*alias*/, type, enabled, false, keep_pkgs);
+           *this, url, _arguments[1]/*alias*/, type, enabled, autorefresh, keep_pkgs);
         return;
       }
     }
index 3ff2407..ff2c2e7 100644 (file)
@@ -1314,7 +1314,7 @@ void add_repo(Zypper & zypper, RepoInfo & repo)
 void add_repo_by_url( Zypper & zypper,
                      const zypp::Url & url, const string & alias,
                      const string & type,
-                     tribool enabled, tribool autorefresh, tribool keepPackages)
+                     TriBool enabled, TriBool autorefresh, TriBool keepPackages)
 {
   MIL << "going to add repository by url (alias=" << alias << ", url=" << url
       << ")" << endl;
@@ -1330,12 +1330,16 @@ void add_repo_by_url( Zypper & zypper,
     repo.setName(it->second.front());
   repo.addBaseUrl(url);
 
-  if ( !indeterminate(enabled) )
-    repo.setEnabled((enabled == true));
+  // enable the repo by default
+  if ( indeterminate(enabled) )
+    enabled = true;
+  repo.setEnabled((enabled == true));
+
+  // disable autorefresh by default
   if ( indeterminate(autorefresh) )
-    repo.setAutorefresh(false);
-  else
-    repo.setAutorefresh((autorefresh == true));
+    autorefresh = false;
+  repo.setAutorefresh((autorefresh == true));
+
   if ( !indeterminate(keepPackages) )
     repo.setKeepPackages(keepPackages);
 
@@ -1344,12 +1348,10 @@ void add_repo_by_url( Zypper & zypper,
 
 // ----------------------------------------------------------------------------
 
-//! \todo handle zypp exceptions
 void add_repo_from_file( Zypper & zypper,
-                         const std::string & repo_file_url, tribool enabled,
-                         tribool autorefresh, tribool keepPackages)
+                         const std::string & repo_file_url, TriBool enabled,
+                         TriBool autorefresh, TriBool keepPackages)
 {
-  //! \todo handle local .repo files, validate the URI
   Url url = make_url(repo_file_url);
   if (!url.isValid())
   {
@@ -1411,14 +1413,20 @@ void add_repo_from_file( Zypper & zypper,
       continue;
     }
 
-    MIL << "enabled: " << enabled << " autorefresh: " << autorefresh << endl;
-    if ( !indeterminate(enabled) )
-      repo.setEnabled((enabled == true));
-    if ( !indeterminate(autorefresh) )
-      repo.setAutorefresh((autorefresh == false));
+    MIL << "requested: enabled: " << enabled << " autorefresh: " << autorefresh << endl;
+    // enable by default
+    if ( indeterminate(enabled) )
+      enabled = true;
+    repo.setEnabled((enabled == true));
+    // disable autorefresh by default
+    if ( indeterminate(autorefresh) )
+      autorefresh = false;
+    repo.setAutorefresh((autorefresh == true));
+
     if ( !indeterminate(keepPackages) )
       repo.setKeepPackages(keepPackages);
-    MIL << "enabled: " << repo.enabled() << " autorefresh: " << repo.autorefresh() << endl;
+
+    MIL << "to-be-added: enabled: " << repo.enabled() << " autorefresh: " << repo.autorefresh() << endl;
 
     add_repo(zypper, repo);
   }
index 7243f6b..6200592 100644 (file)
@@ -8,8 +8,7 @@
 #ifndef ZMART_SOURCES_H
 #define ZMART_SOURCES_H
 
-//#include <boost/logic/tribool.hpp>
-
+#include "zypp/TriBool.h"
 #include "zypp/Url.h"
 #include "zypp/RepoInfo.h"
 #include "zypp/Service.h"
@@ -82,9 +81,9 @@ void add_repo_by_url(Zypper & zypper,
                      const zypp::Url & url,
                      const std::string & alias,
                      const std::string & type = "",
-                     boost::tribool enabled = boost::indeterminate,
-                     boost::tribool autorefresh = boost::indeterminate,
-                     boost::tribool keepPackages = boost::indeterminate);
+                     zypp::TriBool enabled = boost::indeterminate,
+                     zypp::TriBool autorefresh = boost::indeterminate,
+                     zypp::TriBool keepPackages = boost::indeterminate);
 
 /**
  * Add repository specified in given repo file on \a repo_file_url. All repos
@@ -97,9 +96,9 @@ void add_repo_by_url(Zypper & zypper,
  */
 void add_repo_from_file(Zypper & zypper,
                         const std::string & repo_file_url,
-                        boost::tribool enabled = boost::indeterminate,
-                        boost::tribool autorefresh = boost::indeterminate,
-                        boost::tribool keepPackages = boost::indeterminate);
+                        zypp::TriBool enabled = boost::indeterminate,
+                        zypp::TriBool autorefresh = boost::indeterminate,
+                        zypp::TriBool keepPackages = boost::indeterminate);
 
 
 /**