- filtering of repos with non-matching repos moved to RepoManager
authorJan Kupec <jkupec@suse.cz>
Wed, 3 Sep 2008 16:23:05 +0000 (16:23 +0000)
committerJan Kupec <jkupec@suse.cz>
Wed, 3 Sep 2008 16:23:05 +0000 (16:23 +0000)
- desired targetDistribution can be set explicitly via RepoManagerOptions

zypp/RepoManager.cc
zypp/RepoManager.h
zypp/parser/RepoindexFileReader.cc

index c179335..c8c0d6a 100644 (file)
@@ -41,6 +41,9 @@
 #include "zypp/repo/susetags/Downloader.h"
 #include "zypp/parser/plaindir/RepoParser.h"
 
+#include "zypp/Target.h" // for Target::targetDistribution() for repo index services
+#include "zypp/ZYppFactory.h" // to get the Target from ZYpp instance
+
 #include "zypp/ZYppCallbacks.h"
 
 #include "sat/Pool.h"
@@ -74,6 +77,14 @@ namespace zypp
     knownReposPath        = Pathname::assertprefix( root_r, ZConfig::instance().knownReposPath() );
     knownServicesPath     = Pathname::assertprefix( root_r, ZConfig::instance().knownServicesPath() );
     probe                 = ZConfig::instance().repo_add_probe();
+    try
+    {
+      servicesTargetDistro = getZYpp()->target()->targetDistribution();
+    }
+    catch (const Exception & e)
+    {
+      DBG << "Target not initialized, using an empty servicesTargetDistro." << endl;
+    }
   }
 
   RepoManagerOptions RepoManagerOptions::makeTestSetup( const Pathname & root_r )
@@ -97,24 +108,46 @@ namespace zypp
     * once per each repo in a file.
     *
     * Passing this functor as callback, you can collect
-    * all resuls at the end, without dealing with async
+    * all results at the end, without dealing with async
     * code.
+    * 
+    * If targetDistro is set, all repos with non-empty RepoInfo::targetDistribution()
+    * will be skipped.
+    * \todo do this through a separate filter
     */
     struct RepoCollector
     {
       RepoCollector()
       {}
+      
+      RepoCollector(const string & targetDistro_)
+        : targetDistro(targetDistro_)
+      {}
 
       ~RepoCollector()
       {}
 
       bool collect( const RepoInfo &repo )
       {
+        // skip repositories meant for other distros than specified
+        if (!targetDistro.empty()
+            && !repo.targetDistribution().empty()
+            && repo.targetDistribution() != targetDistro)
+        {
+          MIL
+            << "Skipping repository meant for '" << targetDistro
+            << "' distribution (current distro is '"
+            << repo.targetDistribution() << "')." << endl;
+
+          return true;
+        }
+
         repos.push_back(repo);
         return true;
       }
 
       RepoInfoList repos;
+      string targetDistro;
     };
 
   ////////////////////////////////////////////////////////////////////////////
@@ -1457,8 +1490,8 @@ namespace zypp
     mediamanager.provideFile( mid, "repo/repoindex.xml" );
     Pathname path = mediamanager.localPath(mid, "repo/repoindex.xml" );
 
-    //parse it
-    RepoCollector collector;
+    // parse it
+    RepoCollector collector(_pimpl->options.servicesTargetDistro);
     parser::RepoindexFileReader reader( path,
       bind( &RepoCollector::collect, &collector, _1 ) );
     mediamanager.release( mid );
index e21c79d..b841f25 100644 (file)
@@ -81,6 +81,17 @@ namespace zypp
     Pathname knownReposPath;
     Pathname knownServicesPath;
     bool probe;
+    /**
+     * Target distro ID to be used when refreshing repo index services.
+     * Repositories not maching this ID will be skipped/removed.
+     *
+     * The value is initialized upon construction to
+     * \ref Target::targetDistribution() if the Target is already initialized,
+     * otherwise the value is initially empty.
+     *
+     * If empty, no repositories contained in the index will be skipped.
+     */
+    std::string servicesTargetDistro;
   };
 
 
index e5cdad7..d1cdf49 100644 (file)
@@ -68,11 +68,9 @@ namespace zypp
   RepoindexFileReader::Impl::Impl(
       const Pathname &repoindex_file, const ProcessResource & callback)
     : _callback(callback)
-    , _target_distro(getZYpp()->target()->targetDistribution())
   {
     Reader reader( repoindex_file );
     MIL << "Reading " << repoindex_file << endl;
-    MIL << "Target distro: '" << _target_distro << "'" << endl;
     reader.foreachNode( bind( &RepoindexFileReader::Impl::consumeNode, this, _1 ) );
   }
 
@@ -104,18 +102,6 @@ namespace zypp
       {
         XmlString s;
 
-        // skip repositories with unknown or not matching target distribution
-        s = reader_r->getAttribute("distro_target");
-        if (!s.get() || _target_distro != s.asString())
-        {
-          MIL
-            << "Skipping repository meant for '"
-            << (s.get() ? s.asString() : "(not specified)")
-            << "' distribution (current distro is '" << _target_distro << "')."
-            << endl;
-          return true;
-        }
-
         RepoInfo info;
 
         // url and/or path
@@ -151,6 +137,11 @@ namespace zypp
         if (s.get())
           info.setName(s.asString());
 
+        // optional targetDistro
+        s = reader_r->getAttribute("distro_target");
+        if (s.get())
+          info.setTargetDistribution(s.asString());
+
         DBG << info << endl;
 
         // ignore the rest