Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / ZConfig.cc
index bb67043..857f0c3 100644 (file)
@@ -21,11 +21,10 @@ extern "C"
 }
 #include <iostream>
 #include <fstream>
-#include "zypp/base/LogTools.h"
+#include "zypp/base/Logger.h"
 #include "zypp/base/IOStream.h"
 #include "zypp/base/InputStream.h"
 #include "zypp/base/String.h"
-#include "zypp/base/Regex.h"
 
 #include "zypp/ZConfig.h"
 #include "zypp/ZYppFactory.h"
@@ -33,7 +32,6 @@ extern "C"
 #include "zypp/parser/IniDict.h"
 
 #include "zypp/sat/Pool.h"
-#include "zypp/sat/detail/PoolImpl.h"
 
 using namespace std;
 using namespace zypp::filesystem;
@@ -186,7 +184,7 @@ namespace zypp
      */
     Locale _autodetectTextLocale()
     {
-      Locale ret( Locale::enCode );
+      Locale ret( "en" );
       const char * envlist[] = { "LC_ALL", "LC_MESSAGES", "LANG", NULL };
       for ( const char ** envvar = envlist; *envvar; ++envvar )
       {
@@ -197,7 +195,7 @@ namespace zypp
           if ( envstr != "POSIX" && envstr != "C" )
           {
             Locale lang( envstr );
-            if ( lang )
+            if ( ! lang.code().empty() )
             {
               MIL << "Found " << *envvar << "=" << envstr << endl;
               ret = lang;
@@ -212,28 +210,15 @@ namespace zypp
       return ret;
     }
 
-
-    inline Pathname _autodetectSystemRoot()
-    {
-      Target_Ptr target( getZYpp()->getTarget() );
-      return target ? target->root() : Pathname();
-    }
-
-    inline Pathname _autodetectZyppConfPath()
-    {
-      const char *env_confpath = getenv( "ZYPP_CONF" );
-      return env_confpath ? env_confpath : "/etc/zypp/zypp.conf";
-    }
-
    /////////////////////////////////////////////////////////////////
   } // namespace zypp
   ///////////////////////////////////////////////////////////////////
 
   /** Mutable option. */
-  template<class Tp>
+  template<class _Tp>
       struct Option
       {
-       typedef Tp value_type;
+       typedef _Tp value_type;
 
        /** No default ctor, explicit initialisation! */
        Option( const value_type & initial_r )
@@ -261,14 +246,14 @@ namespace zypp
       };
 
   /** Mutable option with initial value also remembering a config value. */
-  template<class Tp>
-      struct DefaultOption : public Option<Tp>
+  template<class _Tp>
+      struct DefaultOption : public Option<_Tp>
       {
-       typedef Tp         value_type;
-       typedef Option<Tp> option_type;
+       typedef _Tp         value_type;
+       typedef Option<_Tp> option_type;
 
         DefaultOption( const value_type & initial_r )
-          : Option<Tp>( initial_r ), _default( initial_r )
+          : Option<_Tp>( initial_r ), _default( initial_r )
         {}
 
        /** Reset value to the current default. */
@@ -302,8 +287,6 @@ namespace zypp
   */
   class ZConfig::Impl
   {
-    typedef std::set<std::string> MultiversionSpec;
-
     public:
       Impl( const Pathname & override_r = Pathname() )
         : _parsedZyppConf              ( override_r )
@@ -316,7 +299,6 @@ namespace zypp
         , download_use_deltarpm        ( true )
         , download_use_deltarpm_always  ( false )
         , download_media_prefer_download( true )
-       , download_mediaMountdir        ( "/var/adm/mount" )
         , download_max_concurrent_connections( 5 )
         , download_min_download_speed  ( 0 )
         , download_max_download_speed  ( 0 )
@@ -328,22 +310,19 @@ namespace zypp
        , pkgGpgCheck                   ( indeterminate )
         , solver_onlyRequires          ( false )
         , solver_allowVendorChange     ( false )
-       , solver_dupAllowDowngrade      ( true )
-       , solver_dupAllowNameChange     ( true )
-       , solver_dupAllowArchChange     ( true )
-       , solver_dupAllowVendorChange   ( true )
         , solver_cleandepsOnRemove     ( false )
         , solver_upgradeTestcasesToKeep        ( 2 )
         , solverUpgradeRemoveDroppedPackages( true )
         , apply_locks_file             ( true )
         , pluginsPath                  ( "/usr/lib/zypp/plugins" )
       {
-        MIL << "libzypp: " << VERSION << endl;
+        MIL << "libzypp: " << VERSION << " built " << __DATE__ << " " <<  __TIME__ << endl;
         // override_r has higest prio
         // ZYPP_CONF might override /etc/zypp/zypp.conf
         if ( _parsedZyppConf.empty() )
         {
-          _parsedZyppConf = _autodetectZyppConfPath();
+          const char *env_confpath = getenv( "ZYPP_CONF" );
+          _parsedZyppConf = env_confpath ? env_confpath : "/etc/zypp/zypp.conf";
         }
         else
         {
@@ -438,12 +417,6 @@ namespace zypp
                 {
                  download_media_prefer_download.restoreToDefault( str::compareCI( value, "volatile" ) != 0 );
                 }
-
-               else if ( entry == "download.media_mountdir" )
-                {
-                 download_mediaMountdir.restoreToDefault( Pathname(value) );
-                }
-
                 else if ( entry == "download.max_concurrent_connections" )
                 {
                   str::strtonum(value, download_max_concurrent_connections);
@@ -498,22 +471,6 @@ namespace zypp
                 {
                   solver_allowVendorChange.set( str::strToBool( value, solver_allowVendorChange ) );
                 }
-                else if ( entry == "solver.dupAllowDowngrade" )
-               {
-                 solver_dupAllowDowngrade.set( str::strToBool( value, solver_dupAllowDowngrade ) );
-               }
-               else if ( entry == "solver.dupAllowNameChange" )
-               {
-                 solver_dupAllowNameChange.set( str::strToBool( value, solver_dupAllowNameChange ) );
-               }
-               else if ( entry == "solver.dupAllowArchChange" )
-               {
-                 solver_dupAllowArchChange.set( str::strToBool( value, solver_dupAllowArchChange ) );
-               }
-               else if ( entry == "solver.dupAllowVendorChange" )
-               {
-                 solver_dupAllowVendorChange.set( str::strToBool( value, solver_dupAllowVendorChange ) );
-               }
                 else if ( entry == "solver.cleandepsOnRemove" )
                 {
                   solver_cleandepsOnRemove.set( str::strToBool( value, solver_cleandepsOnRemove ) );
@@ -530,14 +487,9 @@ namespace zypp
                 {
                   solver_checkSystemFile = Pathname(value);
                 }
-                else if ( entry == "solver.checkSystemFileDir" )
-                {
-                  solver_checkSystemFileDir = Pathname(value);
-                }
                 else if ( entry == "multiversion" )
                 {
-                 MultiversionSpec & defSpec( _multiversionMap.getDefaultSpec() );
-                  str::splitEscaped( value, std::inserter( defSpec, defSpec.end() ), ", \t" );
+                  str::split( value, inserter( _multiversion, _multiversion.end() ), ", \t" );
                 }
                 else if ( entry == "locksfile.path" )
                 {
@@ -583,8 +535,6 @@ namespace zypp
               }
             }
           }
-          //
-
         }
         else
         {
@@ -641,7 +591,6 @@ namespace zypp
     bool download_use_deltarpm;
     bool download_use_deltarpm_always;
     DefaultOption<bool> download_media_prefer_download;
-    DefaultOption<Pathname> download_mediaMountdir;
 
     int download_max_concurrent_connections;
     int download_min_download_speed;
@@ -657,19 +606,14 @@ namespace zypp
 
     Option<bool>       solver_onlyRequires;
     Option<bool>       solver_allowVendorChange;
-    Option<bool>       solver_dupAllowDowngrade;
-    Option<bool>       solver_dupAllowNameChange;
-    Option<bool>       solver_dupAllowArchChange;
-    Option<bool>       solver_dupAllowVendorChange;
     Option<bool>       solver_cleandepsOnRemove;
     Option<unsigned>   solver_upgradeTestcasesToKeep;
     DefaultOption<bool> solverUpgradeRemoveDroppedPackages;
 
     Pathname solver_checkSystemFile;
-    Pathname solver_checkSystemFileDir;
 
-    MultiversionSpec &         multiversion()          { return getMultiversion(); }
-    const MultiversionSpec &   multiversion() const    { return getMultiversion(); }
+    std::set<std::string> &            multiversion()          { return getMultiversion(); }
+    const std::set<std::string> &      multiversion() const    { return getMultiversion(); }
 
     bool apply_locks_file;
 
@@ -684,91 +628,33 @@ namespace zypp
     Option<Pathname> pluginsPath;
 
   private:
-    // HACK for bnc#906096: let pool re-evaluate multiversion spec
-    // if target root changes. ZConfig returns data sensitive to
-    // current target root.
-    // TODO Actually we'd need to scan the target systems zypp.conf and
-    // overlay all system specific values.
-    struct MultiversionMap
+    std::set<std::string> & getMultiversion() const
     {
-      typedef std::map<Pathname,MultiversionSpec> SpecMap;
-
-      MultiversionSpec & getSpec( Pathname root_r, const Impl & zConfImpl_r )  // from system at root
+      if ( ! _multiversionInitialized )
       {
-       // _specMap[]     - the plain zypp.conf value
-       // _specMap[/]    - combine [] and multiversion.d scan
-       // _specMap[root] - scan root/zypp.conf and root/multiversion.d
-
-       if ( root_r.empty() )
-         root_r == "/";
-       bool cacheHit = _specMap.count( root_r );
-       MultiversionSpec & ret( _specMap[root_r] );     // creates new entry on the fly
-
-       if ( ! cacheHit )
-       {
-         if ( root_r == "/" )
-           ret.swap( _specMap[Pathname()] );           // original zypp.conf
-         else
-           scanConfAt( root_r, ret, zConfImpl_r );     // scan zypp.conf at root_r
-         scanDirAt( root_r, ret, zConfImpl_r );        // add multiversion.d at root_r
-         using zypp::operator<<;
-         MIL << "MultiversionSpec '" << root_r << "' = " << ret << endl;
-       }
-       return ret;
-      }
-
-      MultiversionSpec & getDefaultSpec()      // Spec from zypp.conf parsing; called before any getSpec
-      {        return _specMap[Pathname()]; }
-
-    private:
-      void scanConfAt( const Pathname root_r, MultiversionSpec & spec_r, const Impl & zConfImpl_r )
-      {
-       static const str::regex rx( "^multiversion *= *(.*)" );
-       str::smatch what;
-       iostr::simpleParseFile( InputStream( Pathname::assertprefix( root_r, _autodetectZyppConfPath() ) ),
-                               [&]( int num_r, std::string line_r )->bool
-                               {
-                                 if ( line_r[0] == 'm' && str::regex_match( line_r, what, rx ) )
-                                 {
-                                   str::splitEscaped( what[1], std::inserter( spec_r, spec_r.end() ), ", \t" );
-                                   return false;       // stop after match
-                                 }
-                                 return true;
-                               } );
-      }
-
-      void scanDirAt( const Pathname root_r, MultiversionSpec & spec_r, const Impl & zConfImpl_r )
-      {
-       // NOTE:  Actually we'd need to scan and use the root_r! zypp.conf values.
-       Pathname multiversionDir( zConfImpl_r.cfg_multiversion_path );
+       Pathname multiversionDir( cfg_multiversion_path );
        if ( multiversionDir.empty() )
-         multiversionDir = ( zConfImpl_r.cfg_config_path.empty()
-                           ? Pathname("/etc/zypp")
-                           : zConfImpl_r.cfg_config_path ) / "multiversion.d";
+         multiversionDir = ( cfg_config_path.empty() ? Pathname("/etc/zypp") : cfg_config_path ) / "multiversion.d";
 
-       filesystem::dirForEach( Pathname::assertprefix( root_r, multiversionDir ),
-                               [&spec_r]( const Pathname & dir_r, const char *const & name_r )->bool
+       filesystem::dirForEach( multiversionDir,
+                               [this]( const Pathname & dir_r, const char *const & name_r )->bool
                                {
                                  MIL << "Parsing " << dir_r/name_r << endl;
                                  iostr::simpleParseFile( InputStream( dir_r/name_r ),
-                                                         [&spec_r]( int num_r, std::string line_r )->bool
+                                                         [this]( int num_r, std::string line_r )->bool
                                                          {
                                                            DBG << "  found " << line_r << endl;
-                                                           spec_r.insert( std::move(line_r) );
+                                                          _multiversion.insert( line_r );
                                                            return true;
                                                          } );
                                  return true;
                                } );
+       _multiversionInitialized = true;
       }
-
-    private:
-      SpecMap _specMap;
-    };
-
-    MultiversionSpec & getMultiversion() const
-    { return _multiversionMap.getSpec( _autodetectSystemRoot(), *this ); }
-
-    mutable MultiversionMap _multiversionMap;
+      return _multiversion;
+    }
+    mutable std::set<std::string>      _multiversion;
+    mutable DefaultIntegral<bool,false>        _multiversionInitialized;
   };
   ///////////////////////////////////////////////////////////////////
 
@@ -811,7 +697,10 @@ namespace zypp
   {}
 
   Pathname ZConfig::systemRoot() const
-  { return _autodetectSystemRoot(); }
+  {
+    Target_Ptr target( getZYpp()->getTarget() );
+    return target ? target->root() : Pathname();
+  }
 
   ///////////////////////////////////////////////////////////////////
   //
@@ -993,10 +882,6 @@ namespace zypp
   long ZConfig::download_transfer_timeout() const
   { return _pimpl->download_transfer_timeout; }
 
-  Pathname ZConfig::download_mediaMountdir() const             { return _pimpl->download_mediaMountdir; }
-  void ZConfig::set_download_mediaMountdir( Pathname newval_r )        { _pimpl->download_mediaMountdir.set( std::move(newval_r) ); }
-  void ZConfig::set_default_download_mediaMountdir()           { _pimpl->download_mediaMountdir.restoreToDefault(); }
-
   DownloadMode ZConfig::commit_downloadMode() const
   { return _pimpl->commit_downloadMode; }
 
@@ -1015,11 +900,6 @@ namespace zypp
   bool ZConfig::solver_allowVendorChange() const
   { return _pimpl->solver_allowVendorChange; }
 
-  bool ZConfig::solver_dupAllowDowngrade() const       { return _pimpl->solver_dupAllowDowngrade; }
-  bool ZConfig::solver_dupAllowNameChange() const      { return _pimpl->solver_dupAllowNameChange; }
-  bool ZConfig::solver_dupAllowArchChange() const      { return _pimpl->solver_dupAllowArchChange; }
-  bool ZConfig::solver_dupAllowVendorChange() const    { return _pimpl->solver_dupAllowVendorChange; }
-
   bool ZConfig::solver_cleandepsOnRemove() const
   { return _pimpl->solver_cleandepsOnRemove; }
 
@@ -1027,10 +907,6 @@ namespace zypp
   { return ( _pimpl->solver_checkSystemFile.empty()
       ? (configPath()/"systemCheck") : _pimpl->solver_checkSystemFile ); }
 
-  Pathname ZConfig::solver_checkSystemFileDir() const
-  { return ( _pimpl->solver_checkSystemFileDir.empty()
-      ? (configPath()/"systemCheck.d") : _pimpl->solver_checkSystemFileDir ); }
-
   unsigned ZConfig::solver_upgradeTestcasesToKeep() const
   { return _pimpl->solver_upgradeTestcasesToKeep; }
 
@@ -1038,19 +914,11 @@ namespace zypp
   void ZConfig::setSolverUpgradeRemoveDroppedPackages( bool val_r )    { _pimpl->solverUpgradeRemoveDroppedPackages.set( val_r ); }
   void ZConfig::resetSolverUpgradeRemoveDroppedPackages()              { _pimpl->solverUpgradeRemoveDroppedPackages.restoreToDefault(); }
 
-  namespace
-  {
-    inline void sigMultiversionSpecChanged()
-    {
-      sat::detail::PoolMember::myPool().multiversionSpecChanged();
-    }
-  }
-
   const std::set<std::string> & ZConfig::multiversionSpec() const      { return _pimpl->multiversion(); }
-  void ZConfig::multiversionSpec( std::set<std::string> new_r )                { _pimpl->multiversion().swap( new_r );         sigMultiversionSpecChanged(); }
-  void ZConfig::clearMultiversionSpec()                                        { _pimpl->multiversion().clear();               sigMultiversionSpecChanged(); }
-  void ZConfig::addMultiversionSpec( const std::string & name_r )      { _pimpl->multiversion().insert( name_r );      sigMultiversionSpecChanged(); }
-  void ZConfig::removeMultiversionSpec( const std::string & name_r )   { _pimpl->multiversion().erase( name_r );       sigMultiversionSpecChanged(); }
+  void ZConfig::multiversionSpec( std::set<std::string> new_r )                { _pimpl->multiversion().swap( new_r ); }
+  void ZConfig::clearMultiversionSpec()                                        { _pimpl->multiversion().clear(); }
+  void ZConfig::addMultiversionSpec( const std::string & name_r )      { _pimpl->multiversion().insert( name_r ); }
+  void ZConfig::removeMultiversionSpec( const std::string & name_r )   { _pimpl->multiversion().erase( name_r ); }
 
   bool ZConfig::apply_locks_file() const
   { return _pimpl->apply_locks_file; }
@@ -1120,7 +988,7 @@ namespace zypp
 
   std::ostream & ZConfig::about( std::ostream & str ) const
   {
-    str << "libzypp: " << VERSION << endl;
+    str << "libzypp: " << VERSION << " built " << __DATE__ << " " <<  __TIME__ << endl;
 
     str << "libsolv: " << solv_version;
     if ( ::strcmp( solv_version, LIBSOLV_VERSION_STRING ) )