- fix various issues with distroverpkg (Dmitry V. Levin)
authorpmatilai <pmatilai>
Wed, 5 Apr 2006 09:19:02 +0000 (09:19 +0000)
committerpmatilai <pmatilai>
Wed, 5 Apr 2006 09:19:02 +0000 (09:19 +0000)
apt-pkg/rpm/rpmsystem.cc

index 7398078..6a925e1 100644 (file)
@@ -249,31 +249,50 @@ signed rpmSystem::Score(Configuration const &Cnf)
 string rpmSystem::DistroVer(Configuration const &Cnf)
 {
    string DistroVerPkg = _config->Find("Apt::DistroVerPkg");
-   string DistroVersion = "";
-
-
-   if (! DistroVerPkg.empty()) {
-      rpmts ts;
-      char *version;
-      int type, count, rc;
-      rpmdbMatchIterator iter;
+   string DistroVersion;
+
+   if (DistroVerPkg.empty())
+      return DistroVersion;
+
+#if RPM_VERSION >= 0x040100
+   rpmts ts;
+   ts = rpmtsCreate();
+   rpmtsSetVSFlags(ts, (rpmVSFlags_e)-1);
+   rpmtsSetRootDir(ts, NULL);
+   if (rpmtsOpenDB(ts, O_RDONLY))
+      return DistroVersion;
+#else
+   rpmdb DB;
+   string RootDir = _config->Find("RPM::RootDir");
+   const char *RootDirStr = RootDir.empty() ? NULL : RootDir.c_str();
+   if (rpmdbOpen(RootDirStr, &DB, O_RDONLY, 0644))
+      return DistroVersion;
+#endif
 
-      ts = rpmtsCreate();
-      rpmtsSetVSFlags(ts, (rpmVSFlags_e)-1);
-      rpmtsSetRootDir(ts, NULL);
-      rc = rpmtsOpenDB(ts, O_RDWR);
+   rpmdbMatchIterator iter;
+#if RPM_VERSION >= 0x040100
+   iter = rpmtsInitIterator(ts, (rpmTag)RPMDBI_LABEL, DistroVerPkg.c_str(), 0);
+#else
+   iter = rpmdbInitIterator(DB, RPMDBI_LABEL, DistroVerPkg.c_str(), 0);
+#endif
+   Header hdr;
+   while ((hdr = rpmdbNextIterator(iter)) != NULL) {
+      void *version;
+      int type, count;
 
-      Header hdr;
-      iter = rpmtsInitIterator(ts, (rpmTag)RPMDBI_LABEL, DistroVerPkg.c_str(), 0);
-      while ((hdr = rpmdbNextIterator(iter)) != NULL) {
-         headerGetEntry(hdr, RPMTAG_VERSION, &type, (void **)&version, &count);
-        DistroVersion = version;
+      if (headerGetEntry(hdr, RPMTAG_VERSION, &type, &version, &count)) {
+         DistroVersion = (char *)version;
+         headerFreeData(&version, (rpmTagType)type);
          break;
       }
-      rpmdbFreeIterator(iter);
-      rpmtsFree(ts);
    }
-   
+   rpmdbFreeIterator(iter);
+#if RPM_VERSION >= 0x040100
+   rpmtsFree(ts);
+#else
+   rpmdbClose(DB);
+#endif
+
    return DistroVersion;
 }