Check for /etc/sysconfig/storage changes before solving (bnc#702365)
authorMichael Andres <ma@suse.de>
Fri, 15 Jul 2011 13:14:34 +0000 (15:14 +0200)
committerMichael Andres <ma@suse.de>
Fri, 15 Jul 2011 13:14:34 +0000 (15:14 +0200)
zypp/sat/Pool.cc
zypp/sat/Pool.h
zypp/sat/detail/PoolImpl.cc
zypp/sat/detail/PoolImpl.h
zypp/solver/detail/SATResolver.cc

index cc0b336..c93422c 100644 (file)
@@ -45,6 +45,9 @@ namespace zypp
     void Pool::prepare() const
     { return myPool().prepare(); }
 
+    void Pool::prepareForSolving() const
+    { return myPool().prepareForSolving(); }
+
     bool Pool::reposEmpty() const
     { return ! myPool()->nrepos; }
 
index d88e5c4..df86592 100644 (file)
@@ -65,6 +65,9 @@ namespace zypp
         /** Update housekeeping data if necessary (e.g. whatprovides). */
         void prepare() const;
 
+       /** \ref prepare plus some expensive checks done before solving only. */
+       void prepareForSolving() const;
+
       public:
         /** Whether \ref Pool contains repos. */
         bool reposEmpty() const;
index 79b2106..8786e78 100644 (file)
@@ -82,6 +82,13 @@ namespace zypp
         return _val;
       }
 
+      const Pathname & sysconfigStoragePath()
+      {
+       static const Pathname _val( "/etc/sysconfig/storage" );
+       return _val;
+      }
+
+
       /////////////////////////////////////////////////////////////////
 
       static void logSat( struct _Pool *, void *data, int type, const char *logString )
@@ -131,15 +138,7 @@ namespace zypp
 
           case NAMESPACE_FILESYSTEM:
           {
-            static const Pathname sysconfigStoragePath( "/etc/sysconfig/storage" );
-            static WatchFile      sysconfigFile( sysconfigStoragePath, WatchFile::NO_INIT );
-            static std::set<std::string> requiredFilesystems;
-            if ( sysconfigFile.hasChanged() )
-            {
-              requiredFilesystems.clear();
-              str::split( base::sysconfig::read( sysconfigStoragePath )["USED_FS_LIST"],
-                          std::inserter( requiredFilesystems, requiredFilesystems.end() ) );
-            }
+           const std::set<std::string> & requiredFilesystems( reinterpret_cast<PoolImpl*>(data)->requiredFilesystems() );
             return requiredFilesystems.find( IdString(rhs).asString() ) != requiredFilesystems.end() ? RET_systemProperty : RET_unsupported;
           }
           break;
@@ -237,7 +236,7 @@ namespace zypp
 
       void PoolImpl::prepare() const
       {
-        if ( _watcher.remember( _serial ) )
+       if ( _watcher.remember( _serial ) )
         {
           // After repo/solvable add/remove:
           // set pool architecture
@@ -246,6 +245,7 @@ namespace zypp
         if ( ! _pool->whatprovides )
         {
           MIL << "pool_createwhatprovides..." << endl;
+
           ::pool_addfileprovides( _pool );
           ::pool_createwhatprovides( _pool );
         }
@@ -256,6 +256,19 @@ namespace zypp
         }
       }
 
+      void PoolImpl::prepareForSolving() const
+      {
+       // additional /etc/sysconfig/storage check:
+       static WatchFile sysconfigFile( sysconfigStoragePath(), WatchFile::NO_INIT );
+       if ( sysconfigFile.hasChanged() )
+       {
+         _requiredFilesystemsPtr.reset(); // recreated on demand
+         const_cast<PoolImpl*>(this)->depSetDirty( "/etc/sysconfig/storage change" );
+       }
+       // finally prepare as usual:
+       prepare();
+      }
+
       ///////////////////////////////////////////////////////////////////
 
       ::_Repo * PoolImpl::_createRepo( const std::string & name_r )
@@ -599,6 +612,18 @@ namespace zypp
        MIL << "onSystemByUserList found: " << onSystemByUserList.size() << endl;
       }
 
+      const std::set<std::string> & PoolImpl::requiredFilesystems() const
+      {
+       if ( ! _requiredFilesystemsPtr )
+       {
+         _requiredFilesystemsPtr.reset( new std::set<std::string> );
+         std::set<std::string> & requiredFilesystems( *_requiredFilesystemsPtr );
+         str::split( base::sysconfig::read( sysconfigStoragePath() )["USED_FS_LIST"],
+                     std::inserter( requiredFilesystems, requiredFilesystems.end() ) );
+       }
+       return *_requiredFilesystemsPtr;
+      }
+
       /////////////////////////////////////////////////////////////////
     } // namespace detail
     ///////////////////////////////////////////////////////////////////
index 09ea430..00edf97 100644 (file)
@@ -67,6 +67,8 @@ 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
@@ -261,6 +263,10 @@ namespace zypp
           }
           //@}
 
+       public:
+         /** accessor for etc/sysconfig/storage reading file on demand */
+         const std::set<std::string> & requiredFilesystems() const;
+
         private:
           /** sat-pool. */
           ::_Pool * _pool;
@@ -283,6 +289,9 @@ namespace zypp
           /**  */
           void onSystemByUserListInit() const;
           mutable scoped_ptr<OnSystemByUserList> _onSystemByUserListPtr;
+
+         /** filesystems mentioned in /etc/sysconfig/storage */
+         mutable scoped_ptr<std::set<std::string> > _requiredFilesystemsPtr;
       };
       ///////////////////////////////////////////////////////////////////
 
index a2629bb..390c88f 100644 (file)
@@ -442,7 +442,7 @@ SATResolver::solving(const CapabilitySet & requires_caps,
     _solv->distupgrade = _distupgrade;
     _solv->distupgrade_removeunsupported = _distupgrade_removeunsupported;
 
-    sat::Pool::instance().prepare();
+    sat::Pool::instance().prepareForSolving();
 
     // Solve !
     MIL << "Starting solving...." << endl;
@@ -826,7 +826,7 @@ void SATResolver::doUpdate()
     _solv->distupgrade = _distupgrade;
     _solv->distupgrade_removeunsupported = _distupgrade_removeunsupported;
 
-    sat::Pool::instance().prepare();
+    sat::Pool::instance().prepareForSolving();
 
     // Solve !
     MIL << "Starting solving for update...." << endl;