libzypp  15.3.0
ZConfig.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 extern "C"
13 {
14 #include <features.h>
15 #include <sys/utsname.h>
16 #if __GLIBC_PREREQ (2,16)
17 #include <sys/auxv.h> // getauxval for PPC64P7 detection
18 #endif
19 #include <unistd.h>
20 #include <solv/solvversion.h>
21 }
22 #include <iostream>
23 #include <fstream>
24 #include "zypp/base/Logger.h"
25 #include "zypp/base/IOStream.h"
26 #include "zypp/base/InputStream.h"
27 #include "zypp/base/String.h"
28 
29 #include "zypp/ZConfig.h"
30 #include "zypp/ZYppFactory.h"
31 #include "zypp/PathInfo.h"
32 #include "zypp/parser/IniDict.h"
33 
34 #include "zypp/sat/Pool.h"
35 
36 using namespace std;
37 using namespace zypp::filesystem;
38 using namespace zypp::parser;
39 
40 #undef ZYPP_BASE_LOGGER_LOGGROUP
41 #define ZYPP_BASE_LOGGER_LOGGROUP "zconfig"
42 
44 namespace zypp
45 {
46 
55  namespace
57  {
58 
61  Arch _autodetectSystemArchitecture()
62  {
63  struct ::utsname buf;
64  if ( ::uname( &buf ) < 0 )
65  {
66  ERR << "Can't determine system architecture" << endl;
67  return Arch_noarch;
68  }
69 
70  Arch architecture( buf.machine );
71  MIL << "Uname architecture is '" << buf.machine << "'" << endl;
72 
73  if ( architecture == Arch_i686 )
74  {
75  // some CPUs report i686 but dont implement cx8 and cmov
76  // check for both flags in /proc/cpuinfo and downgrade
77  // to i586 if either is missing (cf bug #18885)
78  std::ifstream cpuinfo( "/proc/cpuinfo" );
79  if ( cpuinfo )
80  {
81  for( iostr::EachLine in( cpuinfo ); in; in.next() )
82  {
83  if ( str::hasPrefix( *in, "flags" ) )
84  {
85  if ( in->find( "cx8" ) == std::string::npos
86  || in->find( "cmov" ) == std::string::npos )
87  {
88  architecture = Arch_i586;
89  WAR << "CPU lacks 'cx8' or 'cmov': architecture downgraded to '" << architecture << "'" << endl;
90  }
91  break;
92  }
93  }
94  }
95  else
96  {
97  ERR << "Cant open " << PathInfo("/proc/cpuinfo") << endl;
98  }
99  }
100  else if ( architecture == Arch_sparc || architecture == Arch_sparc64 )
101  {
102  // Check for sun4[vum] to get the real arch. (bug #566291)
103  std::ifstream cpuinfo( "/proc/cpuinfo" );
104  if ( cpuinfo )
105  {
106  for( iostr::EachLine in( cpuinfo ); in; in.next() )
107  {
108  if ( str::hasPrefix( *in, "type" ) )
109  {
110  if ( in->find( "sun4v" ) != std::string::npos )
111  {
112  architecture = ( architecture == Arch_sparc64 ? Arch_sparc64v : Arch_sparcv9v );
113  WAR << "CPU has 'sun4v': architecture upgraded to '" << architecture << "'" << endl;
114  }
115  else if ( in->find( "sun4u" ) != std::string::npos )
116  {
117  architecture = ( architecture == Arch_sparc64 ? Arch_sparc64 : Arch_sparcv9 );
118  WAR << "CPU has 'sun4u': architecture upgraded to '" << architecture << "'" << endl;
119  }
120  else if ( in->find( "sun4m" ) != std::string::npos )
121  {
122  architecture = Arch_sparcv8;
123  WAR << "CPU has 'sun4m': architecture upgraded to '" << architecture << "'" << endl;
124  }
125  break;
126  }
127  }
128  }
129  else
130  {
131  ERR << "Cant open " << PathInfo("/proc/cpuinfo") << endl;
132  }
133  }
134  else if ( architecture == Arch_armv7l || architecture == Arch_armv6l )
135  {
136  std::ifstream platform( "/etc/rpm/platform" );
137  if (platform)
138  {
139  for( iostr::EachLine in( platform ); in; in.next() )
140  {
141  if ( str::hasPrefix( *in, "armv7hl-" ) )
142  {
143  architecture = Arch_armv7hl;
144  WAR << "/etc/rpm/platform contains armv7hl-: architecture upgraded to '" << architecture << "'" << endl;
145  break;
146  }
147  if ( str::hasPrefix( *in, "armv6hl-" ) )
148  {
149  architecture = Arch_armv6hl;
150  WAR << "/etc/rpm/platform contains armv6hl-: architecture upgraded to '" << architecture << "'" << endl;
151  break;
152  }
153  }
154  }
155  }
156 #if __GLIBC_PREREQ (2,16)
157  else if ( architecture == Arch_ppc64 )
158  {
159  const char * platform = (const char *)getauxval( AT_PLATFORM );
160  int powerlvl;
161  if ( platform && sscanf( platform, "power%d", &powerlvl ) == 1 && powerlvl > 6 )
162  architecture = Arch_ppc64p7;
163  }
164 #endif
165  return architecture;
166  }
167 
185  Locale _autodetectTextLocale()
186  {
187  Locale ret( "en" );
188  const char * envlist[] = { "LC_ALL", "LC_MESSAGES", "LANG", NULL };
189  for ( const char ** envvar = envlist; *envvar; ++envvar )
190  {
191  const char * envlang = getenv( *envvar );
192  if ( envlang )
193  {
194  std::string envstr( envlang );
195  if ( envstr != "POSIX" && envstr != "C" )
196  {
197  Locale lang( envstr );
198  if ( ! lang.code().empty() )
199  {
200  MIL << "Found " << *envvar << "=" << envstr << endl;
201  ret = lang;
202  break;
203  }
204  }
205  }
206  }
207  MIL << "Default text locale is '" << ret << "'" << endl;
208 #warning HACK AROUND BOOST_TEST_CATCH_SYSTEM_ERRORS
209  setenv( "BOOST_TEST_CATCH_SYSTEM_ERRORS", "no", 1 );
210  return ret;
211  }
212 
214  } // namespace zypp
216 
218  template<class _Tp>
219  struct Option
220  {
221  typedef _Tp value_type;
222 
224  Option( const value_type & initial_r )
225  : _val( initial_r )
226  {}
227 
229  const value_type & get() const
230  { return _val; }
231 
233  operator const value_type &() const
234  { return _val; }
235 
237  void set( const value_type & newval_r )
238  { _val = newval_r; }
239 
241  value_type & ref()
242  { return _val; }
243 
244  private:
245  value_type _val;
246  };
247 
249  template<class _Tp>
250  struct DefaultOption : public Option<_Tp>
251  {
252  typedef _Tp value_type;
254 
255  DefaultOption( const value_type & initial_r )
256  : Option<_Tp>( initial_r ), _default( initial_r )
257  {}
258 
261  { this->set( _default.get() ); }
262 
264  void restoreToDefault( const value_type & newval_r )
265  { setDefault( newval_r ); restoreToDefault(); }
266 
268  const value_type & getDefault() const
269  { return _default.get(); }
270 
272  void setDefault( const value_type & newval_r )
273  { _default.set( newval_r ); }
274 
275  private:
276  option_type _default;
277  };
278 
280  //
281  // CLASS NAME : ZConfig::Impl
282  //
289  {
290  public:
291  Impl( const Pathname & override_r = Pathname() )
292  : _parsedZyppConf ( override_r )
293  , cfg_arch ( defaultSystemArchitecture() )
294  , cfg_textLocale ( defaultTextLocale() )
295  , updateMessagesNotify ( "single | /usr/lib/zypp/notify-message -p %p" )
296  , repo_add_probe ( false )
297  , repo_refresh_delay ( 10 )
298  , repoLabelIsAlias ( false )
299  , download_use_deltarpm ( true )
300  , download_use_deltarpm_always ( false )
301  , download_media_prefer_download( true )
302  , download_max_concurrent_connections( 5 )
303  , download_min_download_speed ( 0 )
304  , download_max_download_speed ( 0 )
305  , download_max_silent_tries ( 5 )
306  , download_transfer_timeout ( 180 )
307  , commit_downloadMode ( DownloadDefault )
308  , gpgCheck ( true )
309  , repoGpgCheck ( indeterminate )
310  , pkgGpgCheck ( indeterminate )
311  , solver_onlyRequires ( false )
312  , solver_allowVendorChange ( false )
313  , solver_cleandepsOnRemove ( false )
314  , solver_upgradeTestcasesToKeep ( 2 )
315  , solverUpgradeRemoveDroppedPackages( true )
316  , apply_locks_file ( true )
317  , pluginsPath ( "/usr/lib/zypp/plugins" )
318  {
319  MIL << "libzypp: " << VERSION << " built " << __DATE__ << " " << __TIME__ << endl;
320  // override_r has higest prio
321  // ZYPP_CONF might override /etc/zypp/zypp.conf
322  if ( _parsedZyppConf.empty() )
323  {
324  const char *env_confpath = getenv( "ZYPP_CONF" );
325  _parsedZyppConf = env_confpath ? env_confpath : "/etc/zypp/zypp.conf";
326  }
327  else
328  {
329  // Inject this into ZConfig. Be shure this is
330  // allocated via new. See: reconfigureZConfig
331  INT << "Reconfigure to " << _parsedZyppConf << endl;
332  ZConfig::instance()._pimpl.reset( this );
333  }
334  if ( PathInfo(_parsedZyppConf).isExist() )
335  {
336  parser::IniDict dict( _parsedZyppConf );
338  sit != dict.sectionsEnd();
339  ++sit )
340  {
341  string section(*sit);
342  //MIL << section << endl;
343  for ( IniDict::entry_const_iterator it = dict.entriesBegin(*sit);
344  it != dict.entriesEnd(*sit);
345  ++it )
346  {
347  string entry(it->first);
348  string value(it->second);
349  //DBG << (*it).first << "=" << (*it).second << endl;
350  if ( section == "main" )
351  {
352  if ( entry == "arch" )
353  {
354  Arch carch( value );
355  if ( carch != cfg_arch )
356  {
357  WAR << "Overriding system architecture (" << cfg_arch << "): " << carch << endl;
358  cfg_arch = carch;
359  }
360  }
361  else if ( entry == "cachedir" )
362  {
363  cfg_cache_path = Pathname(value);
364  }
365  else if ( entry == "metadatadir" )
366  {
367  cfg_metadata_path = Pathname(value);
368  }
369  else if ( entry == "solvfilesdir" )
370  {
371  cfg_solvfiles_path = Pathname(value);
372  }
373  else if ( entry == "packagesdir" )
374  {
375  cfg_packages_path = Pathname(value);
376  }
377  else if ( entry == "configdir" )
378  {
379  cfg_config_path = Pathname(value);
380  }
381  else if ( entry == "reposdir" )
382  {
383  cfg_known_repos_path = Pathname(value);
384  }
385  else if ( entry == "servicesdir" )
386  {
387  cfg_known_services_path = Pathname(value);
388  }
389  else if ( entry == "repo.add.probe" )
390  {
391  repo_add_probe = str::strToBool( value, repo_add_probe );
392  }
393  else if ( entry == "repo.refresh.delay" )
394  {
395  str::strtonum(value, repo_refresh_delay);
396  }
397  else if ( entry == "repo.refresh.locales" )
398  {
399  std::vector<std::string> tmp;
400  str::split( value, back_inserter( tmp ), ", \t" );
401 
402  boost::function<Locale(const std::string &)> transform(
403  [](const std::string & str_r)->Locale{ return Locale(str_r); }
404  );
405  repoRefreshLocales.insert( make_transform_iterator( tmp.begin(), transform ),
406  make_transform_iterator( tmp.end(), transform ) );
407  }
408  else if ( entry == "download.use_deltarpm" )
409  {
410  download_use_deltarpm = str::strToBool( value, download_use_deltarpm );
411  }
412  else if ( entry == "download.use_deltarpm.always" )
413  {
414  download_use_deltarpm_always = str::strToBool( value, download_use_deltarpm_always );
415  }
416  else if ( entry == "download.media_preference" )
417  {
418  download_media_prefer_download.restoreToDefault( str::compareCI( value, "volatile" ) != 0 );
419  }
420  else if ( entry == "download.max_concurrent_connections" )
421  {
422  str::strtonum(value, download_max_concurrent_connections);
423  }
424  else if ( entry == "download.min_download_speed" )
425  {
426  str::strtonum(value, download_min_download_speed);
427  }
428  else if ( entry == "download.max_download_speed" )
429  {
430  str::strtonum(value, download_max_download_speed);
431  }
432  else if ( entry == "download.max_silent_tries" )
433  {
434  str::strtonum(value, download_max_silent_tries);
435  }
436  else if ( entry == "download.transfer_timeout" )
437  {
438  str::strtonum(value, download_transfer_timeout);
439  if ( download_transfer_timeout < 0 ) download_transfer_timeout = 0;
440  else if ( download_transfer_timeout > 3600 ) download_transfer_timeout = 3600;
441  }
442  else if ( entry == "commit.downloadMode" )
443  {
444  commit_downloadMode.set( deserializeDownloadMode( value ) );
445  }
446  else if ( entry == "gpgcheck" )
447  {
448  gpgCheck.set( str::strToBool( value, gpgCheck ) );
449  }
450  else if ( entry == "repo_gpgcheck" )
451  {
452  repoGpgCheck.set( str::strToTriBool( value ) );
453  }
454  else if ( entry == "pkg_gpgcheck" )
455  {
456  pkgGpgCheck.set( str::strToTriBool( value ) );
457  }
458  else if ( entry == "vendordir" )
459  {
460  cfg_vendor_path = Pathname(value);
461  }
462  else if ( entry == "multiversiondir" )
463  {
464  cfg_multiversion_path = Pathname(value);
465  }
466  else if ( entry == "solver.onlyRequires" )
467  {
468  solver_onlyRequires.set( str::strToBool( value, solver_onlyRequires ) );
469  }
470  else if ( entry == "solver.allowVendorChange" )
471  {
472  solver_allowVendorChange.set( str::strToBool( value, solver_allowVendorChange ) );
473  }
474  else if ( entry == "solver.cleandepsOnRemove" )
475  {
476  solver_cleandepsOnRemove.set( str::strToBool( value, solver_cleandepsOnRemove ) );
477  }
478  else if ( entry == "solver.upgradeTestcasesToKeep" )
479  {
480  solver_upgradeTestcasesToKeep.set( str::strtonum<unsigned>( value ) );
481  }
482  else if ( entry == "solver.upgradeRemoveDroppedPackages" )
483  {
484  solverUpgradeRemoveDroppedPackages.restoreToDefault( str::strToBool( value, solverUpgradeRemoveDroppedPackages.getDefault() ) );
485  }
486  else if ( entry == "solver.checkSystemFile" )
487  {
488  solver_checkSystemFile = Pathname(value);
489  }
490  else if ( entry == "solver.checkSystemFileDir" )
491  {
492  solver_checkSystemFileDir = Pathname(value);
493  }
494  else if ( entry == "multiversion" )
495  {
496  str::split( value, inserter( _multiversion, _multiversion.end() ), ", \t" );
497  }
498  else if ( entry == "locksfile.path" )
499  {
500  locks_file = Pathname(value);
501  }
502  else if ( entry == "locksfile.apply" )
503  {
504  apply_locks_file = str::strToBool( value, apply_locks_file );
505  }
506  else if ( entry == "update.datadir" )
507  {
508  update_data_path = Pathname(value);
509  }
510  else if ( entry == "update.scriptsdir" )
511  {
512  update_scripts_path = Pathname(value);
513  }
514  else if ( entry == "update.messagessdir" )
515  {
516  update_messages_path = Pathname(value);
517  }
518  else if ( entry == "update.messages.notify" )
519  {
520  updateMessagesNotify.set( value );
521  }
522  else if ( entry == "rpm.install.excludedocs" )
523  {
524  rpmInstallFlags.setFlag( target::rpm::RPMINST_EXCLUDEDOCS,
525  str::strToBool( value, false ) );
526  }
527  else if ( entry == "history.logfile" )
528  {
529  history_log_path = Pathname(value);
530  }
531  else if ( entry == "credentials.global.dir" )
532  {
533  credentials_global_dir_path = Pathname(value);
534  }
535  else if ( entry == "credentials.global.file" )
536  {
537  credentials_global_file_path = Pathname(value);
538  }
539  }
540  }
541  }
542  }
543  else
544  {
545  MIL << _parsedZyppConf << " not found, using defaults instead." << endl;
546  _parsedZyppConf = _parsedZyppConf.extend( " (NOT FOUND)" );
547  }
548 
549  // legacy:
550  if ( getenv( "ZYPP_TESTSUITE_FAKE_ARCH" ) )
551  {
552  Arch carch( getenv( "ZYPP_TESTSUITE_FAKE_ARCH" ) );
553  if ( carch != cfg_arch )
554  {
555  WAR << "ZYPP_TESTSUITE_FAKE_ARCH: Overriding system architecture (" << cfg_arch << "): " << carch << endl;
556  cfg_arch = carch;
557  }
558  }
559  MIL << "ZConfig singleton created." << endl;
560  }
561 
563  {}
564 
565  public:
567  Pathname _parsedZyppConf;
568 
571 
572  Pathname cfg_cache_path;
576 
577  Pathname cfg_config_path;
580 
581  Pathname cfg_vendor_path;
583  Pathname locks_file;
584 
589 
594 
598 
604 
606 
610 
616 
619 
620  std::set<std::string> & multiversion() { return getMultiversion(); }
621  const std::set<std::string> & multiversion() const { return getMultiversion(); }
622 
624 
625  target::rpm::RpmInstFlags rpmInstallFlags;
626 
630 
631  std::string userData;
632 
634 
635  private:
636  std::set<std::string> & getMultiversion() const
637  {
638  if ( ! _multiversionInitialized )
639  {
640  Pathname multiversionDir( cfg_multiversion_path );
641  if ( multiversionDir.empty() )
642  multiversionDir = ( cfg_config_path.empty() ? Pathname("/etc/zypp") : cfg_config_path ) / "multiversion.d";
643 
644  filesystem::dirForEach( multiversionDir,
645  [this]( const Pathname & dir_r, const char *const & name_r )->bool
646  {
647  MIL << "Parsing " << dir_r/name_r << endl;
648  iostr::simpleParseFile( InputStream( dir_r/name_r ),
649  [this]( int num_r, std::string line_r )->bool
650  {
651  DBG << " found " << line_r << endl;
652  _multiversion.insert( line_r );
653  return true;
654  } );
655  return true;
656  } );
657  _multiversionInitialized = true;
658  }
659  return _multiversion;
660  }
661  mutable std::set<std::string> _multiversion;
663  };
665 
666  // Backdoor to redirect ZConfig from within the running
667  // TEST-application. HANDLE WITH CARE!
668  void reconfigureZConfig( const Pathname & override_r )
669  {
670  // ctor puts itself unter smart pointer control.
671  new ZConfig::Impl( override_r );
672  }
673 
675  //
676  // METHOD NAME : ZConfig::instance
677  // METHOD TYPE : ZConfig &
678  //
679  ZConfig & ZConfig::instance()
680  {
681  static ZConfig _instance; // The singleton
682  return _instance;
683  }
684 
686  //
687  // METHOD NAME : ZConfig::ZConfig
688  // METHOD TYPE : Ctor
689  //
690  ZConfig::ZConfig()
691  : _pimpl( new Impl )
692  {
693  about( MIL );
694  }
695 
697  //
698  // METHOD NAME : ZConfig::~ZConfig
699  // METHOD TYPE : Dtor
700  //
702  {}
703 
704  Pathname ZConfig::systemRoot() const
705  {
706  Target_Ptr target( getZYpp()->getTarget() );
707  return target ? target->root() : Pathname();
708  }
709 
711  //
712  // system architecture
713  //
715 
717  {
718  static Arch _val( _autodetectSystemArchitecture() );
719  return _val;
720  }
721 
723  { return _pimpl->cfg_arch; }
724 
725  void ZConfig::setSystemArchitecture( const Arch & arch_r )
726  {
727  if ( arch_r != _pimpl->cfg_arch )
728  {
729  WAR << "Overriding system architecture (" << _pimpl->cfg_arch << "): " << arch_r << endl;
730  _pimpl->cfg_arch = arch_r;
731  }
732  }
733 
735  //
736  // text locale
737  //
739 
741  {
742  static Locale _val( _autodetectTextLocale() );
743  return _val;
744  }
745 
747  { return _pimpl->cfg_textLocale; }
748 
749  void ZConfig::setTextLocale( const Locale & locale_r )
750  {
751  if ( locale_r != _pimpl->cfg_textLocale )
752  {
753  WAR << "Overriding text locale (" << _pimpl->cfg_textLocale << "): " << locale_r << endl;
754  _pimpl->cfg_textLocale = locale_r;
755 #warning prefer signal
756  sat::Pool::instance().setTextLocale( locale_r );
757  }
758  }
759 
761  // user data
763 
764  bool ZConfig::hasUserData() const
765  { return !_pimpl->userData.empty(); }
766 
767  std::string ZConfig::userData() const
768  { return _pimpl->userData; }
769 
770  bool ZConfig::setUserData( const std::string & str_r )
771  {
772  for_( ch, str_r.begin(), str_r.end() )
773  {
774  if ( *ch < ' ' && *ch != '\t' )
775  {
776  ERR << "New user data string rejectded: char " << (int)*ch << " at position " << (ch - str_r.begin()) << endl;
777  return false;
778  }
779  }
780  MIL << "Set user data string to '" << str_r << "'" << endl;
781  _pimpl->userData = str_r;
782  return true;
783  }
784 
786 
787  Pathname ZConfig::repoCachePath() const
788  {
789  return ( _pimpl->cfg_cache_path.empty()
790  ? Pathname("/var/cache/zypp") : _pimpl->cfg_cache_path );
791  }
792 
793  Pathname ZConfig::repoMetadataPath() const
794  {
795  return ( _pimpl->cfg_metadata_path.empty()
796  ? (repoCachePath()/"raw") : _pimpl->cfg_metadata_path );
797  }
798 
799  Pathname ZConfig::repoSolvfilesPath() const
800  {
801  return ( _pimpl->cfg_solvfiles_path.empty()
802  ? (repoCachePath()/"solv") : _pimpl->cfg_solvfiles_path );
803  }
804 
805  Pathname ZConfig::repoPackagesPath() const
806  {
807  return ( _pimpl->cfg_packages_path.empty()
808  ? (repoCachePath()/"packages") : _pimpl->cfg_packages_path );
809  }
810 
812 
813  Pathname ZConfig::configPath() const
814  {
815  return ( _pimpl->cfg_config_path.empty()
816  ? Pathname("/etc/zypp") : _pimpl->cfg_config_path );
817  }
818 
819  Pathname ZConfig::knownReposPath() const
820  {
821  return ( _pimpl->cfg_known_repos_path.empty()
822  ? (configPath()/"repos.d") : _pimpl->cfg_known_repos_path );
823  }
824 
825  Pathname ZConfig::knownServicesPath() const
826  {
827  return ( _pimpl->cfg_known_services_path.empty()
828  ? (configPath()/"services.d") : _pimpl->cfg_known_services_path );
829  }
830 
831  Pathname ZConfig::vendorPath() const
832  {
833  return ( _pimpl->cfg_vendor_path.empty()
834  ? (configPath()/"vendors.d") : _pimpl->cfg_vendor_path );
835  }
836 
837  Pathname ZConfig::locksFile() const
838  {
839  return ( _pimpl->locks_file.empty()
840  ? (configPath()/"locks") : _pimpl->locks_file );
841  }
842 
844 
846  { return _pimpl->repo_add_probe; }
847 
849  { return _pimpl->repo_refresh_delay; }
850 
852  { return _pimpl->repoRefreshLocales.empty() ? Target::requestedLocales("") :_pimpl->repoRefreshLocales; }
853 
855  { return _pimpl->repoLabelIsAlias; }
856 
857  void ZConfig::repoLabelIsAlias( bool yesno_r )
858  { _pimpl->repoLabelIsAlias = yesno_r; }
859 
861  { return _pimpl->download_use_deltarpm; }
862 
864  { return download_use_deltarpm() && _pimpl->download_use_deltarpm_always; }
865 
867  { return _pimpl->download_media_prefer_download; }
868 
870  { _pimpl->download_media_prefer_download.set( yesno_r ); }
871 
873  { _pimpl->download_media_prefer_download.restoreToDefault(); }
874 
876  { return _pimpl->download_max_concurrent_connections; }
877 
879  { return _pimpl->download_min_download_speed; }
880 
882  { return _pimpl->download_max_download_speed; }
883 
885  { return _pimpl->download_max_silent_tries; }
886 
888  { return _pimpl->download_transfer_timeout; }
889 
891  { return _pimpl->commit_downloadMode; }
892 
893  bool ZConfig::gpgCheck() const
894  { return _pimpl->gpgCheck; }
895 
897  { return _pimpl->repoGpgCheck; }
898 
900  { return _pimpl->pkgGpgCheck; }
901 
903  { return _pimpl->solver_onlyRequires; }
904 
906  { return _pimpl->solver_allowVendorChange; }
907 
909  { return _pimpl->solver_cleandepsOnRemove; }
910 
912  { return ( _pimpl->solver_checkSystemFile.empty()
913  ? (configPath()/"systemCheck") : _pimpl->solver_checkSystemFile ); }
914 
916  { return ( _pimpl->solver_checkSystemFileDir.empty()
917  ? (configPath()/"systemCheck.d") : _pimpl->solver_checkSystemFileDir ); }
918 
920  { return _pimpl->solver_upgradeTestcasesToKeep; }
921 
922  bool ZConfig::solverUpgradeRemoveDroppedPackages() const { return _pimpl->solverUpgradeRemoveDroppedPackages; }
923  void ZConfig::setSolverUpgradeRemoveDroppedPackages( bool val_r ) { _pimpl->solverUpgradeRemoveDroppedPackages.set( val_r ); }
924  void ZConfig::resetSolverUpgradeRemoveDroppedPackages() { _pimpl->solverUpgradeRemoveDroppedPackages.restoreToDefault(); }
925 
926  const std::set<std::string> & ZConfig::multiversionSpec() const { return _pimpl->multiversion(); }
927  void ZConfig::multiversionSpec( std::set<std::string> new_r ) { _pimpl->multiversion().swap( new_r ); }
928  void ZConfig::clearMultiversionSpec() { _pimpl->multiversion().clear(); }
929  void ZConfig::addMultiversionSpec( const std::string & name_r ) { _pimpl->multiversion().insert( name_r ); }
930  void ZConfig::removeMultiversionSpec( const std::string & name_r ) { _pimpl->multiversion().erase( name_r ); }
931 
933  { return _pimpl->apply_locks_file; }
934 
935  Pathname ZConfig::update_dataPath() const
936  {
937  return ( _pimpl->update_data_path.empty()
938  ? Pathname("/var/adm") : _pimpl->update_data_path );
939  }
940 
942  {
943  return ( _pimpl->update_messages_path.empty()
944  ? Pathname(update_dataPath()/"update-messages") : _pimpl->update_messages_path );
945  }
946 
948  {
949  return ( _pimpl->update_scripts_path.empty()
950  ? Pathname(update_dataPath()/"update-scripts") : _pimpl->update_scripts_path );
951  }
952 
953  std::string ZConfig::updateMessagesNotify() const
954  { return _pimpl->updateMessagesNotify; }
955 
956  void ZConfig::setUpdateMessagesNotify( const std::string & val_r )
957  { _pimpl->updateMessagesNotify.set( val_r ); }
958 
960  { _pimpl->updateMessagesNotify.restoreToDefault(); }
961 
963 
964  target::rpm::RpmInstFlags ZConfig::rpmInstallFlags() const
965  { return _pimpl->rpmInstallFlags; }
966 
967 
968  Pathname ZConfig::historyLogFile() const
969  {
970  return ( _pimpl->history_log_path.empty() ?
971  Pathname("/var/log/zypp/history") : _pimpl->history_log_path );
972  }
973 
975  {
976  return ( _pimpl->credentials_global_dir_path.empty() ?
977  Pathname("/etc/zypp/credentials.d") : _pimpl->credentials_global_dir_path );
978  }
979 
981  {
982  return ( _pimpl->credentials_global_file_path.empty() ?
983  Pathname("/etc/zypp/credentials.cat") : _pimpl->credentials_global_file_path );
984  }
985 
987 
988  std::string ZConfig::distroverpkg() const
989  { return "redhat-release"; }
990 
992 
993  Pathname ZConfig::pluginsPath() const
994  { return _pimpl->pluginsPath.get(); }
995 
997 
998  std::ostream & ZConfig::about( std::ostream & str ) const
999  {
1000  str << "libzypp: " << VERSION << " built " << __DATE__ << " " << __TIME__ << endl;
1001 
1002  str << "libsolv: " << solv_version;
1003  if ( ::strcmp( solv_version, LIBSOLV_VERSION_STRING ) )
1004  str << " (built against " << LIBSOLV_VERSION_STRING << ")";
1005  str << endl;
1006 
1007  str << "zypp.conf: '" << _pimpl->_parsedZyppConf << "'" << endl;
1008  str << "TextLocale: '" << textLocale() << "' (" << defaultTextLocale() << ")" << endl;
1009  str << "SystemArchitecture: '" << systemArchitecture() << "' (" << defaultSystemArchitecture() << ")" << endl;
1010  return str;
1011  }
1012 
1014 } // namespace zypp
~ZConfig()
Dtor.
Definition: ZConfig.cc:701
TriBool strToTriBool(const C_Str &str)
Parse str into a bool if it's a legal true or false string; else indterminate.
Definition: String.cc:91
static Locale defaultTextLocale()
The autodetected prefered locale for translated texts.
Definition: ZConfig.cc:740
Mutable option.
Definition: ZConfig.cc:219
DefaultOption(const value_type &initial_r)
Definition: ZConfig.cc:255
#define MIL
Definition: Logger.h:64
Pathname update_scripts_path
Definition: ZConfig.cc:586
Pathname cfg_known_repos_path
Definition: ZConfig.cc:578
int download_transfer_timeout
Definition: ZConfig.cc:603
MapKVIteratorTraits< SectionSet >::Key_const_iterator section_const_iterator
Definition: IniDict.h:46
Option< unsigned > solver_upgradeTestcasesToKeep
Definition: ZConfig.cc:614
void setUpdateMessagesNotify(const std::string &val_r)
Set a new command definition (see update.messages.notify in zypp.conf).
Definition: ZConfig.cc:956
Option< bool > solver_cleandepsOnRemove
Definition: ZConfig.cc:613
TriBool repoGpgCheck() const
Check repo matadata signatures (indeterminate - according to gpgcheck)
Definition: ZConfig.cc:896
Pathname solver_checkSystemFileDir() const
Directory, which may or may not contain files in which dependencies described which has to be fulfill...
Definition: ZConfig.cc:915
Pathname cfg_known_services_path
Definition: ZConfig.cc:579
Option< TriBool > repoGpgCheck
Definition: ZConfig.cc:608
int download_max_concurrent_connections
Definition: ZConfig.cc:599
std::ostream & about(std::ostream &str) const
Print some detail about the current libzypp version.
Definition: ZConfig.cc:998
Pathname update_messages_path
Definition: ZConfig.cc:587
Option< bool > gpgCheck
Definition: ZConfig.cc:607
std::string distroverpkg() const
Package telling the "product version" on systems not using /etc/product.d/baseproduct.
Definition: ZConfig.cc:988
unsigned split(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=" \t")
Split line_r into words.
Definition: String.h:471
unsigned solver_upgradeTestcasesToKeep() const
When committing a dist upgrade (e.g.
Definition: ZConfig.cc:919
void setTextLocale(const Locale &locale_r)
Set the default language for retrieving translated texts.
Definition: Pool.cc:212
Architecture.
Definition: Arch.h:36
bool download_use_deltarpm
Definition: ZConfig.cc:595
Pathname knownServicesPath() const
Path where the known services .service files are kept (configPath()/services.d).
Definition: ZConfig.cc:825
Pathname vendorPath() const
Directory for equivalent vendor definitions (configPath()/vendors.d)
Definition: ZConfig.cc:831
Pathname repoCachePath() const
Path where the caches are kept (/var/cache/zypp)
Definition: ZConfig.cc:787
LocaleSet repoRefreshLocales
Definition: ZConfig.cc:592
#define INT
Definition: Logger.h:68
Pathname credentialsGlobalFile() const
Defaults to /etc/zypp/credentials.cat.
Definition: ZConfig.cc:980
Pathname cfg_metadata_path
Definition: ZConfig.cc:573
String related utilities and Regular expression matching.
Option< _Tp > option_type
Definition: ZConfig.cc:253
void removeMultiversionSpec(const std::string &name_r)
Definition: ZConfig.cc:930
Pathname cfg_cache_path
Definition: ZConfig.cc:572
Definition: Arch.h:330
void setSystemArchitecture(const Arch &arch_r)
Override the zypp system architecture.
Definition: ZConfig.cc:725
bool apply_locks_file() const
Whether locks file should be read and applied after start (true)
Definition: ZConfig.cc:932
Pathname cfg_config_path
Definition: ZConfig.cc:577
target::rpm::RpmInstFlags rpmInstallFlags
Definition: ZConfig.cc:625
Helper to create and pass std::istream.
Definition: InputStream.h:56
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
void reconfigureZConfig(const Pathname &override_r)
Definition: ZConfig.cc:668
long download_max_download_speed() const
Maximum download speed (bytes per second)
Definition: ZConfig.cc:881
bool setUserData(const std::string &str_r)
Set a new userData string.
Definition: ZConfig.cc:770
bool solver_cleandepsOnRemove() const
Whether removing a package should also remove no longer needed requirements.
Definition: ZConfig.cc:908
bool repo_add_probe() const
Whether repository urls should be probed.
Definition: ZConfig.cc:845
const std::set< std::string > & multiversion() const
Definition: ZConfig.cc:621
void resetSolverUpgradeRemoveDroppedPackages()
Reset solverUpgradeRemoveDroppedPackages to the zypp.conf default.
Definition: ZConfig.cc:924
Pathname _parsedZyppConf
Remember any parsed zypp.conf.
Definition: ZConfig.cc:567
Pathname pluginsPath() const
Defaults to /usr/lib/zypp/plugins.
Definition: ZConfig.cc:993
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
Pointer to implementation.
Definition: ZConfig.h:453
#define ERR
Definition: Logger.h:66
bool solverUpgradeRemoveDroppedPackages() const
Whether dist upgrade should remove a products dropped packages (true).
Definition: ZConfig.cc:922
DownloadMode commit_downloadMode() const
Commit download policy to use as default.
Definition: ZConfig.cc:890
Option< bool > solver_allowVendorChange
Definition: ZConfig.cc:612
void addMultiversionSpec(const std::string &name_r)
Definition: ZConfig.cc:929
Pathname credentials_global_dir_path
Definition: ZConfig.cc:628
void set_download_media_prefer_download(bool yesno_r)
Set download_media_prefer_download to a specific value.
Definition: ZConfig.cc:869
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:29
DefaultOption< bool > download_media_prefer_download
Definition: ZConfig.cc:597
const value_type & getDefault() const
Get the current default value.
Definition: ZConfig.cc:268
Pathname configPath() const
Path where the configfiles are kept (/etc/zypp).
Definition: ZConfig.cc:813
Pathname historyLogFile() const
Path where ZYpp install history is logged.
Definition: ZConfig.cc:968
void setTextLocale(const Locale &locale_r)
Set the prefered locale for translated texts.
Definition: ZConfig.cc:749
int simpleParseFile(std::istream &str_r, ParseFlags flags_r, function< bool(int, std::string)> consume_r)
Simple lineparser optionally trimming and skipping comments.
Definition: IOStream.cc:124
Pathname knownReposPath() const
Path where the known repositories .repo files are kept (configPath()/repos.d).
Definition: ZConfig.cc:819
static Pool instance()
Singleton ctor.
Definition: Pool.h:52
Pathname update_data_path
Definition: ZConfig.cc:585
Pathname credentials_global_file_path
Definition: ZConfig.cc:629
LocaleSet repoRefreshLocales() const
List of locales for which translated package descriptions should be downloaded.
Definition: ZConfig.cc:851
bool gpgCheck() const
Turn signature checking on/off (on)
Definition: ZConfig.cc:893
void set_default_download_media_prefer_download()
Set download_media_prefer_download to the configfiles default.
Definition: ZConfig.cc:872
void restoreToDefault(const value_type &newval_r)
Reset value to a new default.
Definition: ZConfig.cc:264
ZConfig implementation.
Definition: ZConfig.cc:288
void setDefault(const value_type &newval_r)
Set a new default value.
Definition: ZConfig.cc:272
libzypp will decide what to do.
Definition: DownloadMode.h:24
TriBool pkgGpgCheck() const
Check rpm package signatures (indeterminate - according to gpgcheck)
Definition: ZConfig.cc:899
void restoreToDefault()
Reset value to the current default.
Definition: ZConfig.cc:260
Interim helper class to collect global options and settings.
Definition: ZConfig.h:59
#define WAR
Definition: Logger.h:65
Pathname cfg_packages_path
Definition: ZConfig.cc:575
section_const_iterator sectionsBegin() const
Definition: IniDict.cc:94
Types and functions for filesystem operations.
Definition: Glob.cc:23
Option< TriBool > pkgGpgCheck
Definition: ZConfig.cc:609
Pathname update_scriptsPath() const
Path where the repo metadata is downloaded and kept (update_dataPath()/).
Definition: ZConfig.cc:947
Pathname locksFile() const
Path where zypp can find or create lock file (configPath()/locks)
Definition: ZConfig.cc:837
std::tr1::unordered_set< Locale > LocaleSet
Definition: Locale.h:28
long download_min_download_speed() const
Minimum download speed (bytes per second) until the connection is dropped.
Definition: ZConfig.cc:878
void clearMultiversionSpec()
Definition: ZConfig.cc:928
entry_const_iterator entriesEnd(const std::string &section) const
Definition: IniDict.cc:82
bool hasUserData() const
Whether a (non empty) user data sting is defined.
Definition: ZConfig.cc:764
int download_max_silent_tries
Definition: ZConfig.cc:602
Pathname update_messagesPath() const
Path where the repo solv files are created and kept (update_dataPath()/solv).
Definition: ZConfig.cc:941
_It strtonum(const C_Str &str)
Parsing numbers from string.
Definition: String.h:356
Pathname locks_file
Definition: ZConfig.cc:583
Pathname repoSolvfilesPath() const
Path where the repo solv files are created and kept (repoCachePath()/solv).
Definition: ZConfig.cc:799
Pathname repoPackagesPath() const
Path where the repo packages are downloaded and kept (repoCachePath()/packages).
Definition: ZConfig.cc:805
bool download_use_deltarpm() const
Whether to consider using a deltarpm when downloading a package.
Definition: ZConfig.cc:860
Locale cfg_textLocale
Definition: ZConfig.cc:570
Mutable option with initial value also remembering a config value.
Definition: ZConfig.cc:250
Pathname repoMetadataPath() const
Path where the repo metadata is downloaded and kept (repoCachePath()/raw).
Definition: ZConfig.cc:793
value_type & ref()
Non-const reference to set a new value.
Definition: ZConfig.cc:241
long download_max_silent_tries() const
Maximum silent tries.
Definition: ZConfig.cc:884
bool download_use_deltarpm_always
Definition: ZConfig.cc:596
std::set< std::string > & getMultiversion() const
Definition: ZConfig.cc:636
int compareCI(const C_Str &lhs, const C_Str &rhs)
Definition: String.h:921
bool solver_allowVendorChange() const
Whether vendor check is by default enabled.
Definition: ZConfig.cc:905
bool solver_onlyRequires() const
Solver regards required packages,patterns,...
Definition: ZConfig.cc:902
Option< Pathname > pluginsPath
Definition: ZConfig.cc:633
Impl(const Pathname &override_r=Pathname())
Definition: ZConfig.cc:291
Parses a INI file and offers its structure as a dictionary.
Definition: IniDict.h:40
std::set< std::string > & multiversion()
Definition: ZConfig.cc:620
static Arch defaultSystemArchitecture()
The autodetected system architecture.
Definition: ZConfig.cc:716
Pathname systemRoot() const
The target root directory.
Definition: ZConfig.cc:704
entry_const_iterator entriesBegin(const std::string &section) const
Definition: IniDict.cc:71
bool download_media_prefer_download() const
Hint which media to prefer when installing packages (download vs.
Definition: ZConfig.cc:866
DefaultOption< std::string > updateMessagesNotify
Definition: ZConfig.cc:588
const std::set< std::string > & multiversionSpec() const
Definition: ZConfig.cc:926
Pathname solver_checkSystemFile
Definition: ZConfig.cc:617
target::rpm::RpmInstFlags rpmInstallFlags() const
The default target::rpm::RpmInstFlags for ZYppCommitPolicy.
Definition: ZConfig.cc:964
_Tp value_type
Definition: ZConfig.cc:221
Option< bool > solver_onlyRequires
Definition: ZConfig.cc:611
Pathname history_log_path
Definition: ZConfig.cc:627
std::string userData
Definition: ZConfig.cc:631
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
Definition: String.h:397
Pathname update_dataPath() const
Path where the update items are kept (/var/adm)
Definition: ZConfig.cc:935
std::string userData() const
User defined string value to be passed to log, history, plugins...
Definition: ZConfig.cc:767
Option(const value_type &initial_r)
No default ctor, explicit initialisation!
Definition: ZConfig.cc:224
int download_max_download_speed
Definition: ZConfig.cc:601
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:220
void resetUpdateMessagesNotify()
Reset to the zypp.conf default.
Definition: ZConfig.cc:959
int dirForEach(const Pathname &dir_r, function< bool(const Pathname &, const char *const)> fnc_r)
Invoke callback function fnc_r for each entry in directory dir_r.
Definition: PathInfo.cc:552
DefaultIntegral< bool, false > _multiversionInitialized
Definition: ZConfig.cc:662
void setSolverUpgradeRemoveDroppedPackages(bool val_r)
Set solverUpgradeRemoveDroppedPackages to val_r.
Definition: ZConfig.cc:923
int download_min_download_speed
Definition: ZConfig.cc:600
void set(const value_type &newval_r)
Set a new value.
Definition: ZConfig.cc:237
Locale textLocale() const
The locale for translated texts zypp uses.
Definition: ZConfig.cc:746
std::string updateMessagesNotify() const
Command definition for sending update messages.
Definition: ZConfig.cc:953
EntrySet::const_iterator entry_const_iterator
Definition: IniDict.h:47
unsigned repo_refresh_delay() const
Amount of time in minutes that must pass before another refresh.
Definition: ZConfig.cc:848
Arch systemArchitecture() const
The system architecture zypp uses.
Definition: ZConfig.cc:722
Pathname solver_checkSystemFileDir
Definition: ZConfig.cc:618
bool repoLabelIsAlias() const
Whether to use repository alias or name in user messages (progress, exceptions, ...).
Definition: ZConfig.cc:854
Pathname cfg_vendor_path
Definition: ZConfig.cc:581
Pathname cfg_multiversion_path
Definition: ZConfig.cc:582
LocaleSet requestedLocales() const
Languages to be supported by the system.
Definition: Target.cc:109
DefaultOption< bool > solverUpgradeRemoveDroppedPackages
Definition: ZConfig.cc:615
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
section_const_iterator sectionsEnd() const
Definition: IniDict.cc:99
long download_max_concurrent_connections() const
Maximum number of concurrent connections for a single transfer.
Definition: ZConfig.cc:875
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition: String.h:986
option_type _default
Definition: ZConfig.cc:276
value_type _val
Definition: ZConfig.cc:245
Pathname solver_checkSystemFile() const
File in which dependencies described which has to be fulfilled for a running system.
Definition: ZConfig.cc:911
Option< DownloadMode > commit_downloadMode
Definition: ZConfig.cc:605
unsigned repo_refresh_delay
Definition: ZConfig.cc:591
bool download_use_deltarpm_always() const
Whether to consider using a deltarpm even when rpm is local.
Definition: ZConfig.cc:863
#define DBG
Definition: Logger.h:63
long download_transfer_timeout() const
Maximum time in seconds that you allow a transfer operation to take.
Definition: ZConfig.cc:887
Pathname credentialsGlobalDir() const
Defaults to /etc/zypp/credentials.d.
Definition: ZConfig.cc:974
DownloadMode
Supported commit download policies.
Definition: DownloadMode.h:22
Pathname cfg_solvfiles_path
Definition: ZConfig.cc:574
std::set< std::string > _multiversion
Definition: ZConfig.cc:661