* apt-pkg/contrib/configuration.cc:
[ntk/apt.git] / apt-pkg / pkgcachegen.cc
index 24e95f2..a39aa9f 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;
@@ -106,6 +105,9 @@ void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newM
    if (oldMap == newMap)
       return;
 
+   if (_config->FindB("Debug::pkgCacheGen", false))
+      std::clog << "Remaping from " << oldMap << " to " << newMap << std::endl;
+
    Cache.ReMap(false);
 
    CurrentFile += (pkgCache::PackageFile*) newMap - (pkgCache::PackageFile*) oldMap;
@@ -218,7 +220,7 @@ bool pkgCacheGenerator::MergeList(ListParser &List,
 
            // don't add a new description if we have one for the given
            // md5 && language
-           for ( ; Desc.end() == false; Desc++)
+           for ( ; Desc.end() == false; ++Desc)
               if (MD5SumValue(Desc.md5()) == CurMd5 && 
                   Desc.LanguageCode() == List.DescriptionLanguage())
                  duplicate=true;
@@ -227,7 +229,7 @@ bool pkgCacheGenerator::MergeList(ListParser &List,
            
            for (Desc = Ver.DescriptionList();
                 Desc.end() == false;
-                LastDesc = &Desc->NextDesc, Desc++)
+                LastDesc = &Desc->NextDesc, ++Desc)
            {
               if (MD5SumValue(Desc.md5()) == CurMd5) 
                {
@@ -393,7 +395,7 @@ bool pkgCacheGenerator::MergeFileProvides(ListParser &List)
       unsigned long Hash = List.VersionHash();
       pkgCache::VerIterator Ver = Pkg.VersionList();
       Dynamic<pkgCache::VerIterator> DynVer(Ver);
-      for (; Ver.end() == false; Ver++)
+      for (; Ver.end() == false; ++Ver)
       {
         if (Ver->Hash == Hash && Version.c_str() == Ver.VerStr())
         {
@@ -509,7 +511,7 @@ bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver,
    
    // Link it to the end of the list
    map_ptrloc *Last = &Ver->FileList;
-   for (pkgCache::VerFileIterator V = Ver.FileList(); V.end() == false; V++)
+   for (pkgCache::VerFileIterator V = Ver.FileList(); V.end() == false; ++V)
       Last = &V->NextFile;
    VF->NextFile = *Last;
    *Last = VF.Index();
@@ -566,7 +568,7 @@ bool pkgCacheGenerator::NewFileDesc(pkgCache::DescIterator &Desc,
 
    // Link it to the end of the list
    map_ptrloc *Last = &Desc->FileList;
-   for (pkgCache::DescFileIterator D = Desc.FileList(); D.end() == false; D++)
+   for (pkgCache::DescFileIterator D = Desc.FileList(); D.end() == false; ++D)
       Last = &D->NextFile;
 
    DF->NextFile = *Last;
@@ -621,7 +623,7 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress)
       // Create Conflicts in between the group
       pkgCache::GrpIterator G = GetCache().GrpBegin();
       Dynamic<pkgCache::GrpIterator> DynG(G);
-      for (; G.end() != true; G++)
+      for (; G.end() != true; ++G)
       {
         string const PkgName = G.Name();
         pkgCache::PkgIterator P = G.PackageList();
@@ -632,9 +634,11 @@ bool pkgCacheGenerator::FinishCache(OpProgress *Progress)
            Dynamic<pkgCache::PkgIterator> DynallPkg(allPkg);
            pkgCache::VerIterator V = P.VersionList();
            Dynamic<pkgCache::VerIterator> DynV(V);
-           for (; V.end() != true; V++)
+           for (; V.end() != true; ++V)
            {
-              char const * const Arch = P.Arch();
+               // copy P.Arch() into a string here as a cache remap
+               // in NewDepends() later may alter the pointer location
+              string Arch = P.Arch() == NULL ? "" : P.Arch();
               map_ptrloc *OldDepLast = NULL;
               /* MultiArch handling introduces a lot of implicit Dependencies:
                - MultiArch: same → Co-Installable if they have the same version
@@ -643,7 +647,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 (Arch == 0 || *A == Arch)
+                 if (*A == Arch)
                     continue;
                  /* We allow only one installed arch at the time
                     per group, therefore each group member conflicts
@@ -685,7 +689,7 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg,
                                   string const &Version,
                                   unsigned int const &Op,
                                   unsigned int const &Type,
-                                  map_ptrloc *OldDepLast)
+                                  map_ptrloc* &OldDepLast)
 {
    void const * const oldMap = Map.Data();
    // Get a structure
@@ -724,7 +728,7 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg,
    if (OldDepLast == NULL)
    {
       OldDepLast = &Ver->DependsList;
-      for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
+      for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; ++D)
         OldDepLast = &D->NextDepends;
    } else if (oldMap != Map.Data())
       OldDepLast += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap;
@@ -931,7 +935,7 @@ static bool CheckValidity(const string &CacheFile,
       return false;
    }
 
-   if (List.GetLastModifiedTime() < GetModificationTime(CacheFile))
+   if (List.GetLastModifiedTime() > GetModificationTime(CacheFile))
    {
       if (Debug == true)
         std::clog << "sources.list is newer than the cache" << std::endl;
@@ -954,7 +958,7 @@ static bool CheckValidity(const string &CacheFile,
       verify the IMS data and check that it is on the disk too.. */
    SPtrArray<bool> Visited = new bool[Cache.HeaderP->PackageFileCount];
    memset(Visited,0,sizeof(*Visited)*Cache.HeaderP->PackageFileCount);
-   for (; Start != End; Start++)
+   for (; Start != End; ++Start)
    {
       if (Debug == true)
         std::clog << "Checking PkgFile " << (*Start)->Describe() << ": ";
@@ -1021,7 +1025,7 @@ static bool CheckValidity(const string &CacheFile,
 static unsigned long ComputeSize(FileIterator Start,FileIterator End)
 {
    unsigned long TotalSize = 0;
-   for (; Start != End; Start++)
+   for (; Start != End; ++Start)
    {
       if ((*Start)->HasPackages() == false)
         continue;      
@@ -1039,7 +1043,7 @@ static bool BuildCache(pkgCacheGenerator &Gen,
                       FileIterator Start, FileIterator End)
 {
    FileIterator I;
-   for (I = Start; I != End; I++)
+   for (I = Start; I != End; ++I)
    {
       if ((*I)->HasPackages() == false)
         continue;
@@ -1069,7 +1073,7 @@ static bool BuildCache(pkgCacheGenerator &Gen,
         Progress->Done();
       TotalSize = ComputeSize(Start, End);
       CurrentSize = 0;
-      for (I = Start; I != End; I++)
+      for (I = Start; I != End; ++I)
       {
         unsigned long Size = (*I)->Size();
         if (Progress != NULL)
@@ -1116,12 +1120,12 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
    vector<pkgIndexFile *> Files;
    for (vector<metaIndex *>::const_iterator i = List.begin();
         i != List.end();
-        i++)
+        ++i)
    {
       vector <pkgIndexFile *> *Indexes = (*i)->GetIndexFiles();
       for (vector<pkgIndexFile *>::const_iterator j = Indexes->begin();
           j != Indexes->end();
-          j++)
+          ++j)
          Files.push_back (*j);
    }