- Indicate changed pool content if /etc/sysconfig/storage USED_FS_LIST
authorMichael Andres <ma@suse.de>
Thu, 2 Aug 2007 16:19:14 +0000 (16:19 +0000)
committerMichael Andres <ma@suse.de>
Thu, 2 Aug 2007 16:19:14 +0000 (16:19 +0000)
  has changed. Resolver must discard any cached filesystem dependencies.
  (required for #271912)

devel/devel.ma/Basic.cc
zypp/base/SerialNumber.h
zypp/capability/FilesystemCap.cc
zypp/capability/FilesystemCap.h
zypp/pool/PoolImpl.cc
zypp/pool/PoolImpl.h

index f920c04..23d6605 100644 (file)
@@ -19,7 +19,17 @@ void chk( ResObject::constPtr p )
   DBG << p->deps() << endl;
 }
 
-
+namespace zypp {
+namespace filesystem {
+  void touch( const char * p )
+  {
+    static std::string w;
+    ofstream s(p);
+    s<<w<<endl;
+    w+="a";
+  }
+}
+}
 /******************************************************************
 **
 **      FUNCTION NAME : main
@@ -30,14 +40,7 @@ int main( int argc, char * argv[] )
   INT << "===[START]==========================================" << endl;
 
   ResPool pool( getZYpp()->pool() );
-  SerialNumberWatcher poolchanged( pool.serial() );
   USR << pool << endl;
-  USR << poolchanged << endl;
-
-  if ( poolchanged.remember( pool.serial() ) )
-  {
-    SEC << "CHANGED" << endl;
-  }
 
   const char *const lines[] = {
     "@ package",
@@ -50,29 +53,24 @@ int main( int argc, char * argv[] )
     "@ fin"
   };
 
-  debug::addPool( lines, lines+(sizeof(lines)/sizeof(const char *const)) );
+  //debug::addPool( lines, lines+(sizeof(lines)/sizeof(const char *const)) );
   //debug::addPool( "/tmp/a" );
   USR << pool << endl;
-  if ( poolchanged.remember( pool.serial() ) )
-  {
-    SEC << "CHANGED" << endl;
-  }
-  USR << pool << endl;
-
   for_each( pool.begin(), pool.end(), chk );
-  if ( poolchanged.remember( pool.serial() ) )
-  {
-    SEC << "CHANGED" << endl;
-  }
-  if ( poolchanged.remember( pool.serial() ) )
-  {
-    SEC << "CHANGED" << endl;
-  }
-  if ( poolchanged.remember( pool.serial() ) )
-  {
-    SEC << "CHANGED" << endl;
-  }
 
+  SEC << pool.serial().serial() << endl;
+  SEC << pool.serial().serial() << endl;
+  filesystem::touch( "/etc/sysconfig/storage" );
+  SEC << pool.serial().serial() << endl;
+  SEC << pool.serial().serial() << endl;
+  SEC << pool.serial().serial() << endl;
+  filesystem::touch( "/etc/sysconfig/storage" );
+  SEC << pool.serial().serial() << endl;
+  SEC << pool.serial().serial() << endl;
+  filesystem::touch( "/etc/sysconfig/storage" );
+  SEC << pool.serial().serial() << endl;
+  SEC << pool.serial().serial() << endl;
+  SEC << pool.serial().serial() << endl;
 
   INT << "===[END]============================================" << endl
       << endl;
index a0cb602..86be153 100644 (file)
@@ -108,7 +108,12 @@ namespace zypp
    *
    * int main()
    * {
+   *   check();          // This call would trigger, if check used a
+   *                     // default constructed SerialNumberWatcher.
+   *
    *   check();          //
+   *   sno.dirty();
+   *   check();          // "Serial number changed."
    *   check();          //
    *   sno.dirty();
    *   check();          // "Serial number changed."
@@ -119,8 +124,17 @@ namespace zypp
     friend std::ostream & operator<<( std::ostream & str, const SerialNumberWatcher & obj );
 
     public:
-      /** Ctor taking an initial \c serial value. */
-      SerialNumberWatcher( unsigned serial_r = 0 );
+      /** Ctor taking an initial \c serial value.
+       *
+       * A default constructed SerialNumberWatcher remembers the serial
+       * number <tt>(unsigned)-1</tt>. So it is most likely the the 1st
+       * call to \ref remember returns \ref isDirty.
+       *
+       * Vice versa, initializing the SerialNumberWatcher with the current
+       * SerialNumber, most likely prevents the 1st to \ref remember to
+       * return \ref isDirty.
+      */
+      SerialNumberWatcher( unsigned serial_r = (unsigned)-1 );
       /** Ctor taking an initial \c serial value. */
       SerialNumberWatcher( const SerialNumber & serial_r );
       /** Dtor */
index 3f7d04c..9ae2f6c 100644 (file)
@@ -14,6 +14,7 @@
 #include "zypp/base/Logger.h"
 #include "zypp/base/WatchFile.h"
 #include "zypp/base/Sysconfig.h"
+#include "zypp/base/SerialNumber.h"
 
 #include "zypp/capability/FilesystemCap.h"
 
@@ -26,8 +27,17 @@ namespace zypp
   namespace capability
   { /////////////////////////////////////////////////////////////////
 
+    namespace
+    {
+      const Pathname & sysconfigStoragePath()
+      {
+        static Pathname _p( "/etc/sysconfig/storage" );
+        return _p;
+      }
+    }
+
     IMPL_PTR_TYPE(FilesystemCap)
-    
+
     /** Ctor */
     FilesystemCap::FilesystemCap( const Resolvable::Kind & refers_r,
                                  const std::string & name_r )
@@ -67,15 +77,17 @@ namespace zypp
     bool FilesystemCap::isEvalCmd() const
     { return _name.empty(); }
 
+
+
     bool FilesystemCap::evaluate() const
     {
-      static WatchFile sysconfigFile( "/etc/sysconfig/storage", WatchFile::NO_INIT );
+      static SerialNumberWatcher sysconfigStorage;
       static std::set<std::string> fs;
 
-      if ( sysconfigFile.hasChanged() )
+      if ( sysconfigStorage.remember( sysconfigStorageSerial() ) )
       {
        std::set<std::string> newfs;
-       str::split( base::sysconfig::read( sysconfigFile.path() )["USED_FS_LIST"],
+       str::split( base::sysconfig::read( sysconfigStoragePath() )["USED_FS_LIST"],
                    std::inserter( newfs, newfs.end() ) );
        fs.swap( newfs );
       }
@@ -83,6 +95,18 @@ namespace zypp
       return( fs.find( _name ) != fs.end() );
     }
 
+    const SerialNumber & FilesystemCap::sysconfigStorageSerial()
+    {
+      static WatchFile    _sysconfigFile( sysconfigStoragePath(), WatchFile::NO_INIT );
+      static SerialNumber _serial;
+
+      if ( _sysconfigFile.hasChanged() )
+      {
+        _serial.setDirty();
+      }
+      return _serial;
+    }
+
     /////////////////////////////////////////////////////////////////
   } // namespace capability
   ///////////////////////////////////////////////////////////////////
index 32793c7..9205216 100644 (file)
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
+
+  class SerialNumber;
+
   ///////////////////////////////////////////////////////////////////
   namespace capability
   { /////////////////////////////////////////////////////////////////
 
     DEFINE_PTR_TYPE(FilesystemCap)
-    
+
     ///////////////////////////////////////////////////////////////////
     //
     // CLASS NAME : FilesystemCap
@@ -46,7 +49,7 @@ namespace zypp
       typedef FilesystemCap Self;
       typedef FilesystemCap_Ptr Ptr;
       typedef FilesystemCap_constPtr constPtr;
-      
+
     public:
       /** Ctor */
       FilesystemCap( const Resolvable::Kind & refers_r, const std::string & name_r );
@@ -78,6 +81,10 @@ namespace zypp
     private:
       /**  */
       std::string _name;
+
+    public:
+      /** Serial number indicating a change in /etc/sysconfig/storage */
+      static const SerialNumber & sysconfigStorageSerial();
     };
     ///////////////////////////////////////////////////////////////////
 
index 8fba2a6..9d5c697 100644 (file)
@@ -11,6 +11,7 @@
 */
 #include <iostream>
 #include "zypp/base/Logger.h"
+#include "zypp/capability/FilesystemCap.h"
 
 #include "zypp/pool/PoolImpl.h"
 #include "zypp/pool/PoolStats.h"
@@ -194,6 +195,7 @@ namespace zypp
     // METHOD TYPE : Ctor
     //
     PoolImpl::PoolImpl()
+      : _watchFilesystemSysconfigStorage( capability::FilesystemCap::sysconfigStorageSerial() )
     {}
 
     ///////////////////////////////////////////////////////////////////
@@ -211,7 +213,10 @@ namespace zypp
     //
     const SerialNumber & PoolImpl::serial() const
     {
-#warning INCLUDE CHECK FOR CHANGED DEPENDENCIES
+      if ( _watchFilesystemSysconfigStorage.remember( capability::FilesystemCap::sysconfigStorageSerial() ) )
+      {
+        const_cast<PoolImpl*>(this)->_serial.setDirty(); // propagate changed /etc/sysconfig/storage
+      }
       return _serial;
     }
 
index 3d57919..07dd347 100644 (file)
@@ -329,7 +329,9 @@ namespace zypp
 
     private:
       /** Serial number. */
-      SerialNumber _serial;
+      SerialNumber        _serial;
+      /** Watch for changes in /etc/sysconfig/storage. */
+      SerialNumberWatcher _watchFilesystemSysconfigStorage;
 
     public:
       ContainerT   _store;