throw exception with details about sources that cannot be restored
authorStanislav Visnovsky <visnov@suse.cz>
Thu, 2 Mar 2006 15:32:04 +0000 (15:32 +0000)
committerStanislav Visnovsky <visnov@suse.cz>
Thu, 2 Mar 2006 15:32:04 +0000 (15:32 +0000)
zypp/SourceManager.cc
zypp/SourceManager.h

index b540571..9ab2fdc 100644 (file)
@@ -11,6 +11,7 @@
 */
 #include <iostream>
 #include "zypp/base/Logger.h"
+#include "zypp/base/Gettext.h"
 
 #include "zypp/ZYpp.h"
 #include "zypp/ZYppFactory.h"
@@ -253,10 +254,10 @@ namespace zypp
   bool SourceManager::restore(Pathname root_r, bool use_caches )
   {
     if (! _sources.empty() )
-       ZYPP_THROW(Exception ("At least one source already registered, cannot restore sources from persistent store.") );
+       ZYPP_THROW(Exception ( N_("At least one source already registered, cannot restore sources from persistent store.") ) );
+
+    FailedSourcesRestoreException report;
 
-    bool error = false;
-        
     storage::PersistentStorage store;    
     store.init( root_r );
     
@@ -274,9 +275,9 @@ namespace zypp
        try {
            id = addSource(it->url, it->product_dir, it->alias, it->cache_dir);
        }
-       catch ( const Exception & expt ){
+       catch ( Exception expt ){
            ERR << "Unable to restore source from " << it->url << endl;
-           error = true;
+           report.append( it->url + it->product_dir, expt );
            continue;
        }
        
@@ -291,7 +292,10 @@ namespace zypp
        src.setAutorefresh ( it->autorefresh );
     }
     
-    return !error;
+    if( !report.empty() ) 
+    {
+       ZYPP_THROW(report);
+    }
   }
 
   /******************************************************************
@@ -332,6 +336,27 @@ namespace zypp
     return *(it->second); // just to keep gcc happy
   }
 
+  std::ostream & FailedSourcesRestoreException::dumpOn( std::ostream & str ) const
+  {
+       return str << _summary;
+  }
+
+  std::ostream & FailedSourcesRestoreException::dumpOnTranslated( std::ostream & str ) const
+  {
+       return str << Exception::asTranslatedString() << endl << _translatedSummary;
+  }
+
+  bool FailedSourcesRestoreException::empty () const
+  {
+       return _summary.empty();
+  }
+
+  void FailedSourcesRestoreException::append( std::string source, const Exception& expt) 
+  {
+       _summary = _summary + "\n" + source + ": " + expt.asString();
+       _translatedSummary = _translatedSummary + "\n" + source + ": " + expt.asTranslatedString();
+
+  }
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
index ccde1b8..239dab8 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "zypp/base/ReferenceCounted.h"
 #include "zypp/base/NonCopyable.h"
+#include "zypp/base/Gettext.h"
 
 #include "zypp/Source.h"
 #include "zypp/Url.h"
@@ -29,6 +30,26 @@ namespace zypp
 
   DEFINE_PTR_TYPE(SourceManager)
 
+  class FailedSourcesRestoreException : public Exception 
+  {
+    public:
+      FailedSourcesRestoreException()
+      : Exception(N_("Unable to restore all sources."))
+      , _summary()
+      , _translatedSummary()
+      {}
+      virtual ~FailedSourcesRestoreException() throw() {};
+
+      void append( std::string source, const Exception& problem );
+      bool empty() const;
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+      virtual std::ostream & dumpOnTranslated( std::ostream & str ) const;
+    private:
+      std::string _summary;
+      std::string _translatedSummary;
+  };
+
   ///////////////////////////////////////////////////////////////////
   //
   //   CLASS NAME : SourceManager