1
/*---------------------------------------------------------------------\
3
| |__ / \ / / . \ . \ |
8
\---------------------------------------------------------------------*/
10
#include "zypp/base/LogTools.h"
11
#include "zypp/base/String.h"
13
#include "zypp/ZConfig.h"
14
#include "zypp/Target.h"
15
#include "zypp/Arch.h"
16
#include "zypp/repo/RepoVariables.h"
17
#include "zypp/base/NonCopyable.h"
19
///////////////////////////////////////////////////////////////////
22
///////////////////////////////////////////////////////////////////
25
///////////////////////////////////////////////////////////////////
28
/** \brief Provide lazy initialized repo variables
30
struct ReplacerData : private zypp::base::NonCopyable
32
const std::string & sysarch() const
34
if ( _sysarch.empty() )
39
const std::string & basearch() const
41
if ( _basearch.empty() )
46
const std::string & releasever() const
48
if( _releasever.empty() )
49
_releasever = Target::distributionVersion( Pathname()/*guess*/ );
54
void initArchStr() const
56
Arch arch( ZConfig::instance().systemArchitecture() );
57
_sysarch = arch.asString();
58
_basearch = arch.baseArch().asString();
61
mutable std::string _sysarch;
62
mutable std::string _basearch;
63
mutable std::string _releasever;
66
/** \brief Replace repo variables on demand
68
* Initialisation of repo variables is delayed until they actually occur in
71
std::string replacer( const std::string & value_r )
73
static ReplacerData _data;
75
std::string ret( value_r );
76
// Don't need to capture static (non automatic) _data in lambda
77
ret = str::replaceAllFun( ret, "$arch", []()-> std::string { return _data.sysarch(); } );
78
ret = str::replaceAllFun( ret, "$basearch", []()-> std::string { return _data.basearch(); } );
79
ret = str::replaceAllFun( ret, "$releasever", []()-> std::string { return _data.releasever(); } );
84
///////////////////////////////////////////////////////////////////
86
std::string RepoVariablesStringReplacer::operator()( const std::string & value ) const
88
return replacer( value );
91
Url RepoVariablesUrlReplacer::operator()( const Url & value ) const
94
newurl.setPathData( replacer( value.getPathData() ) );
95
newurl.setQueryString( replacer( value.getQueryString() ) );
100
///////////////////////////////////////////////////////////////////
102
///////////////////////////////////////////////////////////////////