reorder includes: add <config.h> if needed and include it at first
[ntk/apt.git] / apt-pkg / pkgcachegen.cc
index b0ee045..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;
@@ -479,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 == "all") ? _config->Find("APT::Architecture") : 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;
@@ -641,7 +641,7 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress)
               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
@@ -783,7 +783,7 @@ bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator &Ver,
 
    // We do not add self referencing provides
    if (Ver.ParentPkg().Name() == PkgName && (PkgArch == Ver.ParentPkg().Arch() ||
-       (PkgArch == "all" && _config->Find("APT::Architecture") == Ver.ParentPkg().Arch())))
+       (PkgArch == "all" && strcmp((Cache.StrP + Cache.HeaderP->Architecture), Ver.ParentPkg().Arch()) == 0)))
       return true;
    
    // Get a structure
@@ -1168,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);