- solv_free(evr);
- return 1;
-}
-
-
-/******************************************************************/
-/* Rpm Database stuff
- */
-
-struct rpmdbstate {
- Pool *pool;
- char *rootdir;
-
- RpmHead *rpmhead; /* header storage space */
- int rpmheadsize;
-
- int dbopened;
- DB_ENV *dbenv; /* database environment */
- DB *db; /* packages database */
- int byteswapped; /* endianess of packages database */
-};
-
-struct rpmdbentry {
- Id rpmdbid;
- Id nameoff;
-};
-
-#define ENTRIES_BLOCK 255
-#define NAMEDATA_BLOCK 1023
-
-
-static inline Id db2rpmdbid(unsigned char *db, int byteswapped)
-{
-#ifdef RPM5
- return db[0] << 24 | db[1] << 16 | db[2] << 8 | db[3];
-#else
-# if defined(WORDS_BIGENDIAN)
- if (!byteswapped)
-# else
- if (byteswapped)
-# endif
- return db[0] << 24 | db[1] << 16 | db[2] << 8 | db[3];
- else
- return db[3] << 24 | db[2] << 16 | db[1] << 8 | db[0];
-#endif
-}
-
-static inline void rpmdbid2db(unsigned char *db, Id id, int byteswapped)
-{
-#ifdef RPM5
- db[0] = id >> 24, db[1] = id >> 16, db[2] = id >> 8, db[3] = id;
-#else
-# if defined(WORDS_BIGENDIAN)
- if (!byteswapped)
-# else
- if (byteswapped)
-# endif
- db[0] = id >> 24, db[1] = id >> 16, db[2] = id >> 8, db[3] = id;
- else
- db[3] = id >> 24, db[2] = id >> 16, db[1] = id >> 8, db[0] = id;
-#endif
-}
-
-/* should look in /usr/lib/rpm/macros instead, but we want speed... */
-static int
-opendbenv(struct rpmdbstate *state, const char *rootdir)
-{
- char dbpath[PATH_MAX];
- DB_ENV *dbenv = 0;
- int r;
-
- if (db_env_create(&dbenv, 0))
- return pool_error(state->pool, 0, "db_env_create: %s", strerror(errno));
-#if defined(FEDORA) && (DB_VERSION_MAJOR >= 5 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5))
- dbenv->set_thread_count(dbenv, 8);
-#endif
- snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm", rootdir ? rootdir : "");
- if (access(dbpath, W_OK) == -1)
- {
- r = dbenv->open(dbenv, dbpath, DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL, 0);
- }
- else
- {
-#ifdef FEDORA
- r = dbenv->open(dbenv, dbpath, DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL, 0644);
-#else
- r = dbenv->open(dbenv, dbpath, DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL, 0);
-#endif
- }
- if (r)
- {
- pool_error(state->pool, 0, "dbenv->open: %s", strerror(errno));
- dbenv->close(dbenv, 0);
- return 0;
- }
- state->dbenv = dbenv;
- return 1;
-}
-
-static int
-openpkgdb(struct rpmdbstate *state)
-{
- if (state->dbopened)
- return state->dbopened > 0 ? 1 : 0;
- state->dbopened = -1;
- if (!state->dbenv && !opendbenv(state, state->rootdir))
- return 0;
- if (db_create(&state->db, state->dbenv, 0))
- {
- pool_error(state->pool, 0, "db_create: %s", strerror(errno));
- state->db = 0;
- state->dbenv->close(state->dbenv, 0);
- state->dbenv = 0;
- return 0;
- }
- if (state->db->open(state->db, 0, "Packages", 0, DB_UNKNOWN, DB_RDONLY, 0664))
- {
- pool_error(state->pool, 0, "db->open Packages: %s", strerror(errno));
- state->db->close(state->db, 0);
- state->db = 0;
- state->dbenv->close(state->dbenv, 0);
- state->dbenv = 0;
- return 0;
- }
- if (state->db->get_byteswapped(state->db, &state->byteswapped))
- {
- pool_error(state->pool, 0, "db->get_byteswapped: %s", strerror(errno));
- state->db->close(state->db, 0);
- state->db = 0;
- state->dbenv->close(state->dbenv, 0);
- state->dbenv = 0;
- return 0;
- }
- state->dbopened = 1;