libzypp  14.48.5
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 
242  { return _val; }
243 
244  private:
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:
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.restoreToDefault( str::strToBool( value, gpgCheck ) );
449  }
450  else if ( entry == "repo_gpgcheck" )
451  {
452  repoGpgCheck.restoreToDefault( str::strToTriBool( value ) );
453  }
454  else if ( entry == "pkg_gpgcheck" )
455  {
456  pkgGpgCheck.restoreToDefault( 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 == "multiversion" )
491  {
492  str::split( value, inserter( _multiversion, _multiversion.end() ), ", \t" );
493  }
494  else if ( entry == "locksfile.path" )
495  {
496  locks_file = Pathname(value);
497  }
498  else if ( entry == "locksfile.apply" )
499  {
500  apply_locks_file = str::strToBool( value, apply_locks_file );
501  }
502  else if ( entry == "update.datadir" )
503  {
504  update_data_path = Pathname(value);
505  }
506  else if ( entry == "update.scriptsdir" )
507  {
508  update_scripts_path = Pathname(value);
509  }
510  else if ( entry == "update.messagessdir" )
511  {
512  update_messages_path = Pathname(value);
513  }
514  else if ( entry == "update.messages.notify" )
515  {
516  updateMessagesNotify.set( value );
517  }
518  else if ( entry == "rpm.install.excludedocs" )
519  {
520  rpmInstallFlags.setFlag( target::rpm::RPMINST_EXCLUDEDOCS,
521  str::strToBool( value, false ) );
522  }
523  else if ( entry == "history.logfile" )
524  {
525  history_log_path = Pathname(value);
526  }
527  else if ( entry == "credentials.global.dir" )
528  {
529  credentials_global_dir_path = Pathname(value);
530  }
531  else if ( entry == "credentials.global.file" )
532  {
533  credentials_global_file_path = Pathname(value);
534  }
535  }
536  }
537  }
538  }
539  else
540  {
541  MIL << _parsedZyppConf << " not found, using defaults instead." << endl;
542  _parsedZyppConf = _parsedZyppConf.extend( " (NOT FOUND)" );
543  }
544 
545  // legacy:
546  if ( getenv( "ZYPP_TESTSUITE_FAKE_ARCH" ) )
547  {
548  Arch carch( getenv( "ZYPP_TESTSUITE_FAKE_ARCH" ) );
549  if ( carch != cfg_arch )
550  {
551  WAR << "ZYPP_TESTSUITE_FAKE_ARCH: Overriding system architecture (" << cfg_arch << "): " << carch << endl;
552  cfg_arch = carch;
553  }
554  }
555  MIL << "ZConfig singleton created." << endl;
556  }
557 
559  {}
560 
561  public:
563  Pathname _parsedZyppConf;
564 
567 
568  Pathname cfg_cache_path;
572 
573  Pathname cfg_config_path;
576 
577  Pathname cfg_vendor_path;
579  Pathname locks_file;
580 
585 
590 
594 
600 
602 
606 
612 
614 
615  std::set<std::string> & multiversion() { return getMultiversion(); }
616  const std::set<std::string> & multiversion() const { return getMultiversion(); }
617 
619 
620  target::rpm::RpmInstFlags rpmInstallFlags;
621 
625 
626  std::string userData;
627 
629 
630  private:
631  std::set<std::string> & getMultiversion() const
632  {
633  if ( ! _multiversionInitialized )
634  {
635  Pathname multiversionDir( cfg_multiversion_path );
636  if ( multiversionDir.empty() )
637  multiversionDir = ( cfg_config_path.empty() ? Pathname("/etc/zypp") : cfg_config_path ) / "multiversion.d";
638 
639  filesystem::dirForEach( multiversionDir,
640  [this]( const Pathname & dir_r, const char *const & name_r )->bool
641  {
642  MIL << "Parsing " << dir_r/name_r << endl;
643  iostr::simpleParseFile( InputStream( dir_r/name_r ),
644  [this]( int num_r, std::string line_r )->bool
645  {
646  DBG << " found " << line_r << endl;
647  _multiversion.insert( line_r );
648  return true;
649  } );
650  return true;
651  } );
652  _multiversionInitialized = true;
653  }
654  return _multiversion;
655  }
656  mutable std::set<std::string> _multiversion;
658  };
660 
661  // Backdoor to redirect ZConfig from within the running
662  // TEST-application. HANDLE WITH CARE!
663  void reconfigureZConfig( const Pathname & override_r )
664  {
665  // ctor puts itself unter smart pointer control.
666  new ZConfig::Impl( override_r );
667  }
668 
670  //
671  // METHOD NAME : ZConfig::instance
672  // METHOD TYPE : ZConfig &
673  //
674  ZConfig & ZConfig::instance()
675  {
676  static ZConfig _instance; // The singleton
677  return _instance;
678  }
679 
681  //
682  // METHOD NAME : ZConfig::ZConfig
683  // METHOD TYPE : Ctor
684  //
685  ZConfig::ZConfig()
686  : _pimpl( new Impl )
687  {
688  about( MIL );
689  }
690 
692  //
693  // METHOD NAME : ZConfig::~ZConfig
694  // METHOD TYPE : Dtor
695  //
697  {}
698 
699  Pathname ZConfig::systemRoot() const
700  {
701  Target_Ptr target( getZYpp()->getTarget() );
702  return target ? target->root() : Pathname();
703  }
704 
706  //
707  // system architecture
708  //
710 
712  {
713  static Arch _val( _autodetectSystemArchitecture() );
714  return _val;
715  }
716 
718  { return _pimpl->cfg_arch; }
719 
720  void ZConfig::setSystemArchitecture( const Arch & arch_r )
721  {
722  if ( arch_r != _pimpl->cfg_arch )
723  {
724  WAR << "Overriding system architecture (" << _pimpl->cfg_arch << "): " << arch_r << endl;
725  _pimpl->cfg_arch = arch_r;
726  }
727  }
728 
730  //
731  // text locale
732  //
734 
736  {
737  static Locale _val( _autodetectTextLocale() );
738  return _val;
739  }
740 
742  { return _pimpl->cfg_textLocale; }
743 
744  void ZConfig::setTextLocale( const Locale & locale_r )
745  {
746  if ( locale_r != _pimpl->cfg_textLocale )
747  {
748  WAR << "Overriding text locale (" << _pimpl->cfg_textLocale << "): " << locale_r << endl;
749  _pimpl->cfg_textLocale = locale_r;
750 #warning prefer signal
751  sat::Pool::instance().setTextLocale( locale_r );
752  }
753  }
754 
756  // user data
758 
759  bool ZConfig::hasUserData() const
760  { return !_pimpl->userData.empty(); }
761 
762  std::string ZConfig::userData() const
763  { return _pimpl->userData; }
764 
765  bool ZConfig::setUserData( const std::string & str_r )
766  {
767  for_( ch, str_r.begin(), str_r.end() )
768  {
769  if ( *ch < ' ' && *ch != '\t' )
770  {
771  ERR << "New user data string rejectded: char " << (int)*ch << " at position " << (ch - str_r.begin()) << endl;
772  return false;
773  }
774  }
775  MIL << "Set user data string to '" << str_r << "'" << endl;
776  _pimpl->userData = str_r;
777  return true;
778  }
779 
781 
782  Pathname ZConfig::repoCachePath() const
783  {
784  return ( _pimpl->cfg_cache_path.empty()
785  ? Pathname("/var/cache/zypp") : _pimpl->cfg_cache_path );
786  }
787 
788  Pathname ZConfig::repoMetadataPath() const
789  {
790  return ( _pimpl->cfg_metadata_path.empty()
791  ? (repoCachePath()/"raw") : _pimpl->cfg_metadata_path );
792  }
793 
794  Pathname ZConfig::repoSolvfilesPath() const
795  {
796  return ( _pimpl->cfg_solvfiles_path.empty()
797  ? (repoCachePath()/"solv") : _pimpl->cfg_solvfiles_path );
798  }
799 
800  Pathname ZConfig::repoPackagesPath() const
801  {
802  return ( _pimpl->cfg_packages_path.empty()
803  ? (repoCachePath()/"packages") : _pimpl->cfg_packages_path );
804  }
805 
807 
808  Pathname ZConfig::configPath() const
809  {
810  return ( _pimpl->cfg_config_path.empty()
811  ? Pathname("/etc/zypp") : _pimpl->cfg_config_path );
812  }
813 
814  Pathname ZConfig::knownReposPath() const
815  {
816  return ( _pimpl->cfg_known_repos_path.empty()
817  ? (configPath()/"repos.d") : _pimpl->cfg_known_repos_path );
818  }
819 
820  Pathname ZConfig::knownServicesPath() const
821  {
822  return ( _pimpl->cfg_known_services_path.empty()
823  ? (configPath()/"services.d") : _pimpl->cfg_known_services_path );
824  }
825 
826  Pathname ZConfig::vendorPath() const
827  {
828  return ( _pimpl->cfg_vendor_path.empty()
829  ? (configPath()/"vendors.d") : _pimpl->cfg_vendor_path );
830  }
831 
832  Pathname ZConfig::locksFile() const
833  {
834  return ( _pimpl->locks_file.empty()
835  ? (configPath()/"locks") : _pimpl->locks_file );
836  }
837 
839 
841  { return _pimpl->repo_add_probe; }
842 
844  { return _pimpl->repo_refresh_delay; }
845 
847  { return _pimpl->repoRefreshLocales.empty() ? Target::requestedLocales("") :_pimpl->repoRefreshLocales; }
848 
850  { return _pimpl->repoLabelIsAlias; }
851 
852  void ZConfig::repoLabelIsAlias( bool yesno_r )
853  { _pimpl->repoLabelIsAlias = yesno_r; }
854 
856  { return _pimpl->download_use_deltarpm; }
857 
859  { return download_use_deltarpm() && _pimpl->download_use_deltarpm_always; }
860 
862  { return _pimpl->download_media_prefer_download; }
863 
865  { _pimpl->download_media_prefer_download.set( yesno_r ); }
866 
868  { _pimpl->download_media_prefer_download.restoreToDefault(); }
869 
871  { return _pimpl->download_max_concurrent_connections; }
872 
874  { return _pimpl->download_min_download_speed; }
875 
877  { return _pimpl->download_max_download_speed; }
878 
880  { return _pimpl->download_max_silent_tries; }
881 
883  { return _pimpl->download_transfer_timeout; }
884 
886  { return _pimpl->commit_downloadMode; }
887 
888 
889  bool ZConfig::gpgCheck() const { return _pimpl->gpgCheck; }
890  TriBool ZConfig::repoGpgCheck() const { return _pimpl->repoGpgCheck; }
891  TriBool ZConfig::pkgGpgCheck() const { return _pimpl->pkgGpgCheck; }
892 
893  void ZConfig::setGpgCheck( bool val_r ) { _pimpl->gpgCheck.set( val_r ); }
894  void ZConfig::setRepoGpgCheck( TriBool val_r ) { _pimpl->repoGpgCheck.set( val_r ); }
895  void ZConfig::setPkgGpgCheck( TriBool val_r ) { _pimpl->pkgGpgCheck.set( val_r ); }
896 
897  void ZConfig::resetGpgCheck() { _pimpl->gpgCheck.restoreToDefault(); }
898  void ZConfig::resetRepoGpgCheck() { _pimpl->repoGpgCheck.restoreToDefault(); }
899  void ZConfig::resetPkgGpgCheck() { _pimpl->pkgGpgCheck.restoreToDefault(); }
900 
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_upgradeTestcasesToKeep; }
917 
918  bool ZConfig::solverUpgradeRemoveDroppedPackages() const { return _pimpl->solverUpgradeRemoveDroppedPackages; }
919  void ZConfig::setSolverUpgradeRemoveDroppedPackages( bool val_r ) { _pimpl->solverUpgradeRemoveDroppedPackages.set( val_r ); }
920  void ZConfig::resetSolverUpgradeRemoveDroppedPackages() { _pimpl->solverUpgradeRemoveDroppedPackages.restoreToDefault(); }
921 
922  const std::set<std::string> & ZConfig::multiversionSpec() const { return _pimpl->multiversion(); }
923  void ZConfig::multiversionSpec( std::set<std::string> new_r ) { _pimpl->multiversion().swap( new_r ); }
924  void ZConfig::clearMultiversionSpec() { _pimpl->multiversion().clear(); }
925  void ZConfig::addMultiversionSpec( const std::string & name_r ) { _pimpl->multiversion().insert( name_r ); }
926  void ZConfig::removeMultiversionSpec( const std::string & name_r ) { _pimpl->multiversion().erase( name_r ); }
927 
929  { return _pimpl->apply_locks_file; }
930 
931  Pathname ZConfig::update_dataPath() const
932  {
933  return ( _pimpl->update_data_path.empty()
934  ? Pathname("/var/adm") : _pimpl->update_data_path );
935  }
936 
938  {
939  return ( _pimpl->update_messages_path.empty()
940  ? Pathname(update_dataPath()/"update-messages") : _pimpl->update_messages_path );
941  }
942 
944  {
945  return ( _pimpl->update_scripts_path.empty()
946  ? Pathname(update_dataPath()/"update-scripts") : _pimpl->update_scripts_path );
947  }
948 
949  std::string ZConfig::updateMessagesNotify() const
950  { return _pimpl->updateMessagesNotify; }
951 
952  void ZConfig::setUpdateMessagesNotify( const std::string & val_r )
953  { _pimpl->updateMessagesNotify.set( val_r ); }
954 
956  { _pimpl->updateMessagesNotify.restoreToDefault(); }
957 
959 
960  target::rpm::RpmInstFlags ZConfig::rpmInstallFlags() const
961  { return _pimpl->rpmInstallFlags; }
962 
963 
964  Pathname ZConfig::historyLogFile() const
965  {
966  return ( _pimpl->history_log_path.empty() ?
967  Pathname("/var/log/zypp/history") : _pimpl->history_log_path );
968  }
969 
971  {
972  return ( _pimpl->credentials_global_dir_path.empty() ?
973  Pathname("/etc/zypp/credentials.d") : _pimpl->credentials_global_dir_path );
974  }
975 
977  {
978  return ( _pimpl->credentials_global_file_path.empty() ?
979  Pathname("/etc/zypp/credentials.cat") : _pimpl->credentials_global_file_path );
980  }
981 
983 
984  std::string ZConfig::distroverpkg() const
985  { return "redhat-release"; }
986 
988 
989  Pathname ZConfig::pluginsPath() const
990  { return _pimpl->pluginsPath.get(); }
991 
993 
994  std::ostream & ZConfig::about( std::ostream & str ) const
995  {
996  str << "libzypp: " << VERSION << " built " << __DATE__ << " " << __TIME__ << endl;
997 
998  str << "libsolv: " << solv_version;
999  if ( ::strcmp( solv_version, LIBSOLV_VERSION_STRING ) )
1000  str << " (built against " << LIBSOLV_VERSION_STRING << ")";
1001  str << endl;
1002 
1003  str << "zypp.conf: '" << _pimpl->_parsedZyppConf << "'" << endl;
1004  str << "TextLocale: '" << textLocale() << "' (" << defaultTextLocale() << ")" << endl;
1005  str << "SystemArchitecture: '" << systemArchitecture() << "' (" << defaultSystemArchitecture() << ")" << endl;
1006  return str;
1007  }
1008 
1010 } // namespace zypp
~ZConfig()
Dtor.
Definition: ZConfig.cc:696
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:735
Mutable option.
Definition: ZConfig.cc:219
DefaultOption(const value_type &initial_r)
Definition: ZConfig.cc:255
#define MIL
Definition: Logger.h:47
Pathname update_scripts_path
Definition: ZConfig.cc:582
Pathname cfg_known_repos_path
Definition: ZConfig.cc:574
int download_transfer_timeout
Definition: ZConfig.cc:599
void setGpgCheck(bool val_r)
Change the value.
Definition: ZConfig.cc:893
MapKVIteratorTraits< SectionSet >::Key_const_iterator section_const_iterator
Definition: IniDict.h:46
Option< unsigned > solver_upgradeTestcasesToKeep
Definition: ZConfig.cc:610
void setUpdateMessagesNotify(const std::string &val_r)
Set a new command definition (see update.messages.notify in zypp.conf).
Definition: ZConfig.cc:952
Option< bool > solver_cleandepsOnRemove
Definition: ZConfig.cc:609
TriBool repoGpgCheck() const
Check repo matadata signatures (indeterminate - according to gpgcheck)
Definition: ZConfig.cc:890
void setRepoGpgCheck(TriBool val_r)
Change the value.
Definition: ZConfig.cc:894
Pathname cfg_known_services_path
Definition: ZConfig.cc:575
int download_max_concurrent_connections
Definition: ZConfig.cc:595
std::ostream & about(std::ostream &str) const
Print some detail about the current libzypp version.
Definition: ZConfig.cc:994
Pathname update_messages_path
Definition: ZConfig.cc:583
std::string distroverpkg() const
Package telling the "product version" on systems not using /etc/product.d/baseproduct.
Definition: ZConfig.cc:984
unsigned split(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=" \t")
Split line_r into words.
Definition: String.h:511
unsigned solver_upgradeTestcasesToKeep() const
When committing a dist upgrade (e.g.
Definition: ZConfig.cc:915
void setTextLocale(const Locale &locale_r)
Set the default language for retrieving translated texts.
Definition: Pool.cc:199
Architecture.
Definition: Arch.h:36
bool download_use_deltarpm
Definition: ZConfig.cc:591
Pathname knownServicesPath() const
Path where the known services .service files are kept (configPath()/services.d).
Definition: ZConfig.cc:820
Pathname vendorPath() const
Directory for equivalent vendor definitions (configPath()/vendors.d)
Definition: ZConfig.cc:826
Pathname repoCachePath() const
Path where the caches are kept (/var/cache/zypp)
Definition: ZConfig.cc:782
LocaleSet repoRefreshLocales
Definition: ZConfig.cc:588
#define INT
Definition: Logger.h:51
Pathname credentialsGlobalFile() const
Defaults to /etc/zypp/credentials.cat.
Definition: ZConfig.cc:976
Pathname cfg_metadata_path
Definition: ZConfig.cc:569
Option< _Tp > option_type
Definition: ZConfig.cc:253
void removeMultiversionSpec(const std::string &name_r)
Definition: ZConfig.cc:926
Pathname cfg_cache_path
Definition: ZConfig.cc:568
void setSystemArchitecture(const Arch &arch_r)
Override the zypp system architecture.
Definition: ZConfig.cc:720
bool apply_locks_file() const
Whether locks file should be read and applied after start (true)
Definition: ZConfig.cc:928
Pathname cfg_config_path
Definition: ZConfig.cc:573
target::rpm::RpmInstFlags rpmInstallFlags
Definition: ZConfig.cc:620
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:663
long download_max_download_speed() const
Maximum download speed (bytes per second)
Definition: ZConfig.cc:876
bool setUserData(const std::string &str_r)
Set a new userData string.
Definition: ZConfig.cc:765
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:840
const std::set< std::string > & multiversion() const
Definition: ZConfig.cc:616
void resetSolverUpgradeRemoveDroppedPackages()
Reset solverUpgradeRemoveDroppedPackages to the zypp.conf default.
Definition: ZConfig.cc:920
Pathname _parsedZyppConf
Remember any parsed zypp.conf.
Definition: ZConfig.cc:563
Pathname pluginsPath() const
Defaults to /usr/lib/zypp/plugins.
Definition: ZConfig.cc:989
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
Pointer to implementation.
Definition: ZConfig.h:454
#define ERR
Definition: Logger.h:49
bool solverUpgradeRemoveDroppedPackages() const
Whether dist upgrade should remove a products dropped packages (true).
Definition: ZConfig.cc:918
DownloadMode commit_downloadMode() const
Commit download policy to use as default.
Definition: ZConfig.cc:885
Option< bool > solver_allowVendorChange
Definition: ZConfig.cc:608
void addMultiversionSpec(const std::string &name_r)
Definition: ZConfig.cc:925
void resetGpgCheck()
Reset to the zconfig default.
Definition: ZConfig.cc:897
Pathname credentials_global_dir_path
Definition: ZConfig.cc:623
void set_download_media_prefer_download(bool yesno_r)
Set download_media_prefer_download to a specific value.
Definition: ZConfig.cc:864
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:593
const value_type & getDefault() const
Get the current default value.
Definition: ZConfig.cc:268
DefaultOption< bool > gpgCheck
Definition: ZConfig.cc:603
Pathname configPath() const
Path where the configfiles are kept (/etc/zypp).
Definition: ZConfig.cc:808
Pathname historyLogFile() const
Path where ZYpp install history is logged.
Definition: ZConfig.cc:964
void setTextLocale(const Locale &locale_r)
Set the prefered locale for translated texts.
Definition: ZConfig.cc:744
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:814
static Pool instance()
Singleton ctor.
Definition: Pool.h:52
Pathname update_data_path
Definition: ZConfig.cc:581
Pathname credentials_global_file_path
Definition: ZConfig.cc:624
LocaleSet repoRefreshLocales() const
List of locales for which translated package descriptions should be downloaded.
Definition: ZConfig.cc:846
bool gpgCheck() const
Turn signature checking on/off (on)
Definition: ZConfig.cc:889
void set_default_download_media_prefer_download()
Set download_media_prefer_download to the configfiles default.
Definition: ZConfig.cc:867
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:891
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:48
Pathname cfg_packages_path
Definition: ZConfig.cc:571
section_const_iterator sectionsBegin() const
Definition: IniDict.cc:94
Pathname update_scriptsPath() const
Path where the repo metadata is downloaded and kept (update_dataPath()/).
Definition: ZConfig.cc:943
Pathname locksFile() const
Path where zypp can find or create lock file (configPath()/locks)
Definition: ZConfig.cc:832
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:873
void clearMultiversionSpec()
Definition: ZConfig.cc:924
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:759
int download_max_silent_tries
Definition: ZConfig.cc:598
Pathname update_messagesPath() const
Path where the repo solv files are created and kept (update_dataPath()/solv).
Definition: ZConfig.cc:937
_It strtonum(const C_Str &str)
Parsing numbers from string.
Definition: String.h:396
Pathname locks_file
Definition: ZConfig.cc:579
Pathname repoSolvfilesPath() const
Path where the repo solv files are created and kept (repoCachePath()/solv).
Definition: ZConfig.cc:794
Pathname repoPackagesPath() const
Path where the repo packages are downloaded and kept (repoCachePath()/packages).
Definition: ZConfig.cc:800
bool download_use_deltarpm() const
Whether to consider using a deltarpm when downloading a package.
Definition: ZConfig.cc:855
Locale cfg_textLocale
Definition: ZConfig.cc:566
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:788
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:879
bool download_use_deltarpm_always
Definition: ZConfig.cc:592
std::set< std::string > & getMultiversion() const
Definition: ZConfig.cc:631
int compareCI(const C_Str &lhs, const C_Str &rhs)
Definition: String.h:970
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:628
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:615
static Arch defaultSystemArchitecture()
The autodetected system architecture.
Definition: ZConfig.cc:711
void resetRepoGpgCheck()
Reset to the zconfig default.
Definition: ZConfig.cc:898
Pathname systemRoot() const
The target root directory.
Definition: ZConfig.cc:699
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:861
DefaultOption< std::string > updateMessagesNotify
Definition: ZConfig.cc:584
const std::set< std::string > & multiversionSpec() const
Definition: ZConfig.cc:922
Pathname solver_checkSystemFile
Definition: ZConfig.cc:613
target::rpm::RpmInstFlags rpmInstallFlags() const
The default target::rpm::RpmInstFlags for ZYppCommitPolicy.
Definition: ZConfig.cc:960
_Tp value_type
Definition: ZConfig.cc:221
Option< bool > solver_onlyRequires
Definition: ZConfig.cc:607
Pathname history_log_path
Definition: ZConfig.cc:622
std::string userData
Definition: ZConfig.cc:626
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
Definition: String.h:437
Pathname update_dataPath() const
Path where the update items are kept (/var/adm)
Definition: ZConfig.cc:931
std::string userData() const
User defined string value to be passed to log, history, plugins...
Definition: ZConfig.cc:762
Option(const value_type &initial_r)
No default ctor, explicit initialisation!
Definition: ZConfig.cc:224
int download_max_download_speed
Definition: ZConfig.cc:597
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:221
void resetUpdateMessagesNotify()
Reset to the zypp.conf default.
Definition: ZConfig.cc:955
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:557
DefaultIntegral< bool, false > _multiversionInitialized
Definition: ZConfig.cc:657
void setSolverUpgradeRemoveDroppedPackages(bool val_r)
Set solverUpgradeRemoveDroppedPackages to val_r.
Definition: ZConfig.cc:919
int download_min_download_speed
Definition: ZConfig.cc:596
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:741
std::string updateMessagesNotify() const
Command definition for sending update messages.
Definition: ZConfig.cc:949
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:843
Arch systemArchitecture() const
The system architecture zypp uses.
Definition: ZConfig.cc:717
bool repoLabelIsAlias() const
Whether to use repository alias or name in user messages (progress, exceptions, ...).
Definition: ZConfig.cc:849
Pathname cfg_vendor_path
Definition: ZConfig.cc:577
Pathname cfg_multiversion_path
Definition: ZConfig.cc:578
void setPkgGpgCheck(TriBool val_r)
Change the value.
Definition: ZConfig.cc:895
LocaleSet requestedLocales() const
Languages to be supported by the system.
Definition: Target.cc:109
DefaultOption< bool > solverUpgradeRemoveDroppedPackages
Definition: ZConfig.cc:611
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:870
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition: String.h:1035
option_type _default
Definition: ZConfig.cc:276
value_type _val
Definition: ZConfig.cc:245
DefaultOption< TriBool > repoGpgCheck
Definition: ZConfig.cc:604
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:601
DefaultOption< TriBool > pkgGpgCheck
Definition: ZConfig.cc:605
unsigned repo_refresh_delay
Definition: ZConfig.cc:587
void resetPkgGpgCheck()
Reset to the zconfig default.
Definition: ZConfig.cc:899
bool download_use_deltarpm_always() const
Whether to consider using a deltarpm even when rpm is local.
Definition: ZConfig.cc:858
#define DBG
Definition: Logger.h:46
long download_transfer_timeout() const
Maximum time in seconds that you allow a transfer operation to take.
Definition: ZConfig.cc:882
Pathname credentialsGlobalDir() const
Defaults to /etc/zypp/credentials.d.
Definition: ZConfig.cc:970
DownloadMode
Supported commit download policies.
Definition: DownloadMode.h:22
Pathname cfg_solvfiles_path
Definition: ZConfig.cc:570
std::set< std::string > _multiversion
Definition: ZConfig.cc:656