reorder includes: add <config.h> if needed and include it at first
[ntk/apt.git] / apt-pkg / pkgcachegen.cc
index ed35174..1cae231 100644 (file)
@@ -11,6 +11,7 @@
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
 #define APT_COMPATIBILITY 986
+#include <config.h>
 
 #include <apt-pkg/pkgcachegen.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/sptr.h>
 #include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/macros.h>
-
 #include <apt-pkg/tagfile.h>
 
-#include <apti18n.h>
-
 #include <vector>
-
 #include <sys/stat.h>
 #include <unistd.h>
 #include <errno.h>
 #include <stdio.h>
+
+#include <apti18n.h>
                                                                        /*}}}*/
 typedef vector<pkgIndexFile *>::iterator FileIterator;
 template <typename Iter> std::vector<Iter*> pkgCacheGenerator::Dynamic<Iter>::toReMap;
@@ -178,23 +177,12 @@ bool pkgCacheGenerator::MergeList(ListParser &List,
       if (PackageName.empty() == true)
         return false;
 
-      /* As we handle Arch all packages as architecture bounded
-         we add all information to every (simulated) arch package */
-      std::vector<string> genArch;
-      if (List.ArchitectureAll() == true) {
-        genArch = APT::Configuration::getArchitectures();
-        if (genArch.size() != 1)
-           genArch.push_back("all");
-      } else
-        genArch.push_back(List.Architecture());
-
-      for (std::vector<string>::const_iterator arch = genArch.begin();
-          arch != genArch.end(); ++arch)
-      {
+      string const Arch = List.Architecture();
       // Get a pointer to the package structure
       pkgCache::PkgIterator Pkg;
       Dynamic<pkgCache::PkgIterator> DynPkg(Pkg);
-      if (NewPackage(Pkg, PackageName, *arch) == false)
+      if (NewPackage(Pkg, PackageName, Arch) == false)
         return _error->Error(_("Error occurred while processing %s (NewPackage)"),PackageName.c_str());
       Counter++;
       if (Counter % 100 == 0 && Progress != 0)
@@ -351,7 +339,6 @@ bool pkgCacheGenerator::MergeList(ListParser &List,
 
       if ((*LastDesc == 0 && _error->PendingError()) || NewFileDesc(Desc,List) == false)
         return _error->Error(_("Error occurred while processing %s (NewFileDesc2)"),PackageName.c_str());
-      }
    }
 
    FoundFileDeps |= List.HasFileDeps();
@@ -491,7 +478,8 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name
    // Set the name, arch and the ID
    Pkg->Name = Grp->Name;
    Pkg->Group = Grp.Index();
-   map_ptrloc const idxArch = WriteUniqString(Arch.c_str());
+   // all is mapped to the native architecture
+   map_ptrloc const idxArch = (Arch == "all") ? Cache.HeaderP->Architecture : WriteUniqString(Arch.c_str());
    if (unlikely(idxArch == 0))
       return false;
    Pkg->Arch = idxArch;
@@ -638,27 +626,22 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress)
         Dynamic<pkgCache::PkgIterator> DynP(P);
         for (; P.end() != true; P = G.NextPkg(P))
         {
-           if (strcmp(P.Arch(),"all") == 0)
-              continue;
            pkgCache::PkgIterator allPkg;
            Dynamic<pkgCache::PkgIterator> DynallPkg(allPkg);
            pkgCache::VerIterator V = P.VersionList();
            Dynamic<pkgCache::VerIterator> DynV(V);
            for (; V.end() != true; V++)
            {
-              string const Arch = V.Arch(true);
+              char const * const Arch = P.Arch();
               map_ptrloc *OldDepLast = NULL;
               /* MultiArch handling introduces a lot of implicit Dependencies:
                - MultiArch: same → Co-Installable if they have the same version
                - Architecture: all → Need to be Co-Installable for internal reasons
                - All others conflict with all other group members */
-              bool const coInstall = (V->MultiArch == pkgCache::Version::All ||
-                                       V->MultiArch == pkgCache::Version::Same);
-              if (V->MultiArch == pkgCache::Version::All && allPkg.end() == true)
-                 allPkg = G.FindPkg("all");
+              bool const coInstall = ((V->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same);
               for (vector<string>::const_iterator A = archs.begin(); A != archs.end(); ++A)
               {
-                 if (*A == Arch)
+                 if (Arch == 0 || *A == Arch)
                     continue;
                  /* We allow only one installed arch at the time
                     per group, therefore each group member conflicts
@@ -677,13 +660,6 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress)
                     NewDepends(D, V, V.VerStr(),
                                pkgCache::Dep::NotEquals, pkgCache::Dep::DpkgBreaks,
                                OldDepLast);
-                    if (V->MultiArch == pkgCache::Version::All)
-                    {
-                       // Depend on ${self}:all which does depend on nothing
-                       NewDepends(allPkg, V, V.VerStr(),
-                                  pkgCache::Dep::Equals, pkgCache::Dep::Depends,
-                                  OldDepLast);
-                    }
                  } else {
                        // Conflicts: ${self}:other
                        NewDepends(D, V, "",
@@ -806,7 +782,8 @@ bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator &Ver,
    pkgCache &Cache = Owner->Cache;
 
    // We do not add self referencing provides
-   if (Ver.ParentPkg().Name() == PkgName && PkgArch == Ver.Arch(true))
+   if (Ver.ParentPkg().Name() == PkgName && (PkgArch == Ver.ParentPkg().Arch() ||
+       (PkgArch == "all" && strcmp((Cache.StrP + Cache.HeaderP->Architecture), Ver.ParentPkg().Arch()) == 0)))
       return true;
    
    // Get a structure
@@ -1191,16 +1168,32 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
    SPtr<DynamicMMap> Map;
    if (Writeable == true && CacheFile.empty() == false)
    {
+      _error->PushToStack();
       unlink(CacheFile.c_str());
       CacheF = new FileFd(CacheFile,FileFd::WriteAtomic);
       fchmod(CacheF->Fd(),0644);
       Map = CreateDynamicMMap(CacheF, MMap::Public);
       if (_error->PendingError() == true)
-        return false;
-      if (Debug == true)
+      {
+        delete CacheF.UnGuard();
+        delete Map.UnGuard();
+        if (Debug == true)
+           std::clog << "Open filebased MMap FAILED" << std::endl;
+        Writeable = false;
+        if (AllowMem == false)
+        {
+           _error->MergeWithStack();
+           return false;
+        }
+        _error->RevertToStack();
+      }
+      else if (Debug == true)
+      {
+        _error->MergeWithStack();
         std::clog << "Open filebased MMap" << std::endl;
+      }
    }
-   else
+   if (Writeable == false || CacheFile.empty() == true)
    {
       // Just build it in memory..
       Map = CreateDynamicMMap(NULL);