]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-get.cc
Merge remote-tracking branch 'origin/feature/deb-src-bts731102' into feature/source...
[apt.git] / cmdline / apt-get.cc
index 3003c19713d103671077895847346206e32f0897..7e59f3d6792c6a6dd7c2a34dcb65c6e8e759b7ff 100644 (file)
@@ -63,6 +63,8 @@
 #include <apt-private/private-moo.h>
 #include <apt-private/private-utils.h>
 
+#include <apt-pkg/debmetaindex.h>
+
 #include <apt-private/acqprogress.h>
 
 #include <set>
@@ -132,6 +134,63 @@ bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache,
    return true;
 }
                                                                        /*}}}*/
+
+
+// helper that can go wit hthe next ABI break
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
+std::string MetaIndexFileNameOnDisk(metaIndex *metaindex)
+{
+   // FIXME: this cast is the horror, the horror
+   debReleaseIndex *r = (debReleaseIndex*)metaindex;
+
+   // see if we have a InRelease file
+   std::string PathInRelease =  r->MetaIndexFile("InRelease");
+   if (FileExists(PathInRelease))
+      return PathInRelease;
+
+   // and if not return the normal one
+   if (FileExists(PathInRelease))
+      return r->MetaIndexFile("Release");
+
+   return "";
+}
+#endif
+
+// GetReleaseForSourceRecord - Return Suite for the given srcrecord    /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+std::string GetReleaseForSourceRecord(pkgSourceList *SrcList,
+                                      pkgSrcRecords::Parser *Parse)
+{
+   // try to find release
+   const pkgIndexFile& CurrentIndexFile = Parse->Index();
+
+   for (pkgSourceList::const_iterator S = SrcList->begin(); 
+        S != SrcList->end(); ++S)
+   {
+      vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles();
+      for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin();
+           IF != Indexes->end(); ++IF)
+      {
+         if (&CurrentIndexFile == (*IF))
+         {
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
+            std::string path = MetaIndexFileNameOnDisk(*S);
+#else
+            std::string path = (*S)->LocalFileName();
+#endif
+            if (path != "") 
+            {
+               indexRecords records;
+               records.Load(path);
+               return records.GetSuite();
+            }
+         }
+      }
+   }
+   return "";
+}
+                                                                       /*}}}*/
 // FindSrc - Find a source record                                      /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -140,7 +199,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
                               CacheFile &CacheFile)
 {
    string VerTag;
-   string DefRel = _config->Find("APT::Default-Release");
+   string RelTag = _config->Find("APT::Default-Release");
    string TmpSrc = Name;
    pkgDepCache *Cache = CacheFile.GetDepCache();
 
@@ -148,7 +207,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
    const size_t found = TmpSrc.find_last_of("/=");
    if (found != string::npos) {
       if (TmpSrc[found] == '/')
-        DefRel = TmpSrc.substr(found+1);
+        RelTag = TmpSrc.substr(found+1);
       else
         VerTag = TmpSrc.substr(found+1);
       TmpSrc = TmpSrc.substr(0,found);
@@ -161,7 +220,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
    const pkgCache::PkgIterator Pkg = Cache->FindPkg(TmpSrc);
    if (MatchSrcOnly == false && Pkg.end() == false) 
    {
-      if(VerTag.empty() == false || DefRel.empty() == false) 
+      if(VerTag.empty() == false || RelTag.empty() == false) 
       {
         bool fuzzy = false;
         // we have a default release, try to locate the pkg. we do it like
@@ -201,8 +260,8 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
 
               // or we match against a release
               if(VerTag.empty() == false ||
-                 (VF.File().Archive() != 0 && VF.File().Archive() == DefRel) ||
-                 (VF.File().Codename() != 0 && VF.File().Codename() == DefRel)) 
+                 (VF.File().Archive() != 0 && VF.File().Archive() == RelTag) ||
+                 (VF.File().Codename() != 0 && VF.File().Codename() == RelTag)) 
               {
                  pkgRecords::Parser &Parse = Recs.Lookup(VF);
                  Src = Parse.SourcePkg();
@@ -220,23 +279,13 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
            if (Src.empty() == false)
               break;
         }
-#if 0
-        if (Src.empty() == true) 
-        {
-           // Sources files have no codename information
-           if (VerTag.empty() == true && DefRel.empty() == false) 
-           {
-              _error->Warning(_("Ignore unavailable target release '%s' of package '%s'"), DefRel.c_str(), TmpSrc.c_str());
-               return 0;
-           }
-        }
-#endif
       }
       if (Src.empty() == true)
       {
         // if we don't have found a fitting package yet so we will
         // choose a good candidate and proceed with that.
         // Maybe we will find a source later on with the right VerTag
+         // or RelTag
         pkgCache::VerIterator Ver = Cache->GetCandidateVer(Pkg);
         if (Ver.end() == false) 
         {
@@ -249,7 +298,9 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
    }
 
    if (Src.empty() == true)
+   {
       Src = TmpSrc;
+   }
    else 
    {
       /* if we have a source pkg name, make sure to only search
@@ -267,7 +318,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
    pkgSrcRecords::Parser *Last = 0;
    unsigned long Offset = 0;
    string Version;
-   string FoundRel;
+   pkgSourceList *SrcList = CacheFile.GetSourceList();
 
    /* Iterate over all of the hits, which includes the resulting
       binary packages in the search */
@@ -279,41 +330,20 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
       {
         const string Ver = Parse->Version();
 
-
-         // find release
-         const pkgIndexFile& SI = Parse->Index();
-         pkgSourceList *SrcList = CacheFile.GetSourceList();
-         for (pkgSourceList::const_iterator S = SrcList->begin(); 
-              S != SrcList->end(); ++S)
+         // See if we need to look for a specific release tag
+         if (RelTag != "")
          {
-            vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles();
-            for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin();
-                 IF != Indexes->end(); ++IF)
+            const string Rel = GetReleaseForSourceRecord(SrcList, Parse);
+
+            if (Rel == RelTag)
             {
-               if (&SI == (*IF))
-               {
-                  std::string dirname = _config->FindDir("Dir::State::lists");
-                  std::string path;
-                  path = dirname + URItoFileName((*S)->GetURI()) + "dists_" + (*S)->GetDist() + "_Release";
-                  if (!FileExists(path))
-                     path = dirname + URItoFileName((*S)->GetURI()) + "dists_" + (*S)->GetDist() + "_InRelease";
-                  indexRecords records;
-                  records.Load(path);
-                  if (records.GetSuite() == DefRel)
-                  {
-                     ioprintf(clog, "Selectied version '%s' (%s) for %s\n", 
-                              Ver.c_str(), DefRel.c_str(), Src.c_str());
-                     Last = Parse;
-                     Offset = Parse->Offset();
-                     Version = Ver;
-                     FoundRel = DefRel;
-                     break;
-                  }
-               }
+               ioprintf(c1out, "Selectied version '%s' (%s) for %s\n", 
+                        Ver.c_str(), RelTag.c_str(), Src.c_str());
+               Last = Parse;
+               Offset = Parse->Offset();
+               break;
             }
          }
-         if (DefRel.empty() == false && (DefRel == FoundRel))
-            break;
 
         // Ignore all versions which doesn't fit
         if (VerTag.empty() == false &&
@@ -327,14 +357,14 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
            Version = Ver;
         }
 
-        // was the version check above an exact match? If so, we don't need to look further
+        // was the version check above an exact match?
+         // If so, we don't need to look further
          if (VerTag.empty() == false && (VerTag == Ver))
-         {
            break;
-         }
       }
       if (Last != 0 || VerTag.empty() == true)
         break;
+      _error->Error(_("Ignore unavailable version '%s' of package '%s'"), VerTag.c_str(), TmpSrc.c_str());
       return 0;
    }