From: Duncan Mac-Vicar P Date: Fri, 6 Oct 2006 09:30:16 +0000 (+0000) Subject: Introduce a method to see if a source supports a X-Git-Tag: BASE-SuSE-SLE-10-SP2-Branch~311 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=042aa5a5ef6a2f6831d1c26d0fe1a18c7524e3eb;p=platform%2Fupstream%2Flibzypp.git Introduce a method to see if a source supports a kind of resolvable at that time, so we can init a YUM source like factory but avoid parsing it if it contains no patches. --- diff --git a/zypp/Source.cc b/zypp/Source.cc index 1a70d94..dd43685 100644 --- a/zypp/Source.cc +++ b/zypp/Source.cc @@ -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 Source_Ref::resolvableKinds() const + { return _pimpl->resolvableKinds(); } + /****************************************************************** ** ** FUNCTION NAME : operator<< diff --git a/zypp/Source.h b/zypp/Source.h index 253d10d..f55158c 100644 --- a/zypp/Source.h +++ b/zypp/Source.h @@ -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 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) diff --git a/zypp/source/SourceImpl.cc b/zypp/source/SourceImpl.cc index 6393efd..992ff4a 100644 --- a/zypp/source/SourceImpl.cc +++ b/zypp/source/SourceImpl.cc @@ -214,6 +214,11 @@ namespace zypp return _store; } + std::set SourceImpl::resolvableKinds() const + { + return std::set(); + } + const ResStore SourceImpl::resolvables(zypp::Resolvable::Kind kind) const { Source_Ref self( const_cast(this)->selfSourceRef() ); diff --git a/zypp/source/SourceImpl.h b/zypp/source/SourceImpl.h index 26def71..2cfd794 100644 --- a/zypp/source/SourceImpl.h +++ b/zypp/source/SourceImpl.h @@ -282,6 +282,8 @@ namespace zypp */ virtual media::MediaVerifierRef verifier(unsigned media_nr); + virtual std::set resolvableKinds() const; + /** Provide Source_Ref back to \c this. */ Source_Ref selfSourceRef() { return Source_Ref( this ); } diff --git a/zypp/source/susetags/SuseTagsImpl.cc b/zypp/source/susetags/SuseTagsImpl.cc index 39fb804..c3a14c1 100644 --- a/zypp/source/susetags/SuseTagsImpl.cc +++ b/zypp/source/susetags/SuseTagsImpl.cc @@ -136,6 +136,25 @@ namespace zypp return _media_descr_dir; } + std::set + SuseTagsImpl::resolvableKinds() const + { + std::set kinds; + + kinds.insert( ResTraits::kind ); + + if ( PathInfo(descrDir() + "patterns").isExist() ) + kinds.insert( ResTraits::kind ); + + if ( PathInfo(descrDir() + "selections").isExist() ) + kinds.insert( ResTraits::kind ); + + if ( PathInfo(descrDir() + "packages").isExist() ) + kinds.insert( ResTraits::kind ); + + return kinds; + } + bool SuseTagsImpl::downloadNeeded(const Pathname & localdir) { Pathname new_media_file; diff --git a/zypp/source/susetags/SuseTagsImpl.h b/zypp/source/susetags/SuseTagsImpl.h index 453099d..84d42cc 100644 --- a/zypp/source/susetags/SuseTagsImpl.h +++ b/zypp/source/susetags/SuseTagsImpl.h @@ -103,7 +103,7 @@ namespace zypp Pathname sourceDir( const std::string & dir ); virtual void storeMetadata(const Pathname & cache_dir_r); - + virtual std::set resolvableKinds() const; /** * Get media verifier for the specified media */ diff --git a/zypp/source/yum/YUMSourceImpl.cc b/zypp/source/yum/YUMSourceImpl.cc index b16fecc..b17f7d1 100644 --- a/zypp/source/yum/YUMSourceImpl.cc +++ b/zypp/source/yum/YUMSourceImpl.cc @@ -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 report; YUMSourceEventHandler npp(report); @@ -448,6 +417,29 @@ void YUMSourceImpl::readRepomd() } } +std::set +YUMSourceImpl::resolvableKinds() const +{ + std::set kinds; + + if (_repo_product.size() > 0 ) + kinds.insert( ResTraits::kind ); + + if (_repo_pattern.size() > 0 ) + kinds.insert( ResTraits::kind ); + + if (_repo_group.size() > 0 ) + kinds.insert( ResTraits::kind ); + + if (_repo_primary.size() > 0 ) + kinds.insert( ResTraits::kind ); + + if (_repo_patches.size() > 0 ) + kinds.insert( ResTraits::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::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); diff --git a/zypp/source/yum/YUMSourceImpl.h b/zypp/source/yum/YUMSourceImpl.h index 7469671..b8206f9 100644 --- a/zypp/source/yum/YUMSourceImpl.h +++ b/zypp/source/yum/YUMSourceImpl.h @@ -80,6 +80,8 @@ public: virtual Date timestamp() const; virtual void storeMetadata(const Pathname & cache_dir_r); + virtual std::set resolvableKinds() const; + virtual std::string type(void) const { return typeString();