Author: dmacvicar Date: Thu Nov 6 18:36:39 2008 New Revision: 11607 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11607&view=rev Log: add distrbutionFlavor that does not require the target to be loaded, and it as a header Modified: trunk/libzypp/zypp/Target.cc trunk/libzypp/zypp/Target.h trunk/libzypp/zypp/base/Functional.h trunk/libzypp/zypp/media/MediaAria2c.cc trunk/libzypp/zypp/media/MediaCurl.cc trunk/libzypp/zypp/target/TargetImpl.cc trunk/libzypp/zypp/target/TargetImpl.h Modified: trunk/libzypp/zypp/Target.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Target.cc?rev=11607&r1=11606&r2=11607&view=diff ============================================================================== --- trunk/libzypp/zypp/Target.cc (original) +++ trunk/libzypp/zypp/Target.cc Thu Nov 6 18:36:39 2008 @@ -97,6 +97,9 @@ std::string Target::release() const { return _pimpl->release(); } + std::string Target::distributionFlavor() const + { return _pimpl->distributionFlavor(); } + std::string Target::targetDistribution() const { return _pimpl->targetDistribution(); } Modified: trunk/libzypp/zypp/Target.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Target.h?rev=11607&r1=11606&r2=11607&view=diff ============================================================================== --- trunk/libzypp/zypp/Target.h (original) +++ trunk/libzypp/zypp/Target.h Thu Nov 6 18:36:39 2008 @@ -153,6 +153,15 @@ /** + * This is \flavor attribute of the installed base product + * but does not require the target to be loaded as it remembers + * the last used one. It can be empty is the target has never + * been loaded, as the value is not present in the system + * but computer from a package provides + */ + std::string distributionFlavor() const; + + /** * anonymous unique id * * This id is generated once and stays in the Modified: trunk/libzypp/zypp/base/Functional.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/Functional.h?rev=11607&r1=11606&r2=11607&view=diff ============================================================================== --- trunk/libzypp/zypp/base/Functional.h (original) +++ trunk/libzypp/zypp/base/Functional.h Thu Nov 6 18:36:39 2008 @@ -214,6 +214,29 @@ */ //@{ + /* functor that always returns a copied + value */ + template<class T> + struct Constant + { + Constant( const T &value ) + : _value(value) + {} + + template<class _Tp> + T operator()( _Tp ) const + { return _value; } + + T operator()() const + { return _value; } + + T _value; + }; + + template<class T> + inline Constant<T> constant( const T &value ) + { return Constant<T>(value); } + /** Logical functor always \c true. */ struct True Modified: trunk/libzypp/zypp/media/MediaAria2c.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaAria2c.cc?rev=11607&r1=11606&r2=11607&view=diff ============================================================================== --- trunk/libzypp/zypp/media/MediaAria2c.cc (original) +++ trunk/libzypp/zypp/media/MediaAria2c.cc Thu Nov 6 18:36:39 2008 @@ -104,6 +104,31 @@ return _value.c_str(); } +static const char *const distributionFlavorHeader() +{ + // we need to add the release and identifier to the + // agent string. + // The target could be not initialized, and then this information + // is not available. + Target_Ptr target; + // FIXME this has to go away as soon as the target + // does not throw when not initialized. + try { + target = zypp::getZYpp()->target(); + } + catch ( const Exception &e ) + { + // nothing to do + } + + static const std::string _value( + str::trim( str::form( + "X-ZYpp-DistributionFlavor: %s", + target ? target->distributionFlavor().c_str() : "" ) ) + ); + return _value.c_str(); +} + const char *const MediaAria2c::agentString() { // we need to add the release and identifier to the @@ -200,6 +225,7 @@ // add the anonymous id. _args.push_back(str::form("--header=%s", anonymousIdHeader() )); + _args.push_back(str::form("--header=%s", distributionFlavorHeader() )); // TODO add debug option // Transfer timeout Modified: trunk/libzypp/zypp/media/MediaCurl.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaCurl.cc?rev=11607&r1=11606&r2=11607&view=diff ============================================================================== --- trunk/libzypp/zypp/media/MediaCurl.cc (original) +++ trunk/libzypp/zypp/media/MediaCurl.cc Thu Nov 6 18:36:39 2008 @@ -209,6 +209,32 @@ ); return _value.c_str(); } + +static const char *const distributionFlavorHeader() +{ + // we need to add the release and identifier to the + // agent string. + // The target could be not initialized, and then this information + // is not available. + Target_Ptr target; + // FIXME this has to go away as soon as the target + // does not throw when not initialized. + try { + target = zypp::getZYpp()->target(); + } + catch ( const Exception &e ) + { + // nothing to do + } + + static const std::string _value( + str::trim( str::form( + "X-ZYpp-DistributionFlavor: %s", + target ? target->distributionFlavor().c_str() : "" ) ) + ); + return _value.c_str(); +} + static const char *const agentString() { @@ -718,7 +744,14 @@ if ( !_customHeaders ) { ZYPP_THROW(MediaCurlInitException(_url)); } - + + // now add the product flavor header + _customHeaders = curl_slist_append(_customHeaders, distributionFlavorHeader()); + + if ( !_customHeaders ) { + ZYPP_THROW(MediaCurlInitException(_url)); + } + ret = curl_easy_setopt ( _curl, CURLOPT_HTTPHEADER, _customHeaders ); if ( ret != 0) { Modified: trunk/libzypp/zypp/target/TargetImpl.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/target/TargetImpl.cc?rev=11607&r1=11606&r2=11607&view=diff ============================================================================== --- trunk/libzypp/zypp/target/TargetImpl.cc (original) +++ trunk/libzypp/zypp/target/TargetImpl.cc Thu Nov 6 18:36:39 2008 @@ -390,26 +390,26 @@ generateRandomId ); } - void TargetImpl::createLastBaseProductFlavorCache() const + void TargetImpl::createLastDistributionFlavorCache() const { // create the anonymous unique id // this value is used for statistics - Pathname flavorpath( home() / "LastBaseProductFlavor"); + Pathname flavorpath( home() / "LastDistributionFlavor"); // is there a product Product::constPtr p = baseProduct(); if ( ! p ) { - WAR << "No base product, can't create flavor cache" << endl; + WAR << "No base product, I won't create flavor cache" << endl; return; } string flavor = p->flavor(); - //updateFileContent( flavorpath, - // // only if flavor is not empty - // ( flavor.empty() ? functor::False() : functor::True() ), - // flavor ); + updateFileContent( flavorpath, + // only if flavor is not empty + functor::Constant<bool>( ! flavor.empty() ), + functor::Constant<string>(flavor) ); } /////////////////////////////////////////////////////////////////// @@ -587,7 +587,9 @@ ResPool::instance().setHardLockQueries( hardLocks ); } } - + + // now that the target is loaded, we can cache the flavor + createLastDistributionFlavorCache(); MIL << "Target loaded: " << system.solvablesSize() << " resolvables" << endl; } @@ -1030,6 +1032,18 @@ return _distributionVersion; } + std::string TargetImpl::distributionFlavor() const + { + std::ifstream idfile( ( home() / "LastDistributionFlavor" ).c_str() ); + for( iostr::EachLine in( idfile ); in; in.next() ) + { + std::string line( str::trim( *in ) ); + if ( ! line.empty() ) + return line; + } + return std::string(); + } + /////////////////////////////////////////////////////////////////// std::string TargetImpl::anonymousUniqueId() const Modified: trunk/libzypp/zypp/target/TargetImpl.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/target/TargetImpl.h?rev=11607&r1=11606&r2=11607&view=diff ============================================================================== --- trunk/libzypp/zypp/target/TargetImpl.h (original) +++ trunk/libzypp/zypp/target/TargetImpl.h Thu Nov 6 18:36:39 2008 @@ -79,7 +79,7 @@ /** * generates a cache of the last product flavor */ - void createLastBaseProductFlavorCache() const; + void createLastDistributionFlavorCache() const; void load(); @@ -164,6 +164,9 @@ /** \copydoc Target::distributionVersion()*/ std::string distributionVersion() const; + /** \copydoc Target::distributionFlavor() */ + std::string distributionFlavor() const; + protected: /** Path to the target */ Pathname _root; -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org