libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00009 00010 #include "zypp/base/LogTools.h" 00011 #include "zypp/base/String.h" 00012 00013 #include "zypp/ZConfig.h" 00014 #include "zypp/Target.h" 00015 #include "zypp/Arch.h" 00016 #include "zypp/repo/RepoVariables.h" 00017 #include "zypp/base/NonCopyable.h" 00018 00020 namespace zypp 00021 { 00023 namespace repo 00024 { 00026 namespace 00027 { 00030 struct ReplacerData : private zypp::base::NonCopyable 00031 { 00032 const std::string & sysarch() const 00033 { 00034 if ( _sysarch.empty() ) 00035 initArchStr(); 00036 return _sysarch; 00037 } 00038 00039 const std::string & basearch() const 00040 { 00041 if ( _basearch.empty() ) 00042 initArchStr(); 00043 return _basearch; 00044 } 00045 00046 const std::string & releasever() const 00047 { 00048 if( _releasever.empty() ) 00049 _releasever = Target::distributionVersion( Pathname()/*guess*/ ); 00050 return _releasever; 00051 } 00052 00053 private: 00054 void initArchStr() const 00055 { 00056 Arch arch( ZConfig::instance().systemArchitecture() ); 00057 _sysarch = arch.asString(); 00058 _basearch = arch.baseArch().asString(); 00059 } 00060 private: 00061 mutable std::string _sysarch; 00062 mutable std::string _basearch; 00063 mutable std::string _releasever; 00064 }; 00065 00071 std::string replacer( const std::string & value_r ) 00072 { 00073 static ReplacerData _data; 00074 00075 std::string ret( value_r ); 00076 ret = str::replaceAllFun( ret, "$arch", [&_data]()-> std::string { return _data.sysarch(); } ); 00077 ret = str::replaceAllFun( ret, "$basearch", [&_data]()-> std::string { return _data.basearch(); } ); 00078 ret = str::replaceAllFun( ret, "$releasever", [&_data]()-> std::string { return _data.releasever(); } ); 00079 return ret; 00080 } 00081 00082 } // namespace 00084 00085 std::string RepoVariablesStringReplacer::operator()( const std::string & value ) const 00086 { 00087 return replacer( value ); 00088 } 00089 00090 Url RepoVariablesUrlReplacer::operator()( const Url & value ) const 00091 { 00092 Url newurl( value ); 00093 newurl.setPathData( replacer( value.getPathData() ) ); 00094 newurl.setQueryString( replacer( value.getQueryString() ) ); 00095 return newurl; 00096 } 00097 00098 } // namespace repo 00100 } // namespace zypp