1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ZConfig.cc
13 #include "zypp/base/Logger.h"
14 #include "zypp/base/InputStream.h"
16 #include "zypp/ZConfig.h"
17 #include "zypp/ZYppFactory.h"
18 #include "zypp/PathInfo.h"
19 #include "zypp/parser/IniDict.h"
22 using namespace zypp::filesystem;
23 using namespace zypp::parser;
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 // CLASS NAME : ZConfig::Impl
33 /** ZConfig implementation.
39 : repo_add_probe(false),
40 repo_refresh_delay(0),
41 autolock_untrustedvendor(false)
43 MIL << "ZConfig singleton created." << endl;
44 Pathname confpath("/etc/zypp/zypp.conf");
45 if ( PathInfo(confpath).isExist())
47 InputStream is(confpath);
52 MIL << "No /etc/zypp/zypp.conf" << endl;
55 for ( IniDict::section_const_iterator sit = dict.sectionsBegin();
56 sit != dict.sectionsEnd();
60 //MIL << section << endl;
61 for ( IniDict::entry_const_iterator it = dict.entriesBegin(*sit);
62 it != dict.entriesEnd(*sit);
65 string entry(it->first);
66 string value(it->second);
67 // DBG << (*it).first << "=" << (*it).second << endl;
68 if ( section == "main" )
70 if ( entry == "arch" )
72 cfg_arch = Arch(value);
74 else if ( entry == "metadatadir" )
76 cfg_metadata_path = Pathname(value);
78 else if ( entry == "reposdir" )
80 cfg_known_repos_path = Pathname(value);
82 else if ( entry == "cachedir" )
84 cfg_cache_path = Pathname(value);
86 else if ( entry == "repo.add.probe" )
88 repo_add_probe = (value == "1");
90 else if ( entry == "repo.refresh.delay" )
92 str::strtonum(value, repo_refresh_delay);
95 else if ( section == "locking" )
97 autolock_untrustedvendor = ( value == "1" );
109 parser::IniDict dict;
113 Pathname cfg_metadata_path;
114 Pathname cfg_cache_path;
115 Pathname cfg_known_repos_path;
118 unsigned repo_refresh_delay;
121 bool autolock_untrustedvendor;
124 ///////////////////////////////////////////////////////////////////
126 ///////////////////////////////////////////////////////////////////
128 // METHOD NAME : ZConfig::instance
129 // METHOD TYPE : ZConfig &
131 ZConfig & ZConfig::instance()
133 static ZConfig _instance; // The singleton
137 ///////////////////////////////////////////////////////////////////
139 // METHOD NAME : ZConfig::ZConfig
140 // METHOD TYPE : Ctor
148 ///////////////////////////////////////////////////////////////////
150 // METHOD NAME : ZConfig::~ZConfig
151 // METHOD TYPE : Dtor
156 ///////////////////////////////////////////////////////////////////
157 #warning change methods to use the singleton
159 ///////////////////////////////////////////////////////////////////
161 // METHOD NAME : ZConfig::systemArchitecture
162 // METHOD TYPE : Arch
164 Arch ZConfig::systemArchitecture() const
166 return ( (_pimpl->cfg_arch == Arch()) ?
167 getZYpp()->architecture() : _pimpl->cfg_arch );
170 ///////////////////////////////////////////////////////////////////
172 // METHOD NAME : ZConfig::defaultTextLocale
173 // METHOD TYPE : Locale
175 Locale ZConfig::textLocale() const
177 return getZYpp()->getTextLocale();
180 Pathname ZConfig::repoMetadataPath() const
182 return ( _pimpl->cfg_metadata_path.empty()
183 ? Pathname("/var/cache/zypp/raw") : _pimpl->cfg_metadata_path );
186 Pathname ZConfig::repoCachePath() const
188 return ( _pimpl->cfg_cache_path.empty()
189 ? Pathname("/var/cache/zypp") : _pimpl->cfg_cache_path );
192 Pathname ZConfig::knownReposPath() const
194 return ( _pimpl->cfg_known_repos_path.empty()
195 ? Pathname("/etc/zypp/repos.d") : _pimpl->cfg_known_repos_path );
198 const std::string & ZConfig::cacheDBSplitJoinSeparator() const
200 static std::string s("!@$");
204 bool ZConfig::repo_add_probe() const
206 return _pimpl->repo_add_probe;
209 unsigned ZConfig::repo_refresh_delay() const
211 return _pimpl->repo_refresh_delay;
214 bool ZConfig::autolock_untrustedvendor() const
216 return _pimpl->autolock_untrustedvendor;
219 /////////////////////////////////////////////////////////////////
221 ///////////////////////////////////////////////////////////////////