--download option added to in, up, dup, ve, and patch.
authorJán Kupec <jkupec@suse.cz>
Fri, 20 Nov 2009 14:11:44 +0000 (15:11 +0100)
committerJán Kupec <jkupec@suse.cz>
Fri, 20 Nov 2009 14:11:44 +0000 (15:11 +0100)
src/Zypper.cc
src/solve-commit.cc
src/utils/misc.cc
src/utils/misc.h

index ea0292b..9777849 100644 (file)
@@ -917,6 +917,7 @@ void Zypper::processCommandOptions()
       {"no-recommends",             no_argument,       0,  0 },
       {"recommends",                no_argument,       0,  0 },
       {"download-only",             no_argument,       0, 'd'},
+      {"download",                  required_argument, 0,  0 },
       // rug compatibility - will mark all packages for installation (like 'in *')
       {"entire-catalog",            required_argument, 0,  0 },
       {"help",                      no_argument,       0, 'h'},
@@ -1036,6 +1037,7 @@ void Zypper::processCommandOptions()
       // rug uses -N shorthand
       {"dry-run", no_argument, 0, 'N'},
       {"download-only", no_argument, 0, 'd'},
+      {"download", required_argument, 0, 0},
       {"repo", required_argument, 0, 'r'},
       {"no-recommends", no_argument, 0, 0},
       {"help", no_argument, 0, 'h'},
@@ -1066,6 +1068,7 @@ void Zypper::processCommandOptions()
     static struct option options[] = {
       {"dry-run", no_argument, 0, 'D'},
       {"download-only", no_argument, 0, 'd'},
+      {"download", required_argument, 0, 0},
       {"repo", required_argument, 0, 'r'},
       {"debug-solver", no_argument, 0, 0},
       {"help", no_argument, 0, 'h'},
@@ -1540,6 +1543,7 @@ void Zypper::processCommandOptions()
       // rug uses -N shorthand
       {"dry-run",                   no_argument,       0, 'N'},
       {"download-only",             no_argument,       0, 'd'},
+      {"download",                  required_argument, 0,  0 },
       // rug-compatibility - dummy for now
       //! \todo category can now be implemented in 'patch' using PoolQuery
       {"category",                  no_argument,       0, 'g'},
@@ -1593,6 +1597,7 @@ void Zypper::processCommandOptions()
       {"recommends",                no_argument,       0,  0 },
       {"dry-run",                   no_argument,       0, 'D'},
       {"download-only",             no_argument,       0, 'd'},
+      {"download",                  required_argument, 0,  0 },
       {"bz",                        required_argument, 0, 'b'},
       {"bugzilla",                  required_argument, 0, 'b'},
       {"cve",                       required_argument, 0,  0 },
@@ -1669,6 +1674,7 @@ void Zypper::processCommandOptions()
       // rug uses -N shorthand
       {"dry-run",                   no_argument,       0, 'N'},
       {"download-only",             no_argument,       0, 'd'},
+      {"download",                  required_argument, 0,  0 },
       {"help", no_argument, 0, 'h'},
       {0, 0, 0, 0}
     };
@@ -3143,6 +3149,9 @@ void Zypper::doCommand()
 
     bool install_not_remove = command() == ZypperCommand::INSTALL;
 
+    // parse the download options to check for errors
+    get_download_option(*this);
+
     initRepoManager();
 
     // check for rpm files among the arguments
@@ -3324,6 +3333,9 @@ void Zypper::doCommand()
     if (copts.count("no-confirm"))
       _gopts.non_interactive = true;
 
+    // parse the download options to check for errors
+    get_download_option(*this);
+
     initRepoManager();
 
     init_repos(*this);
@@ -3780,6 +3792,9 @@ void Zypper::doCommand()
         Out::HIGH);
     }
 
+    // parse the download options to check for errors
+    get_download_option(*this);
+
     init_target(*this);
     initRepoManager();
 
@@ -3828,6 +3843,9 @@ void Zypper::doCommand()
       return;
     }
 
+    // parse the download options to check for errors
+    get_download_option(*this);
+
     initRepoManager();
 
     if (!copts.count("repo") && !copts.count("from")
index 37a79c9..fd9fab9 100755 (executable)
@@ -398,11 +398,8 @@ ZYppCommitPolicy get_commit_policy(Zypper & zypper)
   if (zypper.cOpts().count("dry-run"))
     policy.dryRun(true);
 
-  if (zypper.cOpts().count("download-only"))
-    policy.downloadMode(DownloadOnly);
-  //! \todo make this configurable
-  //else
-  //  policy.downloadMode(DownloadInAdvance);
+  if (zypper.cOpts().count("download-only") || zypper.cOpts().count("download"))
+    policy.downloadMode(get_download_option(zypper));
 
   policy.syncPoolAfterCommit(policy.dryRun() ? false : zypper.runningShell());
 
index d0f278c..e40b742 100644 (file)
@@ -478,3 +478,31 @@ void list_processes_using_deleted_files(Zypper & zypper)
         "man zypper"));
   }
 }
+
+DownloadMode get_download_option(Zypper & zypper)
+{
+  if (!zypper.cOpts().count("download") &&
+      !zypper.cOpts().count("download-only"))
+    return DownloadDefault; //! \todo FIXME return ZConfig value
+
+  string download;
+  parsed_opts::const_iterator it = zypper.cOpts().find("download");
+  if (it != zypper.cOpts().end())
+    download = it->second.front();
+  if (zypper.cOpts().count("download-only") || download == "only")
+    return DownloadOnly;
+  else if (download == "in-advance")
+    return DownloadInAdvance;
+  else if (download == "in-heaps")
+    return DownloadInHeaps;
+  else if (download == "as-needed")
+    return DownloadAsNeeded;
+  else
+  {
+    zypper.out().error(str::form(_("Unknown download mode '%s'."), download.c_str()));
+    zypper.out().info(str::form(_("Available download modes: %s"),
+          "only, in-advance, in-heaps, as-needed"));
+    zypper.setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
+    throw ExitRequestException("Unknown download mode");
+  }
+}
index 4291b8c..eaf8860 100644 (file)
@@ -18,6 +18,7 @@
 #include "zypp/Capability.h"
 #include "zypp/ResKind.h"
 #include "zypp/RepoInfo.h"
+#include "zypp/ZYppCommitPolicy.h"
 
 class Zypper;
 
@@ -129,4 +130,6 @@ std::string asXML(const zypp::Pattern & p, bool is_installed);
  */
 void list_processes_using_deleted_files(Zypper & zypper);
 
+zypp::DownloadMode get_download_option(Zypper & zypper);
+
 #endif /*ZYPPER_UTILS_H*/