- skip repositories with non-matching target distro when reading repoindex
authorJan Kupec <jkupec@suse.cz>
Wed, 3 Sep 2008 12:52:00 +0000 (12:52 +0000)
committerJan Kupec <jkupec@suse.cz>
Wed, 3 Sep 2008 12:52:00 +0000 (12:52 +0000)
zypp/parser/RepoindexFileReader.cc

index a32a58c..e5cdad7 100644 (file)
 #include "zypp/base/String.h"
 #include "zypp/base/Logger.h"
 #include "zypp/base/Gettext.h"
-
-#include "zypp/RepoInfo.h"
-
 #include "zypp/Pathname.h"
+
 #include "zypp/parser/xml/Reader.h"
 #include "zypp/parser/ParseException.h"
 
+#include "zypp/RepoInfo.h"
+#include "zypp/Target.h"
+#include "zypp/ZYppFactory.h"
+
 #include "zypp/parser/RepoindexFileReader.h"
 
 
@@ -59,15 +61,18 @@ namespace zypp
   private:
     /** Function for processing collected data. Passed-in through constructor. */
     ProcessResource _callback;
+    string _target_distro;
   };
   ///////////////////////////////////////////////////////////////////////
 
   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 ) );
   }
 
@@ -98,6 +103,19 @@ namespace zypp
       if ( reader_r->name() == "repo" )
       {
         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