Imported Upstream version 16.0.3
[platform/upstream/libzypp.git] / zypp / sat / detail / PoolImpl.h
index d4a248f..77ced71 100644 (file)
@@ -21,10 +21,12 @@ extern "C"
 }
 #include <iosfwd>
 
-#include "zypp/base/Tr1hash.h"
+#include "zypp/base/Hash.h"
 #include "zypp/base/NonCopyable.h"
 #include "zypp/base/SerialNumber.h"
+#include "zypp/base/SetTracker.h"
 #include "zypp/sat/detail/PoolMember.h"
+#include "zypp/sat/Queue.h"
 #include "zypp/RepoInfo.h"
 #include "zypp/Locale.h"
 #include "zypp/Capability.h"
@@ -36,6 +38,7 @@ namespace zypp
   ///////////////////////////////////////////////////////////////////
   namespace sat
   { /////////////////////////////////////////////////////////////////
+    class SolvableSet;
     ///////////////////////////////////////////////////////////////////
     namespace detail
     { /////////////////////////////////////////////////////////////////
@@ -55,7 +58,7 @@ namespace zypp
           ~PoolImpl();
 
           /** Pointer style access forwarded to sat-pool. */
-          ::_Pool * operator->()
+          CPool * operator->()
           { return _pool; }
 
         public:
@@ -67,8 +70,6 @@ namespace zypp
            * \todo actually requires a watcher.
            */
           void prepare() const;
-         /** \ref prepare plus some expensive checks done before solving only. */
-         void prepareForSolving() const;
 
         private:
           /** Invalidate housekeeping data (e.g. whatprovides) if the
@@ -76,23 +77,43 @@ namespace zypp
            */
           void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
 
+          /** Invalidate locale related housekeeping data.
+           */
+          void localeSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
+
           /** Invalidate housekeeping data (e.g. whatprovides) if dependencies changed.
            */
           void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
 
           /** Callback to resolve namespace dependencies (language, modalias, filesystem, etc.). */
-          static detail::IdType nsCallback( ::_Pool *, void * data, detail::IdType lhs, detail::IdType rhs );
+          static detail::IdType nsCallback( CPool *, void * data, detail::IdType lhs, detail::IdType rhs );
 
         public:
           /** Reserved system repository alias \c @System. */
           static const std::string & systemRepoAlias();
 
-          bool isSystemRepo( ::_Repo * repo_r ) const
+          bool isSystemRepo( CRepo * repo_r ) const
           { return repo_r && _pool->installed == repo_r; }
 
-          ::_Repo * systemRepo() const
+          CRepo * systemRepo() const
           { return _pool->installed; }
 
+          /** Get rootdir (for file conflicts check) */
+         Pathname rootDir() const
+         {
+           const char * rd = ::pool_get_rootdir( _pool );
+           return( rd ? rd : "/" );
+         }
+
+         /** Set rootdir (for file conflicts check) */
+         void rootDir( const Pathname & root_r )
+         {
+           if ( root_r.empty() || root_r == "/" )
+             ::pool_set_rootdir( _pool, nullptr );
+           else
+             ::pool_set_rootdir( _pool, root_r.c_str() );
+         }
+
         public:
           /** \name Actions invalidating housekeeping data.
            *
@@ -100,53 +121,53 @@ namespace zypp
            */
           //@{
           /** Creating a new repo named \a name_r. */
-          ::_Repo * _createRepo( const std::string & name_r );
+          CRepo * _createRepo( const std::string & name_r );
 
-          /** Creating a new repo named \a name_r. */
-          void _deleteRepo( ::_Repo * repo_r );
+          /** Delete repo \a repo_r from pool. */
+          void _deleteRepo( CRepo * repo_r );
 
           /** Adding solv file to a repo.
            * Except for \c isSystemRepo_r, solvables of incompatible architecture
            * are filtered out.
           */
-          int _addSolv( ::_Repo * repo_r, FILE * file_r );
+          int _addSolv( CRepo * repo_r, FILE * file_r );
 
           /** Adding helix file to a repo.
            * Except for \c isSystemRepo_r, solvables of incompatible architecture
            * are filtered out.
           */
-          int _addHelix( ::_Repo * repo_r, FILE * file_r );
+          int _addHelix( CRepo * repo_r, FILE * file_r );
 
           /** Adding Solvables to a repo. */
-          detail::SolvableIdType _addSolvables( ::_Repo * repo_r, unsigned count_r );
+          detail::SolvableIdType _addSolvables( CRepo * repo_r, unsigned count_r );
           //@}
 
           /** Helper postprocessing the repo after adding solv or helix files. */
-          void _postRepoAdd( ::_Repo * repo_r );
+          void _postRepoAdd( CRepo * repo_r );
 
         public:
           /** a \c valid \ref Solvable has a non NULL repo pointer. */
-          bool validSolvable( const ::_Solvable & slv_r ) const
+          bool validSolvable( const CSolvable & slv_r ) const
           { return slv_r.repo; }
           /** \overload Check also for id_r being in range of _pool->solvables. */
           bool validSolvable( SolvableIdType id_r ) const
           { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
           /** \overload Check also for slv_r being in range of _pool->solvables. */
-          bool validSolvable( const ::_Solvable * slv_r ) const
+          bool validSolvable( const CSolvable * slv_r ) const
           { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
 
         public:
-          ::_Pool * getPool() const
+          CPool * getPool() const
           { return _pool; }
 
           /** \todo a quick check whether the repo was meanwhile deleted. */
-          ::_Repo * getRepo( RepoIdType id_r ) const
+          CRepo * getRepo( RepoIdType id_r ) const
           { return id_r; }
 
           /** Return pointer to the sat-solvable or NULL if it is not valid.
            * \see \ref validSolvable.
            */
-          ::_Solvable * getSolvable( SolvableIdType id_r ) const
+          CSolvable * getSolvable( SolvableIdType id_r ) const
           {
             if ( validSolvable( id_r ) )
               return &_pool->solvables[id_r];
@@ -199,22 +220,45 @@ namespace zypp
           { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
 
         public:
-          /** \name Requested locales. */
+          /// \name Requested locales.
+         /// The requested LocaleSets managed in _requestedLocalesTracker
+         /// are unexpanded; i.e. they contain just the pure user selection.
+         /// The resolver however uses expanded sets ('de_DE' will also
+         /// include its fallback locales 'de', (en); here in the namespace:
+         /// callback and in the Resolver itself).
           //@{
+         /** */
          void setTextLocale( const Locale & locale_r );
-          void setRequestedLocales( const LocaleSet & locales_r );
-          bool addRequestedLocale( const Locale & locale_r );
-          bool eraseRequestedLocale( const Locale & locale_r );
 
+
+         /** Start tracking changes based on this \a locales_r.
+          * Usually called on TargetInit.
+          */
+         void initRequestedLocales( const LocaleSet & locales_r );
+
+          /** Added since last initRequestedLocales. */
+          const LocaleSet & getAddedRequestedLocales() const
+          { return _requestedLocalesTracker.added(); }
+
+          /** Removed since last initRequestedLocales. */
+          const LocaleSet & getRemovedRequestedLocales() const
+          { return _requestedLocalesTracker.removed(); }
+
+          /** Current set of requested Locales. */
           const LocaleSet & getRequestedLocales() const
-          { return _requestedLocales; }
+          { return _requestedLocalesTracker.current(); }
 
           bool isRequestedLocale( const Locale & locale_r ) const
-          {
-            LocaleSet::const_iterator it( _requestedLocales.find( locale_r ) );
-            return it != _requestedLocales.end();
-          }
+          { return _requestedLocalesTracker.contains( locale_r ); }
 
+          /** User change (tracked). */
+          void setRequestedLocales( const LocaleSet & locales_r );
+          /** User change (tracked). */
+          bool addRequestedLocale( const Locale & locale_r );
+          /** User change (tracked). */
+          bool eraseRequestedLocale( const Locale & locale_r );
+
+         /** All Locales occurring in any repo. */
           const LocaleSet & getAvailableLocales() const;
 
           bool isAvailableLocale( const Locale & locale_r ) const
@@ -223,44 +267,38 @@ namespace zypp
             LocaleSet::const_iterator it( avl.find( locale_r ) );
             return it != avl.end();
           }
+
+          typedef base::SetTracker<IdStringSet> TrackedLocaleIds;
+
+          /** Expanded _requestedLocalesTracker for solver.*/
+          const TrackedLocaleIds & trackedLocaleIds() const;
           //@}
 
         public:
           /** \name Multiversion install. */
           //@{
-          typedef IdStringSet MultiversionList;
+          typedef SolvableSet MultiversionList;
 
-          const MultiversionList & multiversionList() const
-          {
-            if ( ! _multiversionListPtr )
-              multiversionListInit();
-            return *_multiversionListPtr;
-          }
+          const MultiversionList & multiversionList() const;
 
-          bool isMultiversion( IdString ident_r ) const
-          {
-            const MultiversionList & l( multiversionList() );
-            return l.find( ident_r ) != l.end();
-          }
+          bool isMultiversion( const Solvable & solv_r ) const;
+
+         void multiversionSpecChanged();
           //@}
 
         public:
           /** \name Installed on behalf of a user request hint. */
           //@{
-          typedef IdStringSet OnSystemByUserList;
+          /** Get ident list of all autoinstalled solvables. */
+         StringQueue autoInstalled() const
+         { return _autoinstalled; }
 
-          const OnSystemByUserList & onSystemByUserList() const
-          {
-            if ( ! _onSystemByUserListPtr )
-             onSystemByUserListInit();
-           return *_onSystemByUserListPtr;
-          }
+         /** Set ident list of all autoinstalled solvables. */
+         void setAutoInstalled( const StringQueue & autoInstalled_r )
+         { _autoinstalled = autoInstalled_r; }
 
           bool isOnSystemByUser( IdString ident_r ) const
-          {
-            const OnSystemByUserList & l( onSystemByUserList() );
-            return l.find( ident_r ) != l.end();
-          }
+          { return !_autoinstalled.contains( ident_r.id() ); }
           //@}
 
        public:
@@ -269,7 +307,7 @@ namespace zypp
 
         private:
           /** sat-pool. */
-          ::_Pool * _pool;
+          CPool * _pool;
           /** Serial number. */
           SerialNumber _serial;
           /** Watch serial number. */
@@ -278,17 +316,17 @@ namespace zypp
           std::map<RepoIdType,RepoInfo> _repoinfos;
 
           /**  */
-          LocaleSet _requestedLocales;
+         base::SetTracker<LocaleSet> _requestedLocalesTracker;
+         mutable scoped_ptr<TrackedLocaleIds> _trackedLocaleIdsPtr;
+
           mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
-          mutable std::tr1::unordered_set<IdString> _locale2Solver;
 
           /**  */
           void multiversionListInit() const;
           mutable scoped_ptr<MultiversionList> _multiversionListPtr;
 
           /**  */
-          void onSystemByUserListInit() const;
-          mutable scoped_ptr<OnSystemByUserList> _onSystemByUserListPtr;
+         sat::StringQueue _autoinstalled;
 
          /** filesystems mentioned in /etc/sysconfig/storage */
          mutable scoped_ptr<std::set<std::string> > _requiredFilesystemsPtr;