std::string Target::release() const
{ return _pimpl->release(); }
+ std::string Target::distributionFlavor() const
+ { return _pimpl->distributionFlavor(); }
+
std::string Target::targetDistribution() const
{ return _pimpl->targetDistribution(); }
/**
+ * 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
*/
//@{
+ /* 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
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
// 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
);
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()
{
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) {
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) );
}
///////////////////////////////////////////////////////////////////
ResPool::instance().setHardLockQueries( hardLocks );
}
}
-
+
+ // now that the target is loaded, we can cache the flavor
+ createLastDistributionFlavorCache();
MIL << "Target loaded: " << system.solvablesSize() << " resolvables" << endl;
}
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
/**
* generates a cache of the last product flavor
*/
- void createLastBaseProductFlavorCache() const;
+ void createLastDistributionFlavorCache() const;
void load();
/** \copydoc Target::distributionVersion()*/
std::string distributionVersion() const;
+ /** \copydoc Target::distributionFlavor() */
+ std::string distributionFlavor() const;
+
protected:
/** Path to the target */
Pathname _root;