00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <iostream>
00013 #include "zypp/base/Logger.h"
00014 #include "zypp/base/InputStream.h"
00015 #include "zypp/base/String.h"
00016
00017 #include "zypp/ZConfig.h"
00018 #include "zypp/ZYppFactory.h"
00019 #include "zypp/PathInfo.h"
00020 #include "zypp/parser/IniDict.h"
00021
00022 using namespace std;
00023 using namespace zypp::filesystem;
00024 using namespace zypp::parser;
00025
00027 namespace zypp
00028 {
00029
00031
00032
00033
00039 class ZConfig::Impl
00040 {
00041 public:
00042 Impl()
00043 : repo_add_probe ( false )
00044 , repo_refresh_delay ( 10 )
00045 , download_use_patchrpm ( true )
00046 , download_use_deltarpm ( true )
00047 , autolock_untrustedvendor( false )
00048
00049 {
00050 MIL << "ZConfig singleton created." << endl;
00051
00052
00053
00054 const char *env_confpath = getenv( "ZYPP_CONF" );
00055 Pathname confpath( env_confpath ? env_confpath : "/etc/zypp/zypp.conf" );
00056 if ( PathInfo(confpath).isExist())
00057 {
00058 InputStream is(confpath);
00059 dict.read(is);
00060 }
00061 else
00062 {
00063 MIL << confpath << " not found, using defaults instead." << endl;
00064 return;
00065 }
00066
00067 for ( IniDict::section_const_iterator sit = dict.sectionsBegin();
00068 sit != dict.sectionsEnd();
00069 ++sit )
00070 {
00071 string section(*sit);
00072
00073 for ( IniDict::entry_const_iterator it = dict.entriesBegin(*sit);
00074 it != dict.entriesEnd(*sit);
00075 ++it )
00076 {
00077 string entry(it->first);
00078 string value(it->second);
00079
00080 if ( section == "main" )
00081 {
00082 if ( entry == "arch" )
00083 {
00084 cfg_arch = Arch(value);
00085 }
00086 else if ( entry == "metadatadir" )
00087 {
00088 cfg_metadata_path = Pathname(value);
00089 }
00090 else if ( entry == "reposdir" )
00091 {
00092 cfg_known_repos_path = Pathname(value);
00093 }
00094 else if ( entry == "cachedir" )
00095 {
00096 cfg_cache_path = Pathname(value);
00097 }
00098 else if ( entry == "repo.add.probe" )
00099 {
00100 repo_add_probe = str::strToBool( value, repo_add_probe );
00101 }
00102 else if ( entry == "repo.refresh.delay" )
00103 {
00104 str::strtonum(value, repo_refresh_delay);
00105 }
00106 else if ( entry == "download.use_patchrpm" )
00107 {
00108 download_use_patchrpm = str::strToBool( value, download_use_patchrpm );
00109 }
00110 else if ( entry == "download.use_deltarpm" )
00111 {
00112 download_use_deltarpm = str::strToBool( value, download_use_deltarpm );
00113 }
00114 }
00115 else if ( section == "locking" )
00116 {
00117 autolock_untrustedvendor = str::strToBool( value, autolock_untrustedvendor );
00118 }
00119
00120 }
00121 }
00122
00123 }
00124
00125 ~Impl()
00126 {}
00127
00128 public:
00129 parser::IniDict dict;
00130
00131 Arch cfg_arch;
00132
00133 Pathname cfg_metadata_path;
00134 Pathname cfg_cache_path;
00135 Pathname cfg_known_repos_path;
00136
00137 bool repo_add_probe;
00138 unsigned repo_refresh_delay;
00139
00140 bool download_use_patchrpm;
00141 bool download_use_deltarpm;
00142
00143
00144 bool autolock_untrustedvendor;
00145
00146 };
00148
00150
00151
00152
00153
00154 ZConfig & ZConfig::instance()
00155 {
00156 static ZConfig _instance;
00157 return _instance;
00158 }
00159
00161
00162
00163
00164
00165 ZConfig::ZConfig()
00166 : _pimpl( new Impl )
00167 {
00168
00169 }
00170
00172
00173
00174
00175
00176 ZConfig::~ZConfig( )
00177 {}
00178
00180 #warning change methods to use the singleton
00181
00183
00184
00185
00186
00187 Arch ZConfig::systemArchitecture() const
00188 {
00189
00190
00191 return ( (_pimpl->cfg_arch == Arch()) ?
00192 getZYpp()->architecture() : _pimpl->cfg_arch );
00193 }
00194
00196
00197
00198
00199
00200 void ZConfig::overrideSystemArchitecture(const Arch & arch)
00201 {
00202 WAR << "Overriding system architecture with " << arch << endl;
00203 _pimpl->cfg_arch = arch;
00204 getZYpp()->setArchitecture( arch );
00205 }
00206
00208
00209
00210
00211
00212 Locale ZConfig::textLocale() const
00213 {
00214 return getZYpp()->getTextLocale();
00215 }
00216
00217 Pathname ZConfig::repoMetadataPath() const
00218 {
00219 return ( _pimpl->cfg_metadata_path.empty()
00220 ? Pathname("/var/cache/zypp/raw") : _pimpl->cfg_metadata_path );
00221 }
00222
00223 Pathname ZConfig::repoCachePath() const
00224 {
00225 return ( _pimpl->cfg_cache_path.empty()
00226 ? Pathname("/var/cache/zypp") : _pimpl->cfg_cache_path );
00227 }
00228
00229 Pathname ZConfig::knownReposPath() const
00230 {
00231 return ( _pimpl->cfg_known_repos_path.empty()
00232 ? Pathname("/etc/zypp/repos.d") : _pimpl->cfg_known_repos_path );
00233 }
00234
00235 const std::string & ZConfig::cacheDBSplitJoinSeparator() const
00236 {
00237 static std::string s("!@$");
00238 return s;
00239 }
00240
00241 bool ZConfig::repo_add_probe() const
00242 {
00243 return _pimpl->repo_add_probe;
00244 }
00245
00246 unsigned ZConfig::repo_refresh_delay() const
00247 {
00248 return _pimpl->repo_refresh_delay;
00249 }
00250
00251 bool ZConfig::download_use_patchrpm() const
00252 { return _pimpl->download_use_patchrpm; }
00253
00254 bool ZConfig::download_use_deltarpm() const
00255 { return _pimpl->download_use_deltarpm; }
00256
00257 bool ZConfig::autolock_untrustedvendor() const
00258 {
00259 return _pimpl->autolock_untrustedvendor;
00260 }
00261
00263 }