- suppressing excessive output of media errors
authorJan Kupec <jkupec@suse.cz>
Thu, 30 Aug 2007 18:32:13 +0000 (18:32 +0000)
committerJan Kupec <jkupec@suse.cz>
Thu, 30 Aug 2007 18:32:13 +0000 (18:32 +0000)
- prompting for media change only for changeable media
- adapted to libzypp 3.21.0 (#294481)

src/zypper-media-callbacks.h
src/zypper-sources.cc
src/zypper.h
zypper.spec.cmake

index fab86a7..aa4888a 100644 (file)
 #include <zypp/Digest.h>
 #include <zypp/Url.h>
 
+#include "zypper.h"
 #include "zypper-callbacks.h"
 #include "AliveCursor.h"
+#include "zypper-utils.h"
 
 using zypp::media::MediaChangeReport;
 using zypp::media::DownloadProgressReport;
@@ -36,29 +38,31 @@ namespace ZmartRecipients
 
   struct MediaChangeReportReceiver : public zypp::callback::ReceiveReport<MediaChangeReport>
   {
-    virtual MediaChangeReport::Action requestMedia( Repository repo,
+    virtual MediaChangeReport::Action requestMedia( zypp::Url & url,
                                                     unsigned mediumNr,
                                                     MediaChangeReport::Error error,
                                                     const std::string & description )
     {
-      if (error == MediaChangeReport::WRONG)
+      if (is_changeable_media(url))
       {
+        cerr << endl; // may be in the middle of RepoReport or ProgressReport
+        cerr << description << endl;
+  
         // TranslatorExplanation translate letters 'y' and 'n' to whathever is appropriate for your language.
         // Try to check what answers does zypper accept (it always accepts y/n at least)
         // You can also have a look at the regular expressions used to check the answer here:
         // /usr/lib/locale/<your_locale>/LC_MESSAGES/SYS_LC_MESSAGES
         std::string request = boost::str(boost::format(
             _("Please insert media [%s] # %d and type 'y' to continue or 'n' to cancel the operation."))
-            % repo.info().name() % mediumNr);
+            % gData.current_repo.name() % mediumNr);
         if (read_bool_answer(request, false))
           return MediaChangeReport::RETRY; 
         else
           return MediaChangeReport::ABORT;
       }
-      else
-      {
-        cerr << description << endl;
-      }
+
+      // not displaying the error for non-changeable media, it will be displayed
+      // where it is caught
     }
   };
 
@@ -85,6 +89,7 @@ namespace ZmartRecipients
       return true;
     }
 
+    // not used anywhere in libzypp 3.20.0
     virtual DownloadProgressReport::Action problem( const zypp::Url & /*file*/, DownloadProgressReport::Error error, const std::string & description )
     {
       display_done ("download", cout_v);
@@ -92,10 +97,12 @@ namespace ZmartRecipients
       return DownloadProgressReport::ABORT;
     }
 
+    // used only to finish, errors will be reported in media change callback (libzypp 3.20.0)
     virtual void finish( const zypp::Url & /*file*/, Error error, const std::string & konreason )
     {
       display_done ("download", cout_v);
-      display_error (error, konreason);
+      // don't display errors here, they will be reported in media change callback
+      // display_error (error, konreason);
     }
   };
 
index d64c653..605656a 100644 (file)
@@ -6,7 +6,6 @@
 
 #include <zypp/target/store/PersistentStorage.h>
 #include <zypp/base/IOStream.h>
-#include <zypp/media/MediaManager.h>
 
 #include <zypp/RepoManager.h>
 #include <zypp/RepoInfo.h>
@@ -36,6 +35,11 @@ extern Settings gSettings;
 
 static bool refresh_raw_metadata(const RepoInfo & repo, bool force_download)
 {
+  gData.current_repo = repo;
+
+  // reset the gData.current_repo when going out of scope
+  struct Bye { ~Bye() { gData.current_repo = RepoInfo(); } } reset __attribute__ ((__unused__));
+
   try
   {
     RepoManager manager;
@@ -654,9 +658,7 @@ int add_repo(RepoInfo & repo)
   for(RepoInfo::urls_const_iterator it = repo.baseUrlsBegin();
       it != repo.baseUrlsEnd(); ++it)
   {
-    MediaManager mm; MediaAccessId id = mm.open(*it);
-    is_cd = mm.isChangeable(id);
-    mm.close(id);
+    is_cd = is_changeable_media(*it);
     if (!is_cd)
       break;
   }
@@ -670,6 +672,11 @@ int add_repo(RepoInfo & repo)
 
   try
   {
+    gData.current_repo = repo;
+
+    // reset the gData.current_repo when going out of scope
+    struct Bye { ~Bye() { gData.current_repo = RepoInfo(); } } reset __attribute__ ((__unused__));
+
     manager.addRepository(repo);
   }
   catch (const RepoAlreadyExistsException & e)
@@ -696,7 +703,7 @@ int add_repo(RepoInfo & repo)
     ZYPP_CAUGHT(e);
     report_problem(e,
         _("Problem transferring repository data from specified URL:"),
-        _("Please, check whether the specified URL is accessible."));
+        is_cd ? "" : _("Please, check whether the specified URL is accessible."));
     ERR << "Problem transferring repository data from specified URL" << endl;
     return ZYPPER_EXIT_ERR_ZYPP;
   }
index dab0790..cf5c8f0 100644 (file)
@@ -100,10 +100,11 @@ struct RuntimeData
   std::list<zypp::RepoInfo> repos;
   int patches_count;
   int security_patches_count;
-  std::vector<std::string> packages_to_install; 
+  std::vector<std::string> packages_to_install;
   std::vector<std::string> packages_to_uninstall; 
   zypp::ResStore repo_resolvables;
   zypp::ResStore target_resolvables;
+  zypp::RepoInfo current_repo;
 
   /**
    * Limit output to and above specified verbosity level.
index 84225a7..eaa9a64 100644 (file)
@@ -11,7 +11,7 @@
 # norootforbuild
 
 Name:           @PACKAGE@
-BuildRequires:  libzypp-devel >= 3.19.0 boost-devel >= 1.33.1 gettext-devel >= 0.15 readline-devel >= 5.1
+BuildRequires:  libzypp-devel > 3.20.1 boost-devel >= 1.33.1 gettext-devel >= 0.15 readline-devel >= 5.1
 BuildRequires:  gcc-c++ >= 4.2 cmake >= 2.4.6 pkg-config >= 0.20
 Requires:      procps
 License:        GPL