Distupgrade: Evaluate new products droplist and schedule packages for deletion. ...
authorMichael Andres <ma@suse.de>
Thu, 15 Oct 2009 15:04:13 +0000 (17:04 +0200)
committerMichael Andres <ma@suse.de>
Thu, 15 Oct 2009 15:04:13 +0000 (17:04 +0200)
libzypp.spec.cmake
tests/data/TCdup/solver-system.xml [new file with mode: 0644]
tests/data/TCdup/solver-test.xml [new file with mode: 0644]
tests/data/TCdup/update.xml [new file with mode: 0644]
tests/zypp/CMakeLists.txt
tests/zypp/Dup_test.cc [new file with mode: 0644]
zypp/solver/detail/SATResolver.cc

index 6bdc2a6..a49bda5 100644 (file)
@@ -25,7 +25,7 @@ Provides:       yast2-packagemanager
 Obsoletes:      yast2-packagemanager
 Recommends:     logrotate
 BuildRequires:  cmake
-BuildRequires:  libsatsolver-devel >= 0.14.5
+BuildRequires:  libsatsolver-devel >= 0.14.9
 BuildRequires:  openssl-devel
 BuildRequires:  boost-devel curl-devel dejagnu doxygen gcc-c++ gettext-devel graphviz hal-devel libxml2-devel
 
diff --git a/tests/data/TCdup/solver-system.xml b/tests/data/TCdup/solver-system.xml
new file mode 100644 (file)
index 0000000..2e60954
--- /dev/null
@@ -0,0 +1,55 @@
+<channel><subchannel>
+<product>
+       <name>Product</name>
+       <vendor>openSUSE</vendor>
+       <history><update>
+               <arch>i586</arch>
+               <version>1</version>
+               <release>1</release>
+       </update></history>
+</product>
+<package>
+       <name>release-package</name>
+       <vendor>openSUSE</vendor>
+       <history><update>
+               <arch>i586</arch>
+               <version>1</version>
+               <release>1</release>
+       </update></history>
+        <provides>
+                <dep name='product()'/>
+                <dep name='product(Product)' op='==' version='1' release='1' />
+        </provides>
+</package>
+
+<package>
+       <name>glibc</name>
+       <vendor>openSUSE</vendor>
+       <history><update>
+               <arch>i586</arch>
+               <version>1</version>
+               <release>1</release>
+       </update></history>
+        <requires>
+                <dep name='dropped_required'/>
+        </requires>
+</package>
+<package>
+       <name>dropped_required</name>
+       <vendor>openSUSE</vendor>
+       <history><update>
+               <arch>i586</arch>
+               <version>1</version>
+               <release>1</release>
+       </update></history>
+</package>
+<package>
+       <name>dropped</name>
+       <vendor>openSUSE</vendor>
+       <history><update>
+               <arch>i586</arch>
+               <version>1</version>
+               <release>1</release>
+       </update></history>
+</package>
+</subchannel></channel>
diff --git a/tests/data/TCdup/solver-test.xml b/tests/data/TCdup/solver-test.xml
new file mode 100644 (file)
index 0000000..08c701d
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<test>
+<setup arch="x86_64">
+       <system file="solver-system.xml"/>
+       <!--
+       - alias       : update
+       - url         : http://foo.org/distribution/update
+       -->
+       <channel file="update.xml" name="update" priority="10" />
+       <locale name="en_US" />
+       <locale name="de" />
+</setup>
+</test>
diff --git a/tests/data/TCdup/update.xml b/tests/data/TCdup/update.xml
new file mode 100644 (file)
index 0000000..e8e0e0c
--- /dev/null
@@ -0,0 +1,36 @@
+<channel><subchannel>
+<product>
+       <name>Product</name>
+       <vendor>openSUSE</vendor>
+       <history><update>
+               <arch>i586</arch>
+               <version>2</version>
+               <release>1</release>
+       </update></history>
+</product>
+<package>
+       <name>release-package</name>
+       <vendor>openSUSE</vendor>
+       <history><update>
+               <arch>i586</arch>
+               <version>2</version>
+               <release>1</release>
+       </update></history>
+        <provides>
+                <dep name='product()'/>
+                <dep name='product(Product)' op='==' version='2' release='1' />
+                <dep name='weakremover(dropped_required)'/>
+                <dep name='weakremover(dropped)'/>
+        </provides>
+</package>
+
+<package>
+       <name>package</name>
+       <vendor>openSUSE</vendor>
+       <history><update>
+               <arch>i586</arch>
+               <version>2</version>
+               <release>1</release>
+       </update></history>
+</package>
+</subchannel></channel>
index a4a2495..3ca5491 100644 (file)
@@ -10,6 +10,7 @@ ADD_TESTS(
   Capabilities
   CheckSum
   Date
+  Dup
   Digest
   Deltarpm
   Edition
diff --git a/tests/zypp/Dup_test.cc b/tests/zypp/Dup_test.cc
new file mode 100644 (file)
index 0000000..248a03d
--- /dev/null
@@ -0,0 +1,63 @@
+#include "TestSetup.h"
+#include "zypp/ResPool.h"
+#include "zypp/ResPoolProxy.h"
+#include "zypp/pool/PoolStats.h"
+#include "zypp/ui/Selectable.h"
+
+#define BOOST_TEST_MODULE Dup
+
+/////////////////////////////////////////////////////////////////////////////
+
+static TestSetup test;
+
+template <class _Iterator>
+std::ostream & vdumpPoolStats( std::ostream & str, _Iterator begin_r, _Iterator end_r )
+{
+  pool::PoolStats stats;
+  for_( it, begin_r, end_r )
+  {
+    str << *it << endl;
+    stats( *it );
+  }
+  return str << stats;
+}
+
+bool upgrade()
+{
+  bool rres = false;
+  {
+    rres = getZYpp()->resolver()->doUpgrade();
+  }
+  if ( ! rres )
+  {
+    ERR << "upgrade " << rres << endl;
+    getZYpp()->resolver()->problems();
+    return false;
+  }
+  MIL << "upgrade " << rres << endl;
+  vdumpPoolStats( USR << "Transacting:"<< endl,
+                  make_filter_begin<resfilter::ByTransact>(test.pool()),
+                  make_filter_end<resfilter::ByTransact>(test.pool()) ) << endl;
+  return true;
+}
+
+
+BOOST_AUTO_TEST_CASE(testcase_init)
+{
+  //zypp::base::LogControl::instance().logToStdErr();
+  test.loadTestcaseRepos( TESTS_SRC_DIR"/data/TCdup" );
+  dumpRange( USR, test.pool().knownRepositoriesBegin(),
+                  test.pool().knownRepositoriesEnd() ) << endl;
+  USR << "pool: " << test.pool() << endl;
+  BOOST_REQUIRE( upgrade() );
+}
+/////////////////////////////////////////////////////////////////////////////
+
+BOOST_AUTO_TEST_CASE(orphaned)
+{
+  ResPoolProxy proxy( test.poolProxy() );
+  BOOST_CHECK_EQUAL( proxy.lookup( ResKind::package, "glibc" )->status(),              ui::S_KeepInstalled );
+  BOOST_CHECK_EQUAL( proxy.lookup( ResKind::package, "release-package" )->status(),    ui::S_AutoUpdate );
+  BOOST_CHECK_EQUAL( proxy.lookup( ResKind::package, "dropped_required" )->status(),   ui::S_KeepInstalled );
+  BOOST_CHECK_EQUAL( proxy.lookup( ResKind::package, "dropped" )->status(),            ui::S_AutoDel );
+}
index 433e65c..9e4598f 100644 (file)
@@ -31,10 +31,11 @@ extern "C"
 
 #include "zypp/solver/detail/Helper.h"
 #include "zypp/base/String.h"
+#include "zypp/Product.h"
 #include "zypp/Capability.h"
 #include "zypp/ResStatus.h"
 #include "zypp/VendorAttr.h"
-#include "zypp/base/Logger.h"
+#include "zypp/base/LogTools.h"
 #include "zypp/base/String.h"
 #include "zypp/base/Gettext.h"
 #include "zypp/base/Algorithm.h"
@@ -640,6 +641,34 @@ SATResolver::solverInit(const PoolItemList & weakItems)
        queue_push( &(_jobQueue), SOLVER_NOOBSOLETES_SOLVABLE_NAME );
        queue_push( &(_jobQueue), it->id() );
     }
+
+    if ( _distupgrade )
+    {
+      if ( ZConfig::instance().solverUpgradeRemoveDropedPackages() )
+      {
+        MIL << "Checking droplists ..." << endl;
+        // Dropped packages: look for 'weakremover()' provides
+        // in dup candidates of installed products.
+        ResPoolProxy proxy( ResPool::instance().proxy() );
+        for_( it, proxy.byKindBegin<Product>(), proxy.byKindEnd<Product>() )
+        {
+          if ( (*it)->onSystem() ) // (to install) or (not to delete)
+          {
+            CapabilitySet droplist( (*it)->candidateAsKind<Product>()->droplist() );
+            dumpRangeLine( MIL << "Droplist for " << (*it)->candidateObj() << ": " << droplist.size() << " ", droplist.begin(), droplist.end() ) << endl;
+            for_( cap, droplist.begin(), droplist.end() )
+            {
+              queue_push( &_jobQueue, SOLVER_DROP_ORPHANED|SOLVER_SOLVABLE_NAME );
+              queue_push( &_jobQueue, cap->id() );
+            }
+          }
+        }
+      }
+      else
+      {
+        MIL << "Droplist processing is disabled." << endl;
+      }
+    }
 }
 
 void