From 65da2593441ea2dd113eb6b5e4283376813b631b Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Tue, 1 Nov 2016 11:08:24 +0900 Subject: [PATCH] Imported Upstream version 15.21.3 Change-Id: I6b0d7df5fb025644c9173b478717f8172f2c41a9 Signed-off-by: DongHun Kwak --- VERSION.cmake | 4 +- package/libzypp.changes | 7 ++ zypp/parser/yum/RepomdFileReader.cc | 69 ++++++++---------- zypp/parser/yum/RepomdFileReader.h | 43 +++++------- zypp/repo/yum/Downloader.cc | 136 +++++++++++++++++++++++++----------- zypp/repo/yum/Downloader.h | 1 + 6 files changed, 153 insertions(+), 107 deletions(-) diff --git a/VERSION.cmake b/VERSION.cmake index db10918..80dd0c4 100644 --- a/VERSION.cmake +++ b/VERSION.cmake @@ -61,8 +61,8 @@ SET(LIBZYPP_MAJOR "15") SET(LIBZYPP_COMPATMINOR "19") SET(LIBZYPP_MINOR "21") -SET(LIBZYPP_PATCH "2") +SET(LIBZYPP_PATCH "3") # -# LAST RELEASED: 15.21.2 (19) +# LAST RELEASED: 15.21.3 (19) # (The number in parenthesis is LIBZYPP_COMPATMINOR) #======= diff --git a/package/libzypp.changes b/package/libzypp.changes index 439d6b9..0978e35 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -1,4 +1,11 @@ ------------------------------------------------------------------- +Thu Feb 18 18:38:52 CET 2016 - ma@suse.de + +- yum::Downloader: Download only wanted 'susedata.LANG' files + (FATE#320518) +- version 15.21.3 (19) + +------------------------------------------------------------------- Thu Feb 4 16:38:14 CET 2016 - ma@suse.de - installSrcPackage: trigger progress callback (bsc#580902) diff --git a/zypp/parser/yum/RepomdFileReader.cc b/zypp/parser/yum/RepomdFileReader.cc index 6163a78..99908b0 100644 --- a/zypp/parser/yum/RepomdFileReader.cc +++ b/zypp/parser/yum/RepomdFileReader.cc @@ -60,12 +60,20 @@ namespace zypp }; public: - /** - * CTOR - * - * \see RepomdFileReader::RepomdFileReader(Pathname,ProcessResource) - */ - Impl(const Pathname &repomd_file, const ProcessResource & callback); + /** Ctro taking a ProcessResource2 callback */ + Impl(const Pathname &repomd_file, const ProcessResource2 & callback ) + : _tag( tag_NONE ) + , _type( ResourceType::NONE_e ) + , _callback( callback ) + { + Reader reader( repomd_file ); + MIL << "Reading " << repomd_file << endl; + reader.foreachNode( bind( &RepomdFileReader::Impl::consumeNode, this, _1 ) ); + } + /** \overload Redirect an old ProcessResource callback */ + Impl(const Pathname &repomd_file, const ProcessResource & callback) + : Impl( repomd_file, ProcessResource2( bind( callback, _1, _2 ) ) ) + {} /** * Callback provided to the XML parser. @@ -74,41 +82,23 @@ namespace zypp private: - /** Location of metadata file. */ - OnMediaLocation _location; + /** Function for processing collected data. Passed-in through constructor. */ + ProcessResource2 _callback; /** Used to remember currently processed tag */ Tag _tag; - /** Type of metadata file. */ - repo::yum::ResourceType _type; - - /** Function for processing collected data. Passed-in through constructor. */ - ProcessResource _callback; - - /** Checksum of metadata file */ - CheckSum _checksum; + /** Type of metadata file (string) */ + std::string _typeStr; - /** Type of checksum of metadata file */ - std::string _checksum_type; + /** Type of metadata file as enum of well known repoinded.xml entries. */ + repo::yum::ResourceType _type; - /** Metadata file time-stamp. */ - Date _timestamp; + /** Location of metadata file. */ + OnMediaLocation _location; }; /////////////////////////////////////////////////////////////////////// - RepomdFileReader::Impl::Impl( - const Pathname &repomd_file, const ProcessResource & callback) - : - _tag(tag_NONE), _type(ResourceType::NONE_e), _callback(callback) - { - Reader reader( repomd_file ); - MIL << "Reading " << repomd_file << endl; - reader.foreachNode( bind( &RepomdFileReader::Impl::consumeNode, this, _1 ) ); - } - - // -------------------------------------------------------------------------- - /* * xpath and multiplicity of processed nodes are included in the code * for convenience: @@ -135,7 +125,8 @@ namespace zypp if ( reader_r->name() == "data" ) { _tag = tag_Data; - _type = ResourceType(reader_r->getAttribute("type").asString()); + _typeStr = reader_r->getAttribute("type").asString(); + _type = ResourceType(_typeStr); return true; } @@ -174,7 +165,7 @@ namespace zypp if ( reader_r->name() == "data" ) { if (_callback) - _callback( _location, _type ); + _callback( _location, _type, _typeStr ); return true; } @@ -190,10 +181,12 @@ namespace zypp // /////////////////////////////////////////////////////////////////// - RepomdFileReader::RepomdFileReader( - const Pathname & repomd_file, const ProcessResource & callback) - : - _pimpl(new Impl(repomd_file, callback)) + RepomdFileReader::RepomdFileReader( const Pathname & repomd_file, const ProcessResource & callback ) + : _pimpl( new Impl(repomd_file, callback) ) + {} + + RepomdFileReader::RepomdFileReader( const Pathname & repomd_file, const ProcessResource2 & callback ) + : _pimpl( new Impl(repomd_file, callback) ) {} RepomdFileReader::~RepomdFileReader() diff --git a/zypp/parser/yum/RepomdFileReader.h b/zypp/parser/yum/RepomdFileReader.h index dd193ea..be10c0e 100644 --- a/zypp/parser/yum/RepomdFileReader.h +++ b/zypp/parser/yum/RepomdFileReader.h @@ -31,12 +31,12 @@ namespace zypp * Reads through a repomd.xml file and collects type, location, checksum and * other data about metadata files to be processed. * - * After each package is read, a \ref OnMediaLocation - * and \ref repo::yum::ResourceType is prepared and \ref _callback - * is called with these two objects passed in. - * - * The \ref _callback is provided on construction. + * After each file entry is read, a \ref OnMediaLocation + * and \ref repo::yum::ResourceType are prepared and passed to the \ref _callback. * + * Depending on the \ref _callback type provided on construction, ResourceType may + * additionally be passed as a plain string. This form allows handling custom + * resource types (e.g. ones with embedded locale tag). * * \code * RepomdFileReader reader(repomd_file, @@ -46,15 +46,11 @@ namespace zypp class RepomdFileReader : private base::NonCopyable { public: - /** - * Callback definition. - * First parameter is a \ref OnMediaLocation object with the resource - * second parameter is the resource type. - */ - typedef function< bool( - const OnMediaLocation &, - const repo::yum::ResourceType &)> - ProcessResource; + /** Callbacl taking \ref OnMediaLocation and \ref repo::yum::ResourceType */ + typedef function< bool( const OnMediaLocation &, const repo::yum::ResourceType & )> ProcessResource; + + /** Alternate callback also receiving the ResourceType as string. */ + typedef function< bool( const OnMediaLocation &, const repo::yum::ResourceType &, const std::string & )> ProcessResource2; /** * CTOR. Creates also \ref xml::Reader and starts reading. @@ -64,12 +60,11 @@ namespace zypp * * \see RepomdFileReader::ProcessResource */ - RepomdFileReader( - const Pathname & repomd_file, const ProcessResource & callback); + RepomdFileReader( const Pathname & repomd_file, const ProcessResource & callback ); + /** \overload taking ProcessResource2 callback */ + RepomdFileReader( const Pathname & repomd_file, const ProcessResource2 & callback ); - /** - * DTOR - */ + /** DTOR */ ~RepomdFileReader(); private: @@ -78,10 +73,8 @@ namespace zypp }; - } // ns yum - } // ns parser -} // ns zypp - -#endif /*zypp_source_yum_RepomdFileReader_H*/ + } // namespace yum + } // namespace parser +} // namespace zypp -// vim: set ts=2 sts=2 sw=2 et ai: +#endif // zypp_source_yum_RepomdFileReader_H diff --git a/zypp/repo/yum/Downloader.cc b/zypp/repo/yum/Downloader.cc index a27dd2f..c173f0d 100644 --- a/zypp/repo/yum/Downloader.cc +++ b/zypp/repo/yum/Downloader.cc @@ -9,8 +9,9 @@ #include #include "zypp/base/String.h" -#include "zypp/base/Logger.h" +#include "zypp/base/LogTools.h" #include "zypp/base/Function.h" +#include "zypp/ZConfig.h" #include "zypp/parser/yum/RepomdFileReader.h" #include "zypp/parser/yum/PatchesFileReader.h" @@ -32,9 +33,7 @@ namespace yum Downloader::Downloader( const RepoInfo &repoinfo , const Pathname &delta_dir) : repo::Downloader(repoinfo), _delta_dir(delta_dir), _media_ptr(0L) -{ -} - +{} RepoStatus Downloader::status( MediaSetAccess &media ) { @@ -42,9 +41,7 @@ RepoStatus Downloader::status( MediaSetAccess &media ) return RepoStatus(repomd); } -static OnMediaLocation -loc_with_path_prefix(const OnMediaLocation & loc, - const Pathname & prefix) +static OnMediaLocation loc_with_path_prefix( const OnMediaLocation & loc, const Pathname & prefix ) { if (prefix.empty() || prefix == "/") return loc; @@ -55,7 +52,7 @@ loc_with_path_prefix(const OnMediaLocation & loc, } // search old repository file file to run the delta algorithm on -static Pathname search_deltafile( const Pathname &dir, const Pathname &file ) +static Pathname search_deltafile( const Pathname & dir, const Pathname & file ) { Pathname deltafile; if (!PathInfo(dir).isDir()) @@ -78,70 +75,125 @@ static Pathname search_deltafile( const Pathname &dir, const Pathname &file ) return deltafile; } -bool Downloader::patches_Callback( const OnMediaLocation &loc, - const string &id ) +bool Downloader::patches_Callback( const OnMediaLocation & loc_r, const string & id_r ) { - OnMediaLocation loc_with_path(loc_with_path_prefix(loc, repoInfo().path())); - MIL << id << " : " << loc_with_path << endl; - this->enqueueDigested(loc_with_path, FileChecker(), search_deltafile(_delta_dir + "repodata", loc.filename())); + OnMediaLocation loc_with_path(loc_with_path_prefix(loc_r, repoInfo().path())); + MIL << id_r << " : " << loc_with_path << endl; + this->enqueueDigested(loc_with_path, FileChecker(), search_deltafile(_delta_dir + "repodata", loc_r.filename())); return true; } -bool Downloader::repomd_Callback( const OnMediaLocation &loc, - const ResourceType &dtype ) -{ - OnMediaLocation loc_with_path(loc_with_path_prefix(loc, repoInfo().path())); - MIL << dtype << " : " << loc_with_path << endl; - //! \todo do this through a ZConfig call so that it is always in sync with parser - // skip other - if ( dtype == ResourceType::OTHER ) - { - MIL << "Skipping other.xml" << endl; - return true; - } - // skip filelists - if ( dtype == ResourceType::FILELISTS ) +//bool repomd_Callback2( const OnMediaLocation &loc, const ResourceType &dtype, const std::string &typestr, UserData & userData_r ); + +/////////////////////////////////////////////////////////////////// +namespace +{ + /////////////////////////////////////////////////////////////////// + /// \class Impl + /// \brief Helper filtering the files offered by a RepomdFileReader + /// + /// Clumsy construct; basically an Impl class for Downloader, maintained + /// in Downloader::download only while parsing a repomd.xml. + /// + /// Introduced because Downloader itself lacks an Impl class, thus can't + /// be extended to provide more data to the callbacks without losing + /// binary compatibility. + /////////////////////////////////////////////////////////////////// + struct RepomdFileReaderCallback2 { - MIL << "Skipping filelists.xml.gz" << endl; - return true; - } + RepomdFileReaderCallback2( const RepomdFileReader::ProcessResource & origCallback_r ) + : _origCallback( origCallback_r ) + { + addWantedLocale( ZConfig::instance().textLocale() ); + for ( const Locale & it : ZConfig::instance().repoRefreshLocales() ) + addWantedLocale( it ); + } - this->enqueueDigested(loc_with_path, FileChecker(), search_deltafile(_delta_dir + "repodata", loc.filename())); + /** The callback invoked by the RepomdFileReader */ + bool repomd_Callback2( const OnMediaLocation & loc_r, const ResourceType & dtype_r, const std::string & typestr_r ) + { + // filter well known resource types + if ( dtype_r == ResourceType::OTHER || dtype_r == ResourceType::FILELISTS ) + return true; // skip it + + // filter custom resource types (by string) + if ( dtype_r == ResourceType::NONE ) + { + // susedata.LANG + if ( str::hasPrefix( typestr_r, "susedata." ) && ! wantLocale( Locale(typestr_r.c_str()+9) ) ) + return true; // skip it + } + + // take it + return( _origCallback ? _origCallback( loc_r, dtype_r ) : true ); + } + + private: + bool wantLocale( const Locale & locale_r ) const + { return _wantedLocales.count( locale_r ); } + + void addWantedLocale( Locale locale_r ) + { + while ( locale_r ) + { + _wantedLocales.insert( locale_r ); + locale_r = locale_r.fallback(); + } + } + + private: + RepomdFileReader::ProcessResource _origCallback; ///< Original Downloader callback + LocaleSet _wantedLocales; ///< Locales do download + + }; +} // namespace +/////////////////////////////////////////////////////////////////// + +bool Downloader::repomd_Callback( const OnMediaLocation & loc_r, const ResourceType & dtype_r ) +{ + // NOTE: Filtering of unwanted files is done in RepomdFileReaderCallback2! + + // schedule file for download + const OnMediaLocation & loc_with_path(loc_with_path_prefix(loc_r, repoInfo().path())); + this->enqueueDigested(loc_with_path, FileChecker(), search_deltafile(_delta_dir + "repodata", loc_r.filename())); // We got a patches file we need to read, to add patches listed // there, so we transfer what we have in the queue, and // queue the patches in the patches callback - if ( dtype == ResourceType::PATCHES ) + if ( dtype_r == ResourceType::PATCHES ) { this->start( _dest_dir, *_media_ptr ); // now the patches.xml file must exists - PatchesFileReader( _dest_dir + repoInfo().path() + loc.filename(), + PatchesFileReader( _dest_dir + repoInfo().path() + loc_r.filename(), bind( &Downloader::patches_Callback, this, _1, _2)); } - return true; } -/** \todo: Downloading/sigcheck of master index shoudl be common in base class */ -void Downloader::download( MediaSetAccess &media, - const Pathname &dest_dir, - const ProgressData::ReceiverFnc & progressrcv ) +void Downloader::download( MediaSetAccess & media, const Pathname & dest_dir, const ProgressData::ReceiverFnc & progressrcv ) { Pathname masterIndex( repoInfo().path() / "/repodata/repomd.xml" ); defaultDownloadMasterIndex( media, dest_dir, masterIndex ); + // init the data stored in Downloader itself _media_ptr = (&media); _dest_dir = dest_dir; - RepomdFileReader( dest_dir / masterIndex, bind( &Downloader::repomd_Callback, this, _1, _2)); + + // init the extended data + RepomdFileReaderCallback2 pimpl( bind(&Downloader::repomd_Callback, this, _1, _2) ); + + // setup parser + RepomdFileReader( dest_dir / masterIndex, + RepomdFileReader::ProcessResource2( bind(&RepomdFileReaderCallback2::repomd_Callback2, &pimpl, _1, _2, _3) ) ); // ready, go! start( dest_dir, media ); } -}// ns yum -}// ns source -} // ns zypp +} // namespace yum +} // namespace repo +} // namespace zypp diff --git a/zypp/repo/yum/Downloader.h b/zypp/repo/yum/Downloader.h index f34b42b..e775299 100644 --- a/zypp/repo/yum/Downloader.h +++ b/zypp/repo/yum/Downloader.h @@ -72,6 +72,7 @@ namespace zypp bool repomd_Callback( const OnMediaLocation &loc, const ResourceType &dtype ); bool patches_Callback( const OnMediaLocation &loc, const std::string &id ); private: + // TODO: Use pimpl to be extensible; but breaks bincompat :( Pathname _dest_dir; Pathname _delta_dir; std::list _patches_files; -- 2.7.4