Introduce a method to see if a source supports a
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 6 Oct 2006 09:30:16 +0000 (09:30 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 6 Oct 2006 09:30:16 +0000 (09:30 +0000)
kind of resolvable at that time, so we can
init a YUM source like factory but avoid parsing
it if it contains no patches.

zypp/Source.cc
zypp/Source.h
zypp/source/SourceImpl.cc
zypp/source/SourceImpl.h
zypp/source/susetags/SuseTagsImpl.cc
zypp/source/susetags/SuseTagsImpl.h
zypp/source/yum/YUMSourceImpl.cc
zypp/source/yum/YUMSourceImpl.h

index 1a70d94..dd43685 100644 (file)
@@ -200,6 +200,12 @@ namespace zypp
   std::string Source_Ref::unique_id (void) const
   { return _pimpl->unique_id(); }
 
+  bool Source_Ref::hasResolvablesOfKind( const zypp::Resolvable::Kind &kind ) const
+  { return _pimpl->resolvableKinds().count(kind) != 0; }
+  
+  std::set<zypp::Resolvable::Kind> Source_Ref::resolvableKinds() const
+  { return _pimpl->resolvableKinds(); }
+  
   /******************************************************************
    **
    **  FUNCTION NAME : operator<<
index 253d10d..f55158c 100644 (file)
@@ -157,6 +157,17 @@ namespace zypp
      */
     Date timestamp() const;
     
+    /**
+     * wether this source provides or supports resolvables
+     * of certain kind.
+     */
+    bool hasResolvablesOfKind( const zypp::Resolvable::Kind &kind ) const;
+    
+    /**
+     * set of resolvable types the source can offer at this moment
+     */
+    std::set<zypp::Resolvable::Kind> resolvableKinds() const;
+    
     /** Whether the ResStore is initialized.
      * If we know that noone has seen the resolvables yet, we can skip
      * them too, eg. when deleting a source. (#174840)
index 6393efd..992ff4a 100644 (file)
@@ -214,6 +214,11 @@ namespace zypp
       return _store;
      }
 
+     std::set<zypp::Resolvable::Kind> SourceImpl::resolvableKinds() const
+     {
+       return std::set<zypp::Resolvable::Kind>();
+     }
+     
     const ResStore SourceImpl::resolvables(zypp::Resolvable::Kind kind) const
     {
       Source_Ref self( const_cast<SourceImpl*>(this)->selfSourceRef() );
index 26def71..2cfd794 100644 (file)
@@ -282,6 +282,8 @@ namespace zypp
        */
       virtual media::MediaVerifierRef verifier(unsigned media_nr);
 
+      virtual std::set<zypp::Resolvable::Kind> resolvableKinds() const;
+      
       /** Provide Source_Ref back to \c this. */
       Source_Ref selfSourceRef()
       { return Source_Ref( this ); }
index 39fb804..c3a14c1 100644 (file)
@@ -136,6 +136,25 @@ namespace zypp
         return _media_descr_dir;
       }
 
+      std::set<zypp::Resolvable::Kind>
+      SuseTagsImpl::resolvableKinds() const
+      {
+        std::set<zypp::Resolvable::Kind> kinds;
+        
+        kinds.insert( ResTraits<zypp::Product>::kind );
+        
+        if ( PathInfo(descrDir() + "patterns").isExist() )
+          kinds.insert( ResTraits<zypp::Pattern>::kind );
+        
+        if ( PathInfo(descrDir() + "selections").isExist() )
+          kinds.insert( ResTraits<zypp::Selection>::kind );
+        
+        if ( PathInfo(descrDir() + "packages").isExist() )
+          kinds.insert( ResTraits<zypp::Package>::kind );
+        
+        return kinds;
+      }
+      
       bool SuseTagsImpl::downloadNeeded(const Pathname & localdir)
       {
         Pathname new_media_file;
index 453099d..84d42cc 100644 (file)
@@ -103,7 +103,7 @@ namespace zypp
 
         Pathname sourceDir( const std::string & dir );
         virtual void storeMetadata(const Pathname & cache_dir_r);
-
+        virtual std::set<zypp::Resolvable::Kind> resolvableKinds() const;
         /**
          * Get media verifier for the specified media
          */
index b16fecc..b17f7d1 100644 (file)
@@ -260,6 +260,8 @@ void YUMSourceImpl::factoryInit()
     DBG << "Cached metadata found in [" << _cache_dir << "]." << endl;
     if ( autorefresh() )
       storeMetadata(_cache_dir);
+    else
+      readRepomd();
   }
   else
   {
@@ -275,6 +277,7 @@ void YUMSourceImpl::factoryInit()
       DBG << "Cached metadata not found in [" << _cache_dir << "]. Will download." << std::endl;
       saveMetadataTo(_cache_dir);
     }
+    readRepomd();
   }
 
   MIL << "YUM source initialized." << std::endl;
@@ -283,49 +286,6 @@ void YUMSourceImpl::factoryInit()
   MIL << "   Metadata : " << metadataRoot() << (_cache_dir.empty() ? " [TMP]" : " [CACHE]") << std::endl;
 }
 
-/*
-void YUMSourceImpl::checkMetadataChecksums() const
-{
-  DBG << "Reading file " << repomdFile() << " to check integrity of metadata." << endl;
-  ifstream repo_st(repomdFile().asString().c_str());
-  YUMRepomdParser repomd(repo_st, "");
-
-  for(; ! repomd.atEnd(); ++repomd)
-  {
-    if ((*repomd)->type == "other")
-    {             // dont parse other.xml (#159316)
-      continue;
-    }
-    else
-    {
-      Pathname file_to_check = metadataRoot() + _path + (*repomd)->location;
-      if (! filesystem::is_checksum( file_to_check, CheckSum((*repomd)->checksumType, (*repomd)->checksum)))
-      {
-        ZYPP_THROW(Exception( (*repomd)->location + " " + N_("fails checksum verification.") ));
-      }
-
-      // now parse patches mentioned if we are in patches.xml
-
-      if ((*repomd)->type == "patches")
-      {
-        Pathname patch_index = file_to_check;
-        DBG << "reading patches from file " << patch_index << endl;
-        ifgzstream st ( patch_index.asString().c_str() );
-        YUMPatchesParser patch(st, "");
-        for (; !patch.atEnd(); ++patch)
-        {
-          Pathname patch_filename = metadataRoot() + _path + (*patch)->location;
-          if (! filesystem::is_checksum(patch_filename, CheckSum((*patch)->checksumType, (*patch)->checksum)))
-          {
-            ZYPP_THROW(Exception( (*patch)->location + " " + N_("fails checksum verification.") ));
-          }
-        }
-      }
-    }
-  }
-}
-*/
-
 bool YUMSourceImpl::downloadNeeded(const Pathname & localdir)
 {
   // we can only assume repomd intact means the source changed if the source is signed.
@@ -365,6 +325,8 @@ void YUMSourceImpl::storeMetadata(const Pathname & cache_dir_r)
 
   MIL << "Metadata saved in " << cache_dir_r << ". Setting as cache." << std::endl;
   _cache_dir = cache_dir_r;
+  readRepomd();
 }
 
 void YUMSourceImpl::saveMetadataTo(const Pathname & dir_r)
@@ -408,6 +370,13 @@ void YUMSourceImpl::saveMetadataTo(const Pathname & dir_r)
 
 void YUMSourceImpl::readRepomd()
 {
+  _repo_primary.clear();
+  _repo_files.clear();
+  _repo_group.clear();
+  _repo_pattern.clear();
+  _repo_product.clear();
+  _repo_patches.clear();
+  
   parser::ParserProgress::Ptr progress;
   callback::SendReport<SourceReport> report;
   YUMSourceEventHandler npp(report);
@@ -448,6 +417,29 @@ void YUMSourceImpl::readRepomd()
   }
 }
 
+std::set<zypp::Resolvable::Kind>
+YUMSourceImpl::resolvableKinds() const
+{
+  std::set<zypp::Resolvable::Kind> kinds;
+  
+  if (_repo_product.size() > 0 )
+    kinds.insert( ResTraits<zypp::Product>::kind ); 
+  
+  if (_repo_pattern.size() > 0 )
+    kinds.insert( ResTraits<zypp::Pattern>::kind );
+  
+  if (_repo_group.size() > 0 )
+    kinds.insert( ResTraits<zypp::Selection>::kind );
+  
+  if (_repo_primary.size() > 0 )
+  kinds.insert( ResTraits<zypp::Package>::kind );
+  
+  if (_repo_patches.size() > 0 )
+    kinds.insert( ResTraits<zypp::Patch>::kind );
+  
+  return kinds;
+}
+
 void YUMSourceImpl::provideProducts(Source_Ref source_r, ResStore& store)
 {
   Pathname filename;
@@ -810,7 +802,7 @@ ResStore YUMSourceImpl::provideResolvablesByKind(Source_Ref source_r, zypp::Reso
 {
   ResStore store;
 
-  readRepomd();
+  //readRepomd();
 
   if ( kind == ResTraits<Product>::kind )
     provideProducts ( selfSourceRef(), store );
@@ -829,7 +821,7 @@ ResStore YUMSourceImpl::provideResolvablesByKind(Source_Ref source_r, zypp::Reso
 void YUMSourceImpl::createResolvables(Source_Ref source_r)
 {
 
-  readRepomd();
+  //readRepomd();
   provideProducts(selfSourceRef(), _store);
   providePackages(selfSourceRef(), _store);
   provideSelections(selfSourceRef(), _store);
index 7469671..b8206f9 100644 (file)
@@ -80,6 +80,8 @@ public:
   virtual Date timestamp() const;
   virtual void storeMetadata(const Pathname & cache_dir_r);
 
+  virtual std::set<zypp::Resolvable::Kind> resolvableKinds() const;
+  
   virtual std::string type(void) const
   {
     return typeString();