Target::reload() added
authorGabriele Mohr <gs@suse.de>
Thu, 6 Sep 2012 13:09:34 +0000 (15:09 +0200)
committerMichael Andres <ma@suse.de>
Thu, 6 Sep 2012 13:17:56 +0000 (15:17 +0200)
Can be used in 'zypper' to reload the cache if rpm database
has changed (bnc #767880)

package/libzypp.changes
zypp/Target.cc
zypp/Target.h
zypp/target/TargetImpl.cc
zypp/target/TargetImpl.h

index 5a72bc64d499627980d083878b0b23a204c68c88..5392b70109fec9044b549ce5cd1974ec8ae5d82a 100644 (file)
@@ -1,3 +1,8 @@
+-------------------------------------------------------------------
+Wed Sep  5 11:56:54 CEST 2012 - gs@suse.de
+
+- Provide Target::reload() 
+
 -------------------------------------------------------------------
 Sun Aug 26 01:13:31 CEST 2012 - ma@suse.de
 
 -------------------------------------------------------------------
 Sun Aug 26 01:13:31 CEST 2012 - ma@suse.de
 
index c4707a8dc40bd0d8b04b26db2768b223b2ffb623..0f2223682808de1be40192842e46122c69ffa1e8 100644 (file)
@@ -79,6 +79,9 @@ namespace zypp
   void Target::load()
   { _pimpl->load(); }
 
   void Target::load()
   { _pimpl->load(); }
 
+  void Target::reload()
+  { _pimpl->reload(); }
+  
   void Target::unload()
   { _pimpl->unload(); }
 
   void Target::unload()
   { _pimpl->unload(); }
 
index db949e1495972b7b0e76a43a1f963d6e456dd5e6..322e9e3fbc7982b028777de78b9a66414a842c49 100644 (file)
@@ -70,6 +70,8 @@ namespace zypp
      */
     void load();
 
      */
     void load();
 
+    void reload();
+    
     /**
      * unload target resolvables from the
      * pool
     /**
      * unload target resolvables from the
      * pool
index d0748e82fd922872349d64f0752cbb1464dbe19e..b451f5015a4f168f8a6bb621579cf98289beb84b 100644 (file)
@@ -818,7 +818,7 @@ namespace zypp
       filesystem::recursive_rmdir( base );
     }
 
       filesystem::recursive_rmdir( base );
     }
 
-    void TargetImpl::buildCache()
+    bool TargetImpl::buildCache()
     {
       Pathname base = solvfilesPath();
       Pathname rpmsolv       = base/"solv";
     {
       Pathname base = solvfilesPath();
       Pathname rpmsolv       = base/"solv";
@@ -958,6 +958,12 @@ namespace zypp
            }
        }
       }
            }
        }
       }
+      return build_rpm_solv;
+    }
+
+    void TargetImpl::reload()
+    {
+        load( false );
     }
 
     void TargetImpl::unload()
     }
 
     void TargetImpl::unload()
@@ -967,11 +973,12 @@ namespace zypp
         system.eraseFromPool();
     }
 
         system.eraseFromPool();
     }
 
-
-    void TargetImpl::load()
+    void TargetImpl::load( bool force )
     {
     {
-      buildCache();
-
+      bool newCache = buildCache();
+      MIL << "New cache built: " << (newCache?"true":"false") <<
+        ", force loading: " << (force?"true":"false") << endl;
       // now add the repos to the pool
       sat::Pool satpool( sat::Pool::instance() );
       Pathname rpmsolv( solvfilesPath() / "solv" );
       // now add the repos to the pool
       sat::Pool satpool( sat::Pool::instance() );
       Pathname rpmsolv( solvfilesPath() / "solv" );
@@ -979,10 +986,19 @@ namespace zypp
 
       // Providing an empty system repo, unload any old content
       Repository system( sat::Pool::instance().findSystemRepo() );
 
       // Providing an empty system repo, unload any old content
       Repository system( sat::Pool::instance().findSystemRepo() );
+
       if ( system && ! system.solvablesEmpty() )
       {
       if ( system && ! system.solvablesEmpty() )
       {
-        system.eraseFromPool(); // invalidates system
+        if ( newCache || force )
+        {
+          system.eraseFromPool(); // invalidates system
+        }
+        else
+        {
+          return;     // nothing to do
+        }
       }
       }
+      
       if ( ! system )
       {
         system = satpool.systemRepo();
       if ( ! system )
       {
         system = satpool.systemRepo();
@@ -990,6 +1006,7 @@ namespace zypp
 
       try
       {
 
       try
       {
+        MIL << "adding " << rpmsolv << " to system" << endl;
         system.addSolv( rpmsolv );
       }
       catch ( const Exception & exp )
         system.addSolv( rpmsolv );
       }
       catch ( const Exception & exp )
index f7716073936420fc6026246ced593e955a93f88d..371b8a4aad1e4a3d005ab2f11448c5f92b8c7645 100644 (file)
@@ -101,13 +101,15 @@ namespace zypp
       Pathname _tmpSolvfilesPath;
 
     public:
       Pathname _tmpSolvfilesPath;
 
     public:
-      void load();
+      void load( bool force = true );
 
       void unload();
 
 
       void unload();
 
+      void reload();
+      
       void clearCache();
 
       void clearCache();
 
-      void buildCache();
+      bool buildCache();
       //@}
 
     public:
       //@}
 
     public: