95896f1492392cdbdd6d655d96d962e90e6f5194
[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 <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
43 ///////////////////////////////////////////////////////////////////
44 namespace zypp
45 { /////////////////////////////////////////////////////////////////
46   /** \addtogroup ZyppConfig Zypp Configuration Options
47    *
48    * The global \c zypp.conf configuration file is per default located in \c /etc/zypp/.
49    * An alternate config file can be set using the environment varaible \c ZYPP_CONF=<PATH>
50    * (see \ref zypp-envars).
51    *
52    * \section ZyppConfig_ZyppConfSample Sample zypp.conf
53    * \include ../zypp.conf
54    */
55   ///////////////////////////////////////////////////////////////////
56   namespace
57   { /////////////////////////////////////////////////////////////////
58
59     /** Determine system architecture evaluating \c uname and \c /proc/cpuinfo.
60     */
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
168      /** The locale to be used for texts and messages.
169      *
170      * For the encoding to be used the preference is
171      *
172      *    LC_ALL, LC_CTYPE, LANG
173      *
174      * For the language of the messages to be used, the preference is
175      *
176      *    LANGUAGE, LC_ALL, LC_MESSAGES, LANG
177      *
178      * Note that LANGUAGE can contain more than one locale name, it can be
179      * a list of locale names like for example
180      *
181      *    LANGUAGE=ja_JP.UTF-8:de_DE.UTF-8:fr_FR.UTF-8
182
183      * \todo Support dynamic fallbacklists defined by LANGUAGE
184      */
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
213    /////////////////////////////////////////////////////////////////
214   } // namespace zypp
215   ///////////////////////////////////////////////////////////////////
216
217   /** Mutable option. */
218   template<class _Tp>
219       struct Option
220       {
221         typedef _Tp value_type;
222
223         /** No default ctor, explicit initialisation! */
224         Option( const value_type & initial_r )
225           : _val( initial_r )
226         {}
227
228         /** Get the value.  */
229         const value_type & get() const
230         { return _val; }
231
232         /** Autoconversion to value_type.  */
233         operator const value_type &() const
234         { return _val; }
235
236         /** Set a new value.  */
237         void set( const value_type & newval_r )
238         { _val = newval_r; }
239
240         /** Non-const reference to set a new value. */
241         value_type & ref()
242         { return _val; }
243
244         private:
245           value_type _val;
246       };
247
248   /** Mutable option with initial value also remembering a config value. */
249   template<class _Tp>
250       struct DefaultOption : public Option<_Tp>
251       {
252         typedef _Tp         value_type;
253         typedef Option<_Tp> option_type;
254
255         DefaultOption( const value_type & initial_r )
256           : Option<_Tp>( initial_r ), _default( initial_r )
257         {}
258
259         /** Reset value to the current default. */
260         void restoreToDefault()
261         { this->set( _default.get() ); }
262
263         /** Reset value to a new default. */
264         void restoreToDefault( const value_type & newval_r )
265         { setDefault( newval_r ); restoreToDefault(); }
266
267         /** Get the current default value. */
268         const value_type & getDefault() const
269         { return _default.get(); }
270
271         /** Set a new default value. */
272         void setDefault( const value_type & newval_r )
273         { _default.set( newval_r ); }
274
275         private:
276           option_type _default;
277       };
278
279   ///////////////////////////////////////////////////////////////////
280   //
281   //    CLASS NAME : ZConfig::Impl
282   //
283   /** ZConfig implementation.
284    * \todo Enrich section and entry definition by some comment
285    * (including the default setting and provide some method to
286    * write this into a sample zypp.conf.
287   */
288   class ZConfig::Impl
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 );
337           for ( IniDict::section_const_iterator sit = dict.sectionsBegin();
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
558       ~Impl()
559       {}
560
561     public:
562     /** Remember any parsed zypp.conf. */
563     Pathname _parsedZyppConf;
564
565     Arch     cfg_arch;
566     Locale   cfg_textLocale;
567
568     Pathname cfg_cache_path;
569     Pathname cfg_metadata_path;
570     Pathname cfg_solvfiles_path;
571     Pathname cfg_packages_path;
572
573     Pathname cfg_config_path;
574     Pathname cfg_known_repos_path;
575     Pathname cfg_known_services_path;
576
577     Pathname cfg_vendor_path;
578     Pathname cfg_multiversion_path;
579     Pathname locks_file;
580
581     Pathname update_data_path;
582     Pathname update_scripts_path;
583     Pathname update_messages_path;
584     DefaultOption<std::string> updateMessagesNotify;
585
586     bool        repo_add_probe;
587     unsigned    repo_refresh_delay;
588     LocaleSet   repoRefreshLocales;
589     bool        repoLabelIsAlias;
590
591     bool download_use_deltarpm;
592     bool download_use_deltarpm_always;
593     DefaultOption<bool> download_media_prefer_download;
594
595     int download_max_concurrent_connections;
596     int download_min_download_speed;
597     int download_max_download_speed;
598     int download_max_silent_tries;
599     int download_transfer_timeout;
600
601     Option<DownloadMode> commit_downloadMode;
602
603     DefaultOption<bool>         gpgCheck;
604     DefaultOption<TriBool>      repoGpgCheck;
605     DefaultOption<TriBool>      pkgGpgCheck;
606
607     Option<bool>        solver_onlyRequires;
608     Option<bool>        solver_allowVendorChange;
609     Option<bool>        solver_cleandepsOnRemove;
610     Option<unsigned>    solver_upgradeTestcasesToKeep;
611     DefaultOption<bool> solverUpgradeRemoveDroppedPackages;
612
613     Pathname solver_checkSystemFile;
614
615     std::set<std::string> &             multiversion()          { return getMultiversion(); }
616     const std::set<std::string> &       multiversion() const    { return getMultiversion(); }
617
618     bool apply_locks_file;
619
620     target::rpm::RpmInstFlags rpmInstallFlags;
621
622     Pathname history_log_path;
623     Pathname credentials_global_dir_path;
624     Pathname credentials_global_file_path;
625
626     std::string userData;
627
628     Option<Pathname> pluginsPath;
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;
657     mutable DefaultIntegral<bool,false> _multiversionInitialized;
658   };
659   ///////////////////////////////////////////////////////////////////
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
669   ///////////////////////////////////////////////////////////////////
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
680   ///////////////////////////////////////////////////////////////////
681   //
682   //    METHOD NAME : ZConfig::ZConfig
683   //    METHOD TYPE : Ctor
684   //
685   ZConfig::ZConfig()
686   : _pimpl( new Impl )
687   {
688     about( MIL );
689   }
690
691   ///////////////////////////////////////////////////////////////////
692   //
693   //    METHOD NAME : ZConfig::~ZConfig
694   //    METHOD TYPE : Dtor
695   //
696   ZConfig::~ZConfig( )
697   {}
698
699   Pathname ZConfig::systemRoot() const
700   {
701     Target_Ptr target( getZYpp()->getTarget() );
702     return target ? target->root() : Pathname();
703   }
704
705   ///////////////////////////////////////////////////////////////////
706   //
707   // system architecture
708   //
709   ///////////////////////////////////////////////////////////////////
710
711   Arch ZConfig::defaultSystemArchitecture()
712   {
713     static Arch _val( _autodetectSystemArchitecture() );
714     return _val;
715   }
716
717   Arch ZConfig::systemArchitecture() const
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
729   ///////////////////////////////////////////////////////////////////
730   //
731   // text locale
732   //
733   ///////////////////////////////////////////////////////////////////
734
735   Locale ZConfig::defaultTextLocale()
736   {
737     static Locale _val( _autodetectTextLocale() );
738     return _val;
739   }
740
741   Locale ZConfig::textLocale() const
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
755   ///////////////////////////////////////////////////////////////////
756   // user data
757   ///////////////////////////////////////////////////////////////////
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
780   ///////////////////////////////////////////////////////////////////
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
806   ///////////////////////////////////////////////////////////////////
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
838   ///////////////////////////////////////////////////////////////////
839
840   bool ZConfig::repo_add_probe() const
841   { return _pimpl->repo_add_probe; }
842
843   unsigned ZConfig::repo_refresh_delay() const
844   { return _pimpl->repo_refresh_delay; }
845
846   LocaleSet ZConfig::repoRefreshLocales() const
847   { return _pimpl->repoRefreshLocales.empty() ? Target::requestedLocales("") :_pimpl->repoRefreshLocales; }
848
849   bool ZConfig::repoLabelIsAlias() const
850   { return _pimpl->repoLabelIsAlias; }
851
852   void ZConfig::repoLabelIsAlias( bool yesno_r )
853   { _pimpl->repoLabelIsAlias = yesno_r; }
854
855   bool ZConfig::download_use_deltarpm() const
856   { return _pimpl->download_use_deltarpm; }
857
858   bool ZConfig::download_use_deltarpm_always() const
859   { return download_use_deltarpm() && _pimpl->download_use_deltarpm_always; }
860
861   bool ZConfig::download_media_prefer_download() const
862   { return _pimpl->download_media_prefer_download; }
863
864   void ZConfig::set_download_media_prefer_download( bool yesno_r )
865   { _pimpl->download_media_prefer_download.set( yesno_r ); }
866
867   void ZConfig::set_default_download_media_prefer_download()
868   { _pimpl->download_media_prefer_download.restoreToDefault(); }
869
870   long ZConfig::download_max_concurrent_connections() const
871   { return _pimpl->download_max_concurrent_connections; }
872
873   long ZConfig::download_min_download_speed() const
874   { return _pimpl->download_min_download_speed; }
875
876   long ZConfig::download_max_download_speed() const
877   { return _pimpl->download_max_download_speed; }
878
879   long ZConfig::download_max_silent_tries() const
880   { return _pimpl->download_max_silent_tries; }
881
882   long ZConfig::download_transfer_timeout() const
883   { return _pimpl->download_transfer_timeout; }
884
885   DownloadMode ZConfig::commit_downloadMode() const
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
902   bool ZConfig::solver_onlyRequires() const
903   { return _pimpl->solver_onlyRequires; }
904
905   bool ZConfig::solver_allowVendorChange() const
906   { return _pimpl->solver_allowVendorChange; }
907
908   bool ZConfig::solver_cleandepsOnRemove() const
909   { return _pimpl->solver_cleandepsOnRemove; }
910
911   Pathname ZConfig::solver_checkSystemFile() const
912   { return ( _pimpl->solver_checkSystemFile.empty()
913       ? (configPath()/"systemCheck") : _pimpl->solver_checkSystemFile ); }
914
915   unsigned ZConfig::solver_upgradeTestcasesToKeep() const
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
928   bool ZConfig::apply_locks_file() const
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
937   Pathname ZConfig::update_messagesPath() const
938   {
939     return ( _pimpl->update_messages_path.empty()
940              ? Pathname(update_dataPath()/"update-messages") : _pimpl->update_messages_path );
941   }
942
943   Pathname ZConfig::update_scriptsPath() const
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
955   void ZConfig::resetUpdateMessagesNotify()
956   { _pimpl->updateMessagesNotify.restoreToDefault(); }
957
958   ///////////////////////////////////////////////////////////////////
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
970   Pathname ZConfig::credentialsGlobalDir() const
971   {
972     return ( _pimpl->credentials_global_dir_path.empty() ?
973         Pathname("/etc/zypp/credentials.d") : _pimpl->credentials_global_dir_path );
974   }
975
976   Pathname ZConfig::credentialsGlobalFile() const
977   {
978     return ( _pimpl->credentials_global_file_path.empty() ?
979         Pathname("/etc/zypp/credentials.cat") : _pimpl->credentials_global_file_path );
980   }
981
982   ///////////////////////////////////////////////////////////////////
983
984   std::string ZConfig::distroverpkg() const
985   { return "redhat-release"; }
986
987   ///////////////////////////////////////////////////////////////////
988
989   Pathname ZConfig::pluginsPath() const
990   { return _pimpl->pluginsPath.get(); }
991
992   ///////////////////////////////////////////////////////////////////
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
1009   /////////////////////////////////////////////////////////////////
1010 } // namespace zypp
1011 ///////////////////////////////////////////////////////////////////