use the type as specified by the persistent store
authorStanislav Visnovsky <visnov@suse.cz>
Wed, 5 Apr 2006 10:51:12 +0000 (10:51 +0000)
committerStanislav Visnovsky <visnov@suse.cz>
Wed, 5 Apr 2006 10:51:12 +0000 (10:51 +0000)
when restoring (#162111)

package/libzypp.changes
zypp/SourceFactory.cc
zypp/SourceFactory.h
zypp/SourceManager.cc
zypp/source/susetags/SuseTagsImpl.h
zypp/source/yum/YUMSourceImpl.h

index aa0e4de..c0e5f44 100644 (file)
@@ -1,4 +1,10 @@
 -------------------------------------------------------------------
+Wed Apr  5 12:48:19 CEST 2006 - visnov@suse.cz
+
+- only try to create a source of a given type when restoring 
+  from the persistent store (#162111) 
+
+-------------------------------------------------------------------
 Wed Apr  5 11:36:54 CEST 2006 - kkaempf@suse.de
 
 - parse all dependencies for patterns (.pat) files (#160602)
index ec88cd1..3265104 100644 (file)
@@ -175,6 +175,67 @@ media::MediaManager media_mgr;
     return Source_Ref(); // not reached!!
   }
 
+  Source_Ref SourceFactory::createFrom( const std::string & type, const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r )
+  {
+    if (! url_r.isValid())
+      ZYPP_THROW( Exception("Empty URL passed to SourceFactory") );
+
+    callback::SendReport<CreateSourceReport> report;
+
+    report->startProbe (url_r);
+    
+#warning if cache_dir is provided, no need to open the original url
+    // open the media
+    media::MediaId id = media_mgr.open(url_r);
+
+    // add dummy verifier
+    media_mgr.addVerifier(id, media::MediaVerifierRef(new media::NoVerifier()));
+    // attach only if initializing from media and not from cache (#153073)
+    if (cache_dir_r == "")
+    {
+      media_mgr.attach(id);
+    }
+    else
+    {
+      MIL << "Initializing from cache" << endl;
+    }
+
+    try
+    {
+
+      Source_Ref::Impl_Ptr impl;
+
+      if( type == yum::YUMSourceImpl::typeString() ) {
+        MIL << "Trying the YUM source" << endl;
+        impl = Source_Ref::Impl_Ptr( Impl::createSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r) );
+        MIL << "Found the YUM source" << endl;
+      } else if ( type == susetags::SuseTagsImpl::typeString() ) {
+        MIL << "Trying the SUSE tags source" << endl;
+#warning TODO pass cache_dir_r once constructor adapted
+        impl = Source_Ref::Impl_Ptr( Impl::createSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r) );
+        MIL << "Found the SUSE tags source" << endl;
+      } else {
+       ZYPP_THROW( Exception ("Cannot create source of unknown type '" + type + "'"));
+      }
+
+      report->endProbe (url_r);
+      
+      return Source_Ref(impl);
+    }
+    catch (const Exception & excpt_r)
+    {
+      ZYPP_CAUGHT(excpt_r);
+      MIL << "Creating a source of type " << type << " failed " << endl;
+    }
+    
+    report->endProbe (url_r);
+
+    ERR << "No next type of source" << endl;
+    ZYPP_THROW(Exception("Cannot create the installation source"));
+    return Source_Ref(); // not reached!!
+  }
+
+
   /******************************************************************
   **
   **   FUNCTION NAME : operator<<
index d87f50b..e70e5a6 100644 (file)
@@ -55,6 +55,11 @@ namespace zypp
     */
     Source_Ref createFrom( const Url & url_r, const Pathname & path_r = "/", const std::string & alias_r = "", const Pathname & cache_dir_r = "" );
 
+    /** Construct source of a given type.
+     * \throw EXCEPTION on fail
+    */
+    Source_Ref createFrom( const std::string & type,  const Url & url_r, const Pathname & path_r = "/", const std::string & alias_r = "", const Pathname & cache_dir_r = "" );
+
   private:
     /** Implementation  */
     class Impl;
index 16e29cd..5a75c46 100644 (file)
@@ -373,7 +373,7 @@ namespace zypp
        SourceId id = 0;
 
        try {
-          id = addSource( SourceFactory().createFrom(it->url, it->product_dir, it->alias, it->cache_dir) );
+          id = addSource( SourceFactory().createFrom(it->type, it->url, it->product_dir, it->alias, it->cache_dir) );
        }
        catch (const Exception &expt )
        {
index 789bc44..f8e8a2c 100644 (file)
@@ -56,7 +56,14 @@ namespace zypp
         virtual ResStore provideResolvables(Source_Ref source_r, zypp::Resolvable::Kind kind);
        
         virtual std::string type(void) const
-        { return "YaST"; }
+        { return typeString(); }
+
+        /** Text used for identifying the type of the source.
+         * Used by the \ref SourceFactory when creating a
+         * source of a given type only.
+         */
+       static std::string typeString(void)
+       { return "YaST"; }
        
         virtual unsigned numberOfMedia(void) const;
         virtual std::string vendor (void) const;
index b584c7f..f3ac4c7 100644 (file)
@@ -56,6 +56,13 @@ namespace zypp
         virtual void storeMetadata(const Pathname & cache_dir_r);
        
        virtual std::string type(void) const
+       { return typeString(); }
+
+       /** Text used for identifying the type of the source.
+        * Used by the \ref SourceFactory when creating a 
+        * source of a given type only.
+        */
+       static std::string typeString(void)
        { return "YUM"; }
 
        virtual void createResolvables(Source_Ref source_r);