From 84bbf2943c5e7ebafce7cf4e42576c7b12e4df5e Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Tue, 5 May 2009 13:34:50 +0200 Subject: [PATCH] Detect and compile with rpm 4.7 (bnc #444211) --- CMakeLists.txt | 4 ++++ cmake/modules/FindRpm.cmake | 13 +++++++++++-- zypp/target/rpm/BinHeader.cc | 40 ++++++++++++++++++++-------------------- zypp/target/rpm/BinHeader.h | 8 ++++---- zypp/target/rpm/RpmHeader.cc | 19 +++++++++++++------ zypp/target/rpm/librpm.h | 5 ++++- zypp/target/rpm/librpmDb.cc | 17 +++++++++++++++++ zypp/target/rpm/librpmDb.cv3.cc | 6 +++--- 8 files changed, 76 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d79a8b3..2e3c1f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/modules/FindRpm.cmake b/cmake/modules/FindRpm.cmake index c49d405..e1a9d44 100644 --- a/cmake/modules/FindRpm.cmake +++ b/cmake/modules/FindRpm.cmake @@ -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") diff --git a/zypp/target/rpm/BinHeader.cc b/zypp/target/rpm/BinHeader.cc index c7a1c58..5485da8 100644 --- a/zypp/target/rpm/BinHeader.cc +++ b/zypp/target/rpm/BinHeader.cc @@ -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 ) { diff --git a/zypp/target/rpm/BinHeader.h b/zypp/target/rpm/BinHeader.h index fa4743f..a3cba75 100644 --- a/zypp/target/rpm/BinHeader.h +++ b/zypp/target/rpm/BinHeader.h @@ -47,7 +47,7 @@ public: typedef intrusive_ptr 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() diff --git a/zypp/target/rpm/RpmHeader.cc b/zypp/target/rpm/RpmHeader.cc index b94e8bc..f263edf 100644 --- a/zypp/target/rpm/RpmHeader.cc +++ b/zypp/target/rpm/RpmHeader.cc @@ -10,6 +10,13 @@ * */ #include "librpm.h" +#ifndef _RPM_4_4_COMPAT +#include +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 +#endif #include #include @@ -266,8 +273,8 @@ CapabilitySet RpmHeader::PkgRelList_val( tag tag_r, bool pre, std::set 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 RpmHeader::tag_fileinfos() const gid_t gid; if (gids.empty()) { - gid = gnameToGid( groupnames[i].c_str(), &gid ); + gid = getGidS( groupnames[i].c_str() ); } else { diff --git a/zypp/target/rpm/librpm.h b/zypp/target/rpm/librpm.h index 5eba346..e80dafd 100644 --- a/zypp/target/rpm/librpm.h +++ b/zypp/target/rpm/librpm.h @@ -18,8 +18,11 @@ extern "C" #include #include #include -#include #include + +#ifndef _RPM_4_4_COMPAT +typedef int32_t rpm_count_t; +#endif } #endif // ZYPP_TARGET_RPM_LIBRPM_H diff --git a/zypp/target/rpm/librpmDb.cc b/zypp/target/rpm/librpmDb.cc index 4f1beb5..7f72999 100644 --- a/zypp/target/rpm/librpmDb.cc +++ b/zypp/target/rpm/librpmDb.cc @@ -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; } diff --git a/zypp/target/rpm/librpmDb.cv3.cc b/zypp/target/rpm/librpmDb.cv3.cc index 072009f..65c1c41 100644 --- a/zypp/target/rpm/librpmDb.cv3.cc +++ b/zypp/target/rpm/librpmDb.cv3.cc @@ -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. -- 2.7.4