- add support for yum-style distroverpkg package whose version can be
authorpmatilai <pmatilai>
Mon, 6 Feb 2006 19:11:06 +0000 (19:11 +0000)
committerpmatilai <pmatilai>
Mon, 6 Feb 2006 19:11:06 +0000 (19:11 +0000)
  read from rpmdb (or overwritten with config) and new variable substitution
  $(VERSION) -> distrover in sources.list

apt-pkg/init.cc
apt-pkg/pkgsystem.h
apt-pkg/rpm/rpmhandler.cc
apt-pkg/rpm/rpmsystem.cc
apt-pkg/rpm/rpmsystem.h
apt-pkg/sourcelist.cc

index bdac517..815e828 100644 (file)
@@ -158,6 +158,11 @@ bool pkgInitSystem(Configuration &Cnf,pkgSystem *&Sys)
         return _error->Error(_("Unable to determine a suitable system type"));
    }
 
+   // PM:2006-02-06
+   if (Cnf.Find("APT::DistroVersion", "").empty()) {
+       Cnf.Set("APT::DistroVersion", Sys->DistroVer(Cnf));
+   }
+
    // CNC:2003-03-15
    bool Ret = Sys->Initialize(Cnf);
 #ifdef WITH_LUA
index 210e671..6ea113d 100644 (file)
@@ -97,6 +97,9 @@ class pkgSystem
    /* Evauluate how 'right' we are for this system based on the filesystem
       etc.. */
    virtual signed Score(Configuration const &/*Cnf*/) {return 0;};
+
+   // PM:2006-02-06 Distro version from package system
+   virtual string DistroVer(Configuration const &/*Cnf*/) {return "";};
    
    // CNC:2002-07-03
    // Do environment specific pre-processing over the Index Files
index eede5cf..0413a49 100644 (file)
@@ -405,8 +405,10 @@ RPMDBHandler::RPMDBHandler(bool WriteLock)
    rpmdbFreeIterator(countIt);
 #else
    iSize = St.st_size;
+
 #endif
 
+
    // Restore just after opening the database, and just after closing.
    if (WriteLock) {
       struct utimbuf Ut;
index dc6e695..69169c7 100644 (file)
 #include <unistd.h>
 #include <stdlib.h>
 #include <dirent.h>
+#include <fcntl.h>
 #include <rpm/rpmlib.h>
 #include <assert.h>
                                                                        /*}}}*/
+// for distrover
+#if RPM_VERSION >= 0x040101
+#include <rpmdb.h>
+#endif
+
 #if RPM_VERSION >= 0x040201
 extern int _rpmds_nopromote;
 #endif
@@ -238,6 +244,38 @@ signed rpmSystem::Score(Configuration const &Cnf)
 
    return Score;
 }
+
+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;
+
+      ts = rpmtsCreate();
+      rpmtsSetVSFlags(ts, (rpmVSFlags_e)-1);
+      rpmtsSetRootDir(ts, NULL);
+      rc = rpmtsOpenDB(ts, O_RDWR);
+
+      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;
+         break;
+      }
+      rpmdbFreeIterator(iter);
+      rpmtsFree(ts);
+   }
+   
+   return DistroVersion;
+}
+
                                                                        /*}}}*/
 // System::AddStatusFiles - Register the status files                  /*{{{*/
 // ---------------------------------------------------------------------
index bc884da..358b7c4 100644 (file)
@@ -59,6 +59,7 @@ class rpmSystem : public pkgSystem
    virtual bool Initialize(Configuration &Cnf);
    virtual bool ArchiveSupported(const char *Type);
    virtual signed Score(Configuration const &Cnf);
+   virtual string DistroVer(Configuration const &Cnf);
    virtual bool AddStatusFiles(vector<pkgIndexFile *> &List);
    virtual bool AddSourceFiles(vector<pkgIndexFile *> &List);
    virtual bool FindIndex(pkgCache::PkgFileIterator File,
index 316bfc1..326791a 100644 (file)
@@ -113,6 +113,8 @@ bool pkgSourceList::Type::ParseLine(vector<pkgIndexFile *> &List,
    
    // CNC:2004-05-18 
    Dist = SubstVar(Dist,"$(ARCH)",_config->Find("APT::Architecture"));
+   // PM:2006-02-06
+   Dist = SubstVar(Dist,"$(VERSION)",_config->Find("APT::DistroVersion"));
 
    // Grab the rest of the dists
    if (ParseQuoteWord(Buffer,Section) == false)