fix capturing "this" in lambda
[platform/upstream/libzypp.git] / zypp / ZConfig.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ZConfig.cc
10  *
11 */
12 extern "C"
13 {
14 #include <sys/utsname.h>
15 #include <unistd.h>
16 #include <solv/solvversion.h>
17 }
18 #include <iostream>
19 #include <fstream>
20 #include "zypp/base/Logger.h"
21 #include "zypp/base/IOStream.h"
22 #include "zypp/base/InputStream.h"
23 #include "zypp/base/String.h"
24
25 #include "zypp/ZConfig.h"
26 #include "zypp/ZYppFactory.h"
27 #include "zypp/PathInfo.h"
28 #include "zypp/parser/IniDict.h"
29
30 #include "zypp/sat/Pool.h"
31
32 using namespace std;
33 using namespace zypp::filesystem;
34 using namespace zypp::parser;
35
36 #undef ZYPP_BASE_LOGGER_LOGGROUP
37 #define ZYPP_BASE_LOGGER_LOGGROUP "zconfig"
38
39 ///////////////////////////////////////////////////////////////////
40 namespace zypp
41 { /////////////////////////////////////////////////////////////////
42   /** \addtogroup ZyppConfig Zypp Configuration Options
43    *
44    * The global \c zypp.conf configuration file is per default located in \c /etc/zypp/.
45    * An alternate config file can be set using the environment varaible \c ZYPP_CONF=<PATH>
46    * (see \ref zypp-envars).
47    *
48    * \section ZyppConfig_ZyppConfSample Sample zypp.conf
49    * \include ../zypp.conf
50    */
51   ///////////////////////////////////////////////////////////////////
52   namespace
53   { /////////////////////////////////////////////////////////////////
54
55     /** Determine system architecture evaluating \c uname and \c /proc/cpuinfo.
56     */
57     Arch _autodetectSystemArchitecture()
58     {
59       struct ::utsname buf;
60       if ( ::uname( &buf ) < 0 )
61       {
62         ERR << "Can't determine system architecture" << endl;
63         return Arch_noarch;
64       }
65
66       Arch architecture( buf.machine );
67       MIL << "Uname architecture is '" << buf.machine << "'" << endl;
68
69       if ( architecture == Arch_i686 )
70       {
71         // some CPUs report i686 but dont implement cx8 and cmov
72         // check for both flags in /proc/cpuinfo and downgrade
73         // to i586 if either is missing (cf bug #18885)
74         std::ifstream cpuinfo( "/proc/cpuinfo" );
75         if ( cpuinfo )
76         {
77           for( iostr::EachLine in( cpuinfo ); in; in.next() )
78           {
79             if ( str::hasPrefix( *in, "flags" ) )
80             {
81               if (    in->find( "cx8" ) == std::string::npos
82                    || in->find( "cmov" ) == std::string::npos )
83               {
84                 architecture = Arch_i586;
85                 WAR << "CPU lacks 'cx8' or 'cmov': architecture downgraded to '" << architecture << "'" << endl;
86               }
87               break;
88             }
89           }
90         }
91         else
92         {
93           ERR << "Cant open " << PathInfo("/proc/cpuinfo") << endl;
94         }
95       }
96       else if ( architecture == Arch_sparc || architecture == Arch_sparc64 )
97       {
98         // Check for sun4[vum] to get the real arch. (bug #566291)
99         std::ifstream cpuinfo( "/proc/cpuinfo" );
100         if ( cpuinfo )
101         {
102           for( iostr::EachLine in( cpuinfo ); in; in.next() )
103           {
104             if ( str::hasPrefix( *in, "type" ) )
105             {
106               if ( in->find( "sun4v" ) != std::string::npos )
107               {
108                 architecture = ( architecture == Arch_sparc64 ? Arch_sparc64v : Arch_sparcv9v );
109                 WAR << "CPU has 'sun4v': architecture upgraded to '" << architecture << "'" << endl;
110               }
111               else if ( in->find( "sun4u" ) != std::string::npos )
112               {
113                 architecture = ( architecture == Arch_sparc64 ? Arch_sparc64 : Arch_sparcv9 );
114                 WAR << "CPU has 'sun4u': architecture upgraded to '" << architecture << "'" << endl;
115               }
116               else if ( in->find( "sun4m" ) != std::string::npos )
117               {
118                 architecture = Arch_sparcv8;
119                 WAR << "CPU has 'sun4m': architecture upgraded to '" << architecture << "'" << endl;
120               }
121               break;
122             }
123           }
124         }
125         else
126         {
127           ERR << "Cant open " << PathInfo("/proc/cpuinfo") << endl;
128         }
129       }
130       return architecture;
131     }
132
133      /** The locale to be used for texts and messages.
134      *
135      * For the encoding to be used the preference is
136      *
137      *    LC_ALL, LC_CTYPE, LANG
138      *
139      * For the language of the messages to be used, the preference is
140      *
141      *    LANGUAGE, LC_ALL, LC_MESSAGES, LANG
142      *
143      * Note that LANGUAGE can contain more than one locale name, it can be
144      * a list of locale names like for example
145      *
146      *    LANGUAGE=ja_JP.UTF-8:de_DE.UTF-8:fr_FR.UTF-8
147
148      * \todo Support dynamic fallbacklists defined by LANGUAGE
149      */
150     Locale _autodetectTextLocale()
151     {
152       Locale ret( "en" );
153       const char * envlist[] = { "LC_ALL", "LC_MESSAGES", "LANG", NULL };
154       for ( const char ** envvar = envlist; *envvar; ++envvar )
155       {
156         const char * envlang = getenv( *envvar );
157         if ( envlang )
158         {
159           std::string envstr( envlang );
160           if ( envstr != "POSIX" && envstr != "C" )
161           {
162             Locale lang( envstr );
163             if ( ! lang.code().empty() )
164             {
165               MIL << "Found " << *envvar << "=" << envstr << endl;
166               ret = lang;
167               break;
168             }
169           }
170         }
171       }
172       MIL << "Default text locale is '" << ret << "'" << endl;
173 #warning HACK AROUND BOOST_TEST_CATCH_SYSTEM_ERRORS
174       setenv( "BOOST_TEST_CATCH_SYSTEM_ERRORS", "no", 1 );
175       return ret;
176     }
177
178    /////////////////////////////////////////////////////////////////
179   } // namespace zypp
180   ///////////////////////////////////////////////////////////////////
181
182   /** Mutable option. */
183   template<class _Tp>
184       struct Option
185       {
186         typedef _Tp value_type;
187
188         /** No default ctor, explicit initialisation! */
189         Option( const value_type & initial_r )
190           : _val( initial_r )
191         {}
192
193         /** Get the value.  */
194         const value_type & get() const
195         { return _val; }
196
197         /** Autoconversion to value_type.  */
198         operator const value_type &() const
199         { return _val; }
200
201         /** Set a new value.  */
202         void set( const value_type & newval_r )
203         { _val = newval_r; }
204
205         /** Non-const reference to set a new value. */
206         value_type & ref()
207         { return _val; }
208
209         private:
210           value_type _val;
211       };
212
213   /** Mutable option with initial value also remembering a config value. */
214   template<class _Tp>
215       struct DefaultOption : public Option<_Tp>
216       {
217         typedef _Tp         value_type;
218         typedef Option<_Tp> option_type;
219
220         DefaultOption( const value_type & initial_r )
221           : Option<_Tp>( initial_r ), _default( initial_r )
222         {}
223
224         /** Reset value to the current default. */
225         void restoreToDefault()
226         { this->set( _default.get() ); }
227
228         /** Reset value to a new default. */
229         void restoreToDefault( const value_type & newval_r )
230         { setDefault( newval_r ); restoreToDefault(); }
231
232         /** Get the current default value. */
233         const value_type & getDefault() const
234         { return _default.get(); }
235
236         /** Set a new default value. */
237         void setDefault( const value_type & newval_r )
238         { _default.set( newval_r ); }
239
240         private:
241           option_type _default;
242       };
243
244   ///////////////////////////////////////////////////////////////////
245   //
246   //    CLASS NAME : ZConfig::Impl
247   //
248   /** ZConfig implementation.
249    * \todo Enrich section and entry definition by some comment
250    * (including the default setting and provide some method to
251    * write this into a sample zypp.conf.
252   */
253   class ZConfig::Impl
254   {
255     public:
256       Impl( const Pathname & override_r = Pathname() )
257         : _parsedZyppConf               ( override_r )
258         , cfg_arch                      ( defaultSystemArchitecture() )
259         , cfg_textLocale                ( defaultTextLocale() )
260         , updateMessagesNotify          ( "single | /usr/lib/zypp/notify-message -p %p" )
261         , repo_add_probe                ( false )
262         , repo_refresh_delay            ( 10 )
263         , repoLabelIsAlias              ( false )
264         , download_use_deltarpm         ( true )
265         , download_use_deltarpm_always  ( false )
266         , download_media_prefer_download( true )
267         , download_max_concurrent_connections( 5 )
268         , download_min_download_speed   ( 0 )
269         , download_max_download_speed   ( 0 )
270         , download_max_silent_tries     ( 5 )
271         , commit_downloadMode           ( DownloadDefault )
272         , solver_onlyRequires           ( false )
273         , solver_allowVendorChange      ( false )
274         , solver_cleandepsOnRemove      ( false )
275         , solver_upgradeTestcasesToKeep ( 2 )
276         , solverUpgradeRemoveDroppedPackages( true )
277         , apply_locks_file              ( true )
278         , pluginsPath                   ( "/usr/lib/zypp/plugins" )
279       {
280         MIL << "libzypp: " << VERSION << " built " << __DATE__ << " " <<  __TIME__ << endl;
281         // override_r has higest prio
282         // ZYPP_CONF might override /etc/zypp/zypp.conf
283         if ( _parsedZyppConf.empty() )
284         {
285           const char *env_confpath = getenv( "ZYPP_CONF" );
286           _parsedZyppConf = env_confpath ? env_confpath : "/etc/zypp/zypp.conf";
287         }
288         else
289         {
290           // Inject this into ZConfig. Be shure this is
291           // allocated via new. See: reconfigureZConfig
292           INT << "Reconfigure to " << _parsedZyppConf << endl;
293           ZConfig::instance()._pimpl.reset( this );
294         }
295         if ( PathInfo(_parsedZyppConf).isExist() )
296         {
297           parser::IniDict dict( _parsedZyppConf );
298           for ( IniDict::section_const_iterator sit = dict.sectionsBegin();
299                 sit != dict.sectionsEnd();
300                 ++sit )
301           {
302             string section(*sit);
303             //MIL << section << endl;
304             for ( IniDict::entry_const_iterator it = dict.entriesBegin(*sit);
305                   it != dict.entriesEnd(*sit);
306                   ++it )
307             {
308               string entry(it->first);
309               string value(it->second);
310               //DBG << (*it).first << "=" << (*it).second << endl;
311               if ( section == "main" )
312               {
313                 if ( entry == "arch" )
314                 {
315                   Arch carch( value );
316                   if ( carch != cfg_arch )
317                   {
318                     WAR << "Overriding system architecture (" << cfg_arch << "): " << carch << endl;
319                     cfg_arch = carch;
320                   }
321                 }
322                 else if ( entry == "cachedir" )
323                 {
324                   cfg_cache_path = Pathname(value);
325                 }
326                 else if ( entry == "metadatadir" )
327                 {
328                   cfg_metadata_path = Pathname(value);
329                 }
330                 else if ( entry == "solvfilesdir" )
331                 {
332                   cfg_solvfiles_path = Pathname(value);
333                 }
334                 else if ( entry == "packagesdir" )
335                 {
336                   cfg_packages_path = Pathname(value);
337                 }
338                 else if ( entry == "configdir" )
339                 {
340                   cfg_config_path = Pathname(value);
341                 }
342                 else if ( entry == "reposdir" )
343                 {
344                   cfg_known_repos_path = Pathname(value);
345                 }
346                 else if ( entry == "servicesdir" )
347                 {
348                   cfg_known_services_path = Pathname(value);
349                 }
350                 else if ( entry == "repo.add.probe" )
351                 {
352                   repo_add_probe = str::strToBool( value, repo_add_probe );
353                 }
354                 else if ( entry == "repo.refresh.delay" )
355                 {
356                   str::strtonum(value, repo_refresh_delay);
357                 }
358                 else if ( entry == "repo.refresh.locales" )
359                 {
360                   std::vector<std::string> tmp;
361                   str::split( value, back_inserter( tmp ), ", \t" );
362
363                   boost::function<Locale(const std::string &)> transform(
364                     [](const std::string & str_r)->Locale{ return Locale(str_r); }
365                   );
366                   repoRefreshLocales.insert( make_transform_iterator( tmp.begin(), transform ),
367                                              make_transform_iterator( tmp.end(), transform ) );
368                 }
369                 else if ( entry == "download.use_deltarpm" )
370                 {
371                   download_use_deltarpm = str::strToBool( value, download_use_deltarpm );
372                 }
373                 else if ( entry == "download.use_deltarpm.always" )
374                 {
375                   download_use_deltarpm_always = str::strToBool( value, download_use_deltarpm_always );
376                 }
377                 else if ( entry == "download.media_preference" )
378                 {
379                   download_media_prefer_download.restoreToDefault( str::compareCI( value, "volatile" ) != 0 );
380                 }
381                 else if ( entry == "download.max_concurrent_connections" )
382                 {
383                   str::strtonum(value, download_max_concurrent_connections);
384                 }
385                 else if ( entry == "download.min_download_speed" )
386                 {
387                   str::strtonum(value, download_min_download_speed);
388                 }
389                 else if ( entry == "download.max_download_speed" )
390                 {
391                   str::strtonum(value, download_max_download_speed);
392                 }
393                 else if ( entry == "download.max_silent_tries" )
394                 {
395                   str::strtonum(value, download_max_silent_tries);
396                 }
397                 else if ( entry == "commit.downloadMode" )
398                 {
399                   commit_downloadMode.set( deserializeDownloadMode( value ) );
400                 }
401                 else if ( entry == "vendordir" )
402                 {
403                   cfg_vendor_path = Pathname(value);
404                 }
405                 else if ( entry == "multiversiondir" )
406                 {
407                   cfg_multiversion_path = Pathname(value);
408                 }
409                 else if ( entry == "solver.onlyRequires" )
410                 {
411                   solver_onlyRequires.set( str::strToBool( value, solver_onlyRequires ) );
412                 }
413                 else if ( entry == "solver.allowVendorChange" )
414                 {
415                   solver_allowVendorChange.set( str::strToBool( value, solver_allowVendorChange ) );
416                 }
417                 else if ( entry == "solver.cleandepsOnRemove" )
418                 {
419                   solver_cleandepsOnRemove.set( str::strToBool( value, solver_cleandepsOnRemove ) );
420                 }
421                 else if ( entry == "solver.upgradeTestcasesToKeep" )
422                 {
423                   solver_upgradeTestcasesToKeep.set( str::strtonum<unsigned>( value ) );
424                 }
425                 else if ( entry == "solver.upgradeRemoveDroppedPackages" )
426                 {
427                   solverUpgradeRemoveDroppedPackages.restoreToDefault( str::strToBool( value, solverUpgradeRemoveDroppedPackages.getDefault() ) );
428                 }
429                 else if ( entry == "solver.checkSystemFile" )
430                 {
431                   solver_checkSystemFile = Pathname(value);
432                 }
433                 else if ( entry == "multiversion" )
434                 {
435                   str::split( value, inserter( _multiversion, _multiversion.end() ), ", \t" );
436                 }
437                 else if ( entry == "locksfile.path" )
438                 {
439                   locks_file = Pathname(value);
440                 }
441                 else if ( entry == "locksfile.apply" )
442                 {
443                   apply_locks_file = str::strToBool( value, apply_locks_file );
444                 }
445                 else if ( entry == "update.datadir" )
446                 {
447                   update_data_path = Pathname(value);
448                 }
449                 else if ( entry == "update.scriptsdir" )
450                 {
451                   update_scripts_path = Pathname(value);
452                 }
453                 else if ( entry == "update.messagessdir" )
454                 {
455                   update_messages_path = Pathname(value);
456                 }
457                 else if ( entry == "update.messages.notify" )
458                 {
459                   updateMessagesNotify.set( value );
460                 }
461                 else if ( entry == "rpm.install.excludedocs" )
462                 {
463                   rpmInstallFlags.setFlag( target::rpm::RPMINST_EXCLUDEDOCS,
464                                            str::strToBool( value, false ) );
465                 }
466                 else if ( entry == "history.logfile" )
467                 {
468                   history_log_path = Pathname(value);
469                 }
470                 else if ( entry == "credentials.global.dir" )
471                 {
472                   credentials_global_dir_path = Pathname(value);
473                 }
474                 else if ( entry == "credentials.global.file" )
475                 {
476                   credentials_global_file_path = Pathname(value);
477                 }
478               }
479             }
480           }
481         }
482         else
483         {
484           MIL << _parsedZyppConf << " not found, using defaults instead." << endl;
485           _parsedZyppConf = _parsedZyppConf.extend( " (NOT FOUND)" );
486         }
487
488         // legacy:
489         if ( getenv( "ZYPP_TESTSUITE_FAKE_ARCH" ) )
490         {
491           Arch carch( getenv( "ZYPP_TESTSUITE_FAKE_ARCH" ) );
492           if ( carch != cfg_arch )
493           {
494             WAR << "ZYPP_TESTSUITE_FAKE_ARCH: Overriding system architecture (" << cfg_arch << "): " << carch << endl;
495             cfg_arch = carch;
496           }
497         }
498         MIL << "ZConfig singleton created." << endl;
499       }
500
501       ~Impl()
502       {}
503
504     public:
505     /** Remember any parsed zypp.conf. */
506     Pathname _parsedZyppConf;
507
508     Arch     cfg_arch;
509     Locale   cfg_textLocale;
510
511     Pathname cfg_cache_path;
512     Pathname cfg_metadata_path;
513     Pathname cfg_solvfiles_path;
514     Pathname cfg_packages_path;
515
516     Pathname cfg_config_path;
517     Pathname cfg_known_repos_path;
518     Pathname cfg_known_services_path;
519
520     Pathname cfg_vendor_path;
521     Pathname cfg_multiversion_path;
522     Pathname locks_file;
523
524     Pathname update_data_path;
525     Pathname update_scripts_path;
526     Pathname update_messages_path;
527     DefaultOption<std::string> updateMessagesNotify;
528
529     bool        repo_add_probe;
530     unsigned    repo_refresh_delay;
531     LocaleSet   repoRefreshLocales;
532     bool        repoLabelIsAlias;
533
534     bool download_use_deltarpm;
535     bool download_use_deltarpm_always;
536     DefaultOption<bool> download_media_prefer_download;
537
538     int download_max_concurrent_connections;
539     int download_min_download_speed;
540     int download_max_download_speed;
541     int download_max_silent_tries;
542
543     Option<DownloadMode> commit_downloadMode;
544
545     Option<bool>        solver_onlyRequires;
546     Option<bool>        solver_allowVendorChange;
547     Option<bool>        solver_cleandepsOnRemove;
548     Option<unsigned>    solver_upgradeTestcasesToKeep;
549     DefaultOption<bool> solverUpgradeRemoveDroppedPackages;
550
551     Pathname solver_checkSystemFile;
552
553     std::set<std::string> &             multiversion()          { return getMultiversion(); }
554     const std::set<std::string> &       multiversion() const    { return getMultiversion(); }
555
556     bool apply_locks_file;
557
558     target::rpm::RpmInstFlags rpmInstallFlags;
559
560     Pathname history_log_path;
561     Pathname credentials_global_dir_path;
562     Pathname credentials_global_file_path;
563
564     Option<Pathname> pluginsPath;
565
566   private:
567     std::set<std::string> & getMultiversion() const
568     {
569       if ( ! _multiversionInitialized )
570       {
571         Pathname multiversionDir( cfg_multiversion_path );
572         if ( multiversionDir.empty() )
573           multiversionDir = ( cfg_config_path.empty() ? Pathname("/etc/zypp") : cfg_config_path ) / "multiversion.d";
574
575         filesystem::dirForEach( multiversionDir,
576                                 [this]( const Pathname & dir_r, const char *const & name_r )->bool
577                                 {
578                                   MIL << "Parsing " << dir_r/name_r << endl;
579                                   iostr::simpleParseFile( InputStream( dir_r/name_r ),
580                                                           [this]( int num_r, std::string line_r )->bool
581                                                           {
582                                                             DBG << "  found " << line_r << endl;
583                                                            _multiversion.insert( line_r );
584                                                             return true;
585                                                           } );
586                                   return true;
587                                 } );
588         _multiversionInitialized = true;
589       }
590       return _multiversion;
591     }
592     mutable std::set<std::string>       _multiversion;
593     mutable DefaultIntegral<bool,false> _multiversionInitialized;
594   };
595   ///////////////////////////////////////////////////////////////////
596
597   // Backdoor to redirect ZConfig from within the running
598   // TEST-application. HANDLE WITH CARE!
599   void reconfigureZConfig( const Pathname & override_r )
600   {
601     // ctor puts itself unter smart pointer control.
602     new ZConfig::Impl( override_r );
603   }
604
605   ///////////////////////////////////////////////////////////////////
606   //
607   //    METHOD NAME : ZConfig::instance
608   //    METHOD TYPE : ZConfig &
609   //
610   ZConfig & ZConfig::instance()
611   {
612     static ZConfig _instance; // The singleton
613     return _instance;
614   }
615
616   ///////////////////////////////////////////////////////////////////
617   //
618   //    METHOD NAME : ZConfig::ZConfig
619   //    METHOD TYPE : Ctor
620   //
621   ZConfig::ZConfig()
622   : _pimpl( new Impl )
623   {
624     about( MIL );
625   }
626
627   ///////////////////////////////////////////////////////////////////
628   //
629   //    METHOD NAME : ZConfig::~ZConfig
630   //    METHOD TYPE : Dtor
631   //
632   ZConfig::~ZConfig( )
633   {}
634
635   Pathname ZConfig::systemRoot() const
636   {
637     Target_Ptr target( getZYpp()->getTarget() );
638     return target ? target->root() : Pathname();
639   }
640
641   ///////////////////////////////////////////////////////////////////
642   //
643   // system architecture
644   //
645   ///////////////////////////////////////////////////////////////////
646
647   Arch ZConfig::defaultSystemArchitecture()
648   {
649     static Arch _val( _autodetectSystemArchitecture() );
650     return _val;
651   }
652
653   Arch ZConfig::systemArchitecture() const
654   { return _pimpl->cfg_arch; }
655
656   void ZConfig::setSystemArchitecture( const Arch & arch_r )
657   {
658     if ( arch_r != _pimpl->cfg_arch )
659     {
660       WAR << "Overriding system architecture (" << _pimpl->cfg_arch << "): " << arch_r << endl;
661       _pimpl->cfg_arch = arch_r;
662     }
663   }
664
665   ///////////////////////////////////////////////////////////////////
666   //
667   // text locale
668   //
669   ///////////////////////////////////////////////////////////////////
670
671   Locale ZConfig::defaultTextLocale()
672   {
673     static Locale _val( _autodetectTextLocale() );
674     return _val;
675   }
676
677   Locale ZConfig::textLocale() const
678   { return _pimpl->cfg_textLocale; }
679
680   void ZConfig::setTextLocale( const Locale & locale_r )
681   {
682     if ( locale_r != _pimpl->cfg_textLocale )
683     {
684       WAR << "Overriding text locale (" << _pimpl->cfg_textLocale << "): " << locale_r << endl;
685       _pimpl->cfg_textLocale = locale_r;
686 #warning prefer signal
687       sat::Pool::instance().setTextLocale( locale_r );
688     }
689   }
690
691   ///////////////////////////////////////////////////////////////////
692
693   Pathname ZConfig::repoCachePath() const
694   {
695     return ( _pimpl->cfg_cache_path.empty()
696         ? Pathname("/var/cache/zypp") : _pimpl->cfg_cache_path );
697   }
698
699   Pathname ZConfig::repoMetadataPath() const
700   {
701     return ( _pimpl->cfg_metadata_path.empty()
702         ? (repoCachePath()/"raw") : _pimpl->cfg_metadata_path );
703   }
704
705   Pathname ZConfig::repoSolvfilesPath() const
706   {
707     return ( _pimpl->cfg_solvfiles_path.empty()
708         ? (repoCachePath()/"solv") : _pimpl->cfg_solvfiles_path );
709   }
710
711   Pathname ZConfig::repoPackagesPath() const
712   {
713     return ( _pimpl->cfg_packages_path.empty()
714         ? (repoCachePath()/"packages") : _pimpl->cfg_packages_path );
715   }
716
717   ///////////////////////////////////////////////////////////////////
718
719   Pathname ZConfig::configPath() const
720   {
721     return ( _pimpl->cfg_config_path.empty()
722         ? Pathname("/etc/zypp") : _pimpl->cfg_config_path );
723   }
724
725   Pathname ZConfig::knownReposPath() const
726   {
727     return ( _pimpl->cfg_known_repos_path.empty()
728         ? (configPath()/"repos.d") : _pimpl->cfg_known_repos_path );
729   }
730
731   Pathname ZConfig::knownServicesPath() const
732   {
733     return ( _pimpl->cfg_known_services_path.empty()
734         ? (configPath()/"services.d") : _pimpl->cfg_known_repos_path );
735   }
736
737   Pathname ZConfig::vendorPath() const
738   {
739     return ( _pimpl->cfg_vendor_path.empty()
740         ? (configPath()/"vendors.d") : _pimpl->cfg_vendor_path );
741   }
742
743   Pathname ZConfig::locksFile() const
744   {
745     return ( _pimpl->locks_file.empty()
746         ? (configPath()/"locks") : _pimpl->locks_file );
747   }
748
749   ///////////////////////////////////////////////////////////////////
750
751   bool ZConfig::repo_add_probe() const
752   { return _pimpl->repo_add_probe; }
753
754   unsigned ZConfig::repo_refresh_delay() const
755   { return _pimpl->repo_refresh_delay; }
756
757   LocaleSet ZConfig::repoRefreshLocales() const
758   { return _pimpl->repoRefreshLocales.empty() ? Target::requestedLocales("") :_pimpl->repoRefreshLocales; }
759
760   bool ZConfig::repoLabelIsAlias() const
761   { return _pimpl->repoLabelIsAlias; }
762
763   void ZConfig::repoLabelIsAlias( bool yesno_r )
764   { _pimpl->repoLabelIsAlias = yesno_r; }
765
766   bool ZConfig::download_use_deltarpm() const
767   { return _pimpl->download_use_deltarpm; }
768
769   bool ZConfig::download_use_deltarpm_always() const
770   { return download_use_deltarpm() && _pimpl->download_use_deltarpm_always; }
771
772   bool ZConfig::download_media_prefer_download() const
773   { return _pimpl->download_media_prefer_download; }
774
775   void ZConfig::set_download_media_prefer_download( bool yesno_r )
776   { _pimpl->download_media_prefer_download.set( yesno_r ); }
777
778   void ZConfig::set_default_download_media_prefer_download()
779   { _pimpl->download_media_prefer_download.restoreToDefault(); }
780
781   long ZConfig::download_max_concurrent_connections() const
782   { return _pimpl->download_max_concurrent_connections; }
783
784   long ZConfig::download_min_download_speed() const
785   { return _pimpl->download_min_download_speed; }
786
787   long ZConfig::download_max_download_speed() const
788   { return _pimpl->download_max_download_speed; }
789
790   long ZConfig::download_max_silent_tries() const
791   { return _pimpl->download_max_silent_tries; }
792
793   DownloadMode ZConfig::commit_downloadMode() const
794   { return _pimpl->commit_downloadMode; }
795
796   bool ZConfig::solver_onlyRequires() const
797   { return _pimpl->solver_onlyRequires; }
798
799   bool ZConfig::solver_allowVendorChange() const
800   { return _pimpl->solver_allowVendorChange; }
801
802   bool ZConfig::solver_cleandepsOnRemove() const
803   { return _pimpl->solver_cleandepsOnRemove; }
804
805   Pathname ZConfig::solver_checkSystemFile() const
806   { return ( _pimpl->solver_checkSystemFile.empty()
807       ? (configPath()/"systemCheck") : _pimpl->solver_checkSystemFile ); }
808
809   unsigned ZConfig::solver_upgradeTestcasesToKeep() const
810   { return _pimpl->solver_upgradeTestcasesToKeep; }
811
812   bool ZConfig::solverUpgradeRemoveDroppedPackages() const              { return _pimpl->solverUpgradeRemoveDroppedPackages; }
813   void ZConfig::setSolverUpgradeRemoveDroppedPackages( bool val_r )     { _pimpl->solverUpgradeRemoveDroppedPackages.set( val_r ); }
814   void ZConfig::resetSolverUpgradeRemoveDroppedPackages()               { _pimpl->solverUpgradeRemoveDroppedPackages.restoreToDefault(); }
815
816   const std::set<std::string> & ZConfig::multiversionSpec() const       { return _pimpl->multiversion(); }
817   void ZConfig::addMultiversionSpec( const std::string & name_r )       { _pimpl->multiversion().insert( name_r ); }
818   void ZConfig::removeMultiversionSpec( const std::string & name_r )    { _pimpl->multiversion().erase( name_r ); }
819
820   bool ZConfig::apply_locks_file() const
821   { return _pimpl->apply_locks_file; }
822
823   Pathname ZConfig::update_dataPath() const
824   {
825     return ( _pimpl->update_data_path.empty()
826         ? Pathname("/var/adm") : _pimpl->update_data_path );
827   }
828
829   Pathname ZConfig::update_messagesPath() const
830   {
831     return ( _pimpl->update_messages_path.empty()
832              ? Pathname(update_dataPath()/"update-messages") : _pimpl->update_messages_path );
833   }
834
835   Pathname ZConfig::update_scriptsPath() const
836   {
837     return ( _pimpl->update_scripts_path.empty()
838              ? Pathname(update_dataPath()/"update-scripts") : _pimpl->update_scripts_path );
839   }
840
841   std::string ZConfig::updateMessagesNotify() const
842   { return _pimpl->updateMessagesNotify; }
843
844   void ZConfig::setUpdateMessagesNotify( const std::string & val_r )
845   { _pimpl->updateMessagesNotify.set( val_r ); }
846
847   void ZConfig::resetUpdateMessagesNotify()
848   { _pimpl->updateMessagesNotify.restoreToDefault(); }
849
850   ///////////////////////////////////////////////////////////////////
851
852   target::rpm::RpmInstFlags ZConfig::rpmInstallFlags() const
853   { return _pimpl->rpmInstallFlags; }
854
855
856   Pathname ZConfig::historyLogFile() const
857   {
858     return ( _pimpl->history_log_path.empty() ?
859         Pathname("/var/log/zypp/history") : _pimpl->history_log_path );
860   }
861
862   Pathname ZConfig::credentialsGlobalDir() const
863   {
864     return ( _pimpl->credentials_global_dir_path.empty() ?
865         Pathname("/etc/zypp/credentials.d") : _pimpl->credentials_global_dir_path );
866   }
867
868   Pathname ZConfig::credentialsGlobalFile() const
869   {
870     return ( _pimpl->credentials_global_file_path.empty() ?
871         Pathname("/etc/zypp/credentials.cat") : _pimpl->credentials_global_file_path );
872   }
873
874   ///////////////////////////////////////////////////////////////////
875
876   std::string ZConfig::distroverpkg() const
877   { return "redhat-release"; }
878
879   ///////////////////////////////////////////////////////////////////
880
881   Pathname ZConfig::pluginsPath() const
882   { return _pimpl->pluginsPath.get(); }
883
884   ///////////////////////////////////////////////////////////////////
885
886   std::ostream & ZConfig::about( std::ostream & str ) const
887   {
888     str << "libzypp: " << VERSION << " built " << __DATE__ << " " <<  __TIME__ << endl;
889
890     str << "libsolv: " << solv_version;
891     if ( ::strcmp( solv_version, LIBSOLV_VERSION_STRING ) )
892       str << " (built against " << LIBSOLV_VERSION_STRING << ")";
893     str << endl;
894
895     str << "zypp.conf: '" << _pimpl->_parsedZyppConf << "'" << endl;
896     str << "TextLocale: '" << textLocale() << "' (" << defaultTextLocale() << ")" << endl;
897     str << "SystemArchitecture: '" << systemArchitecture() << "' (" << defaultSystemArchitecture() << ")" << endl;
898     return str;
899   }
900
901   /////////////////////////////////////////////////////////////////
902 } // namespace zypp
903 ///////////////////////////////////////////////////////////////////