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 5a72bc6..5392b70 100644 (file)
@@ -1,4 +1,9 @@
 -------------------------------------------------------------------
+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
 
 - Update zypp-po.tar.bz2
index c4707a8..0f22236 100644 (file)
@@ -79,6 +79,9 @@ namespace zypp
   void Target::load()
   { _pimpl->load(); }
 
+  void Target::reload()
+  { _pimpl->reload(); }
+  
   void Target::unload()
   { _pimpl->unload(); }
 
index db949e1..322e9e3 100644 (file)
@@ -70,6 +70,8 @@ namespace zypp
      */
     void load();
 
+    void reload();
+    
     /**
      * unload target resolvables from the
      * pool
index d0748e8..b451f50 100644 (file)
@@ -818,7 +818,7 @@ namespace zypp
       filesystem::recursive_rmdir( base );
     }
 
-    void TargetImpl::buildCache()
+    bool TargetImpl::buildCache()
     {
       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()
@@ -967,11 +973,12 @@ namespace zypp
         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" );
@@ -979,10 +986,19 @@ namespace zypp
 
       // Providing an empty system repo, unload any old content
       Repository system( sat::Pool::instance().findSystemRepo() );
+
       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();
@@ -990,6 +1006,7 @@ namespace zypp
 
       try
       {
+        MIL << "adding " << rpmsolv << " to system" << endl;
         system.addSolv( rpmsolv );
       }
       catch ( const Exception & exp )
index f771607..371b8a4 100644 (file)
@@ -101,13 +101,15 @@ namespace zypp
       Pathname _tmpSolvfilesPath;
 
     public:
-      void load();
+      void load( bool force = true );
 
       void unload();
 
+      void reload();
+      
       void clearCache();
 
-      void buildCache();
+      bool buildCache();
       //@}
 
     public: