#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"
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 )
* 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;
};
////////////////////////////////////////////////////////////////////////////
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 );
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;
};
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 ) );
}
{
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
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