Detect and compile with rpm 4.7 (bnc #444211)
authorMichael Andres <ma@suse.de>
Tue, 5 May 2009 11:34:50 +0000 (13:34 +0200)
committerMichael Andres <ma@suse.de>
Tue, 5 May 2009 11:34:50 +0000 (13:34 +0200)
CMakeLists.txt
cmake/modules/FindRpm.cmake
zypp/target/rpm/BinHeader.cc
zypp/target/rpm/BinHeader.h
zypp/target/rpm/RpmHeader.cc
zypp/target/rpm/librpm.h
zypp/target/rpm/librpmDb.cc
zypp/target/rpm/librpmDb.cv3.cc

index d79a8b3..2e3c1f0 100644 (file)
@@ -52,6 +52,10 @@ ELSE ( NOT RPM_FOUND)
   INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR})
   # fix includes not relative to rpm
   INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR}/rpm)
+  if (RPM_4_4_LEGACY)
+    MESSAGE( STATUS "Enable rpm 4.4 legacy interface")
+    ADD_DEFINITIONS(-D_RPM_4_4_COMPAT)
+  endif (RPM_4_4_LEGACY)
 ENDIF( NOT RPM_FOUND)
 
 FIND_PACKAGE(Boost REQUIRED)
index c49d405..e1a9d44 100644 (file)
@@ -1,17 +1,23 @@
 
 if(RPM_INCLUDE_DIR AND RPM_LIBRARY)
        # Already in cache, be silent
-       set(RPM_FIND_QUIETLY TRUE)      
+       set(RPM_FIND_QUIETLY TRUE)
 endif(RPM_INCLUDE_DIR AND RPM_LIBRARY)
 
 set(RPM_LIBRARY)
 set(RPM_INCLUDE_DIR)
+set(RPM_4_4_LEGACY)
 
-FIND_PATH(RPM_INCLUDE_DIR rpm/misc.h
+FIND_PATH(RPM_INCLUDE_DIR rpm/rpmdb.h
        /usr/include
        /usr/local/include
 )
 
+FIND_PATH(RPM_4_4_LEGACY rpm/rpmlegacy.h
+       ${RPM_INCLUDE_DIR}
+       NO_DEFAULT_PATH
+)
+
 FIND_LIBRARY(RPM_LIBRARY NAMES rpm
        PATHS
        /usr/lib
@@ -20,6 +26,9 @@ FIND_LIBRARY(RPM_LIBRARY NAMES rpm
 
 if(RPM_INCLUDE_DIR AND RPM_LIBRARY)
    MESSAGE( STATUS "rpm found: includes in ${RPM_INCLUDE_DIR}, library in ${RPM_LIBRARY}")
+   if ( RPM_4_4_LEGACY )
+     MESSAGE( STATUS "rpm provides 4.4 legacy interface")
+   endif ( RPM_4_4_LEGACY )
    set(RPM_FOUND TRUE)
 else(RPM_INCLUDE_DIR AND RPM_LIBRARY)
    MESSAGE( STATUS "rpm not found")
index c7a1c58..5485da8 100644 (file)
@@ -39,7 +39,7 @@ BinHeader::intList::intList()
     : cnt( 0 ), val( 0 ), type( RPM_NULL_TYPE )
 {}
 
-unsigned BinHeader::intList::set( void * val_r, tag cnt_r, tag type_r )
+unsigned BinHeader::intList::set( void * val_r, unsigned cnt_r, rpmTagType type_r )
 {
   val = val_r;
   cnt = val ? cnt_r : 0;
@@ -56,11 +56,11 @@ int BinHeader::intList::operator[]( const unsigned idx_r ) const
     case RPM_CHAR_TYPE:
       return ((char*)val)[idx_r];
     case RPM_INT8_TYPE:
-      return ((int_8*)val)[idx_r];
+      return ((int8_t*)val)[idx_r];
     case RPM_INT16_TYPE:
-      return ((int_16*)val)[idx_r];
+      return ((int16_t*)val)[idx_r];
     case RPM_INT32_TYPE:
-      return ((int_32*)val)[idx_r];
+      return ((int32_t*)val)[idx_r];
     }
   }
   return 0;
@@ -84,7 +84,7 @@ BinHeader::stringList::stringList()
     : cnt( 0 ), val( 0 )
 {}
 
-unsigned BinHeader::stringList::set( char ** val_r, tag cnt_r )
+unsigned BinHeader::stringList::set( char ** val_r, unsigned cnt_r )
 {
   clear();
   val = val_r;
@@ -198,10 +198,10 @@ unsigned BinHeader::int_list( tag tag_r, intList & lst_r ) const
 {
   if ( !empty() )
   {
-    int_32 type = 0;
-    int_32 cnt  = 0;
+    rpmTagType type = RPM_NULL_TYPE;
+    rpm_count_t cnt = 0;
     void * val  = 0;
-    ::headerGetEntry( _h, tag_r, &type, &val, &cnt );
+    ::headerGetEntry( _h, tag_r, hTYP_t(&type), &val, &cnt );
 
     if ( val )
     {
@@ -238,10 +238,10 @@ unsigned BinHeader::string_list( tag tag_r, stringList & lst_r ) const
 {
   if ( !empty() )
   {
-    int_32 type = 0;
-    int_32 cnt  = 0;
+    rpmTagType type = RPM_NULL_TYPE;
+    rpm_count_t cnt = 0;
     void * val  = 0;
-    ::headerGetEntry( _h, tag_r, &type, &val, &cnt );
+    ::headerGetEntry( _h, tag_r, hTYP_t(&type), &val, &cnt );
 
     if ( val )
     {
@@ -272,10 +272,10 @@ int BinHeader::int_val( tag tag_r ) const
 {
   if ( !empty() )
   {
-    int_32 type = 0;
-    int_32 cnt  = 0;
+    rpmTagType type = RPM_NULL_TYPE;
+    rpm_count_t cnt = 0;
     void * val  = 0;
-    ::headerGetEntry( _h, tag_r, &type, &val, &cnt );
+    ::headerGetEntry( _h, tag_r, hTYP_t(&type), &val, &cnt );
 
     if ( val )
     {
@@ -286,11 +286,11 @@ int BinHeader::int_val( tag tag_r ) const
       case RPM_CHAR_TYPE:
         return *((char*)val);
       case RPM_INT8_TYPE:
-        return *((int_8*)val);
+        return *((int8_t*)val);
       case RPM_INT16_TYPE:
-        return *((int_16*)val);
+        return *((int16_t*)val);
       case RPM_INT32_TYPE:
-        return *((int_32*)val);
+        return *((int32_t*)val);
 
       case RPM_STRING_ARRAY_TYPE:
         free( val );
@@ -315,10 +315,10 @@ std::string BinHeader::string_val( tag tag_r ) const
 {
   if ( !empty() )
   {
-    int_32 type = 0;
-    int_32 cnt  = 0;
+    rpmTagType type = RPM_NULL_TYPE;
+    rpm_count_t cnt = 0;
     void * val  = 0;
-    ::headerGetEntry( _h, tag_r, &type, &val, &cnt );
+    ::headerGetEntry( _h, tag_r, hTYP_t(&type), &val, &cnt );
 
     if ( val )
     {
index fa4743f..a3cba75 100644 (file)
@@ -47,7 +47,7 @@ public:
 
   typedef intrusive_ptr<const BinHeader> constPtr;
 
-  typedef int32_t tag;
+  typedef rpmTag tag;
 
   class intList;
 
@@ -112,10 +112,10 @@ class BinHeader::intList
 private:
   unsigned cnt;
   void *   val;
-  tag      type;
+  rpmTagType type;
 private:
   friend class BinHeader;
-  unsigned set( void * val_r, tag cnt_r, tag type_r );
+  unsigned set( void * val_r, unsigned cnt_r, rpmTagType type_r );
 public:
   intList();
   bool empty() const
@@ -147,7 +147,7 @@ private:
   void clear();
 private:
   friend class BinHeader;
-  unsigned set( char ** val_r, tag cnt_r );
+  unsigned set( char ** val_r, unsigned cnt_r );
 public:
   stringList();
   ~stringList()
index b94e8bc..f263edf 100644 (file)
  *
 */
 #include "librpm.h"
+#ifndef _RPM_4_4_COMPAT
+#include <rpm/ugid.h>
+inline uid_t getUidS(const char * uname) { uid_t tmp; return ::unameToUid( uname, &tmp ); }
+inline gid_t getGidS(const char * gname) { gid_t tmp; return ::gnameToGid( gname, &tmp ); }
+#else
+#include <rpm/rpmbuild.h>
+#endif
 
 #include <iostream>
 #include <map>
@@ -266,8 +273,8 @@ CapabilitySet RpmHeader::PkgRelList_val( tag tag_r, bool pre, std::set<std::stri
   {
     CapabilitySet ret;
 
-    int_32  kindFlags   = 0;
-    int_32  kindVersion = 0;
+    rpmTag  kindFlags   = rpmTag(0);
+    rpmTag  kindVersion = rpmTag(0);
 
     switch ( tag_r )
     {
@@ -318,8 +325,8 @@ CapabilitySet RpmHeader::PkgRelList_val( tag tag_r, bool pre, std::set<std::stri
       std::string n( names[i] );
 
       Rel op = Rel::ANY;
-      int_32 f  = flags[i];
-      std::string v  = versions[i];
+      int32_t f = flags[i];
+      std::string v = versions[i];
 
       if ( n[0] == '/' )
       {
@@ -756,7 +763,7 @@ std::list<FileInfo> RpmHeader::tag_fileinfos() const
       uid_t uid;
       if (uids.empty())
       {
-        uid = unameToUid( usernames[i].c_str(), &uid );
+        uid = getUidS( usernames[i].c_str() );
       }
       else
       {
@@ -766,7 +773,7 @@ std::list<FileInfo> RpmHeader::tag_fileinfos() const
       gid_t gid;
       if (gids.empty())
       {
-        gid = gnameToGid( groupnames[i].c_str(), &gid );
+        gid = getGidS( groupnames[i].c_str() );
       }
       else
       {
index 5eba346..e80dafd 100644 (file)
@@ -18,8 +18,11 @@ extern "C"
 #include <rpm/rpmmacro.h>
 #include <rpm/rpmdb.h>
 #include <rpm/rpmts.h>
-#include <rpm/ugid.h>
 #include <fcntl.h>
+
+#ifndef _RPM_4_4_COMPAT
+typedef int32_t rpm_count_t;
+#endif
 }
 
 #endif // ZYPP_TARGET_RPM_LIBRPM_H
index 4f1beb5..7f72999 100644 (file)
@@ -455,6 +455,22 @@ unsigned librpmDb::size() const
   unsigned count = 0;
   if ( valid() )
   {
+#ifdef _RPM_4_4_COMPAT
+    // looks like rpm-4.7 has no public dbi interface anymore
+    int dbi = ::rpmdbOpen("/", &_d._db, O_RDONLY, 0);
+    if (dbi == 0) {
+        rpmdbMatchIterator mi = ::rpmdbInitIterator(_d._db, RPMTAG_NAME, NULL, 0);
+        if (mi != NULL) {
+            rpmtd item;
+            for (;;) {
+                Header rpmHeader = ::rpmdbNextIterator(mi);
+                if (rpmHeader != NULL)
+                    ++count;
+            }
+        }
+        ::rpmdbClose(_d._db);
+    }
+#else
     dbiIndex dbi = dbiOpen( _d._db, RPMTAG_NAME, 0 );
     if ( dbi )
     {
@@ -470,6 +486,7 @@ unsigned librpmDb::size() const
       dbiCclose( dbi, dbcursor, 0 );
       /* no need to close dbi */
     }
+#endif
   }
   return count;
 }
index 072009f..65c1c41 100644 (file)
@@ -165,7 +165,7 @@ static void compressFilelist(Header h)
   const char ** baseNames;
   int_32 * dirIndexes;
   rpmTagType fnt;
-  int count;
+  rpm_count_t count;
   int i, xx;
   int dirIndex = -1;
 
@@ -273,7 +273,7 @@ void providePackageNVR(Header h)
   const char ** providesEVR = NULL;
   rpmTagType pnt, pvt;
   int_32 * provideFlags = NULL;
-  int providesCount;
+  rpm_count_t providesCount;
   int i, xx;
   int bingo = 1;
 
@@ -408,7 +408,7 @@ void internal_convertV3toV4( const Pathname & v3db_r, const librpmDb::constPtr &
       ::rpmdbClose( db );
     }
     Fclose( fd );
-    ZYPP_THROW(RpmDbOpenException(root, Pathname(string(db->db_root))));
+    ZYPP_THROW(RpmDbOpenException(root, v4db_r->dbPath()));
   }
 
   // Check ammount of packages to process.