]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/pkgcachegen.cc
always create pkg at the time pkg:arch is created
[apt.git] / apt-pkg / pkgcachegen.cc
index 43347cf65b910d37a8a325e3d5cdf81861d92f3c..6e307fba9b32df572709ea1a324815bb7aeeb3d5 100644 (file)
@@ -141,7 +141,7 @@ pkgCacheGenerator::~pkgCacheGenerator()
    Map.Sync(0,sizeof(pkgCache::Header));
 }
                                                                        /*}}}*/
-void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newMap) {/*{{{*/
+void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newMap, size_t oldSize) {/*{{{*/
    if (oldMap == newMap)
       return;
 
@@ -177,31 +177,42 @@ void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newM
    for (std::vector<pkgCache::RlsFileIterator*>::const_iterator i = Dynamic<pkgCache::RlsFileIterator>::toReMap.begin();
        i != Dynamic<pkgCache::RlsFileIterator>::toReMap.end(); ++i)
       (*i)->ReMap(oldMap, newMap);
+   for (APT::StringView* ViewP : Dynamic<APT::StringView>::toReMap) {
+      // Ignore views outside of the cache.
+      if (ViewP->data() < static_cast<const char*>(oldMap)
+        || ViewP->data() > static_cast<const char*>(oldMap) + oldSize)
+        continue;
+      const char *data = ViewP->data() + (static_cast<const char*>(newMap) - static_cast<const char*>(oldMap));
+      *ViewP = StringView(data , ViewP->size());
+   }
 }                                                                      /*}}}*/
 // CacheGenerator::WriteStringInMap                                    /*{{{*/
 map_stringitem_t pkgCacheGenerator::WriteStringInMap(const char *String,
                                        const unsigned long &Len) {
+   size_t oldSize = Map.Size();
    void const * const oldMap = Map.Data();
    map_stringitem_t const index = Map.WriteString(String, Len);
    if (index != 0)
-      ReMap(oldMap, Map.Data());
+      ReMap(oldMap, Map.Data(), oldSize);
    return index;
 }
                                                                        /*}}}*/
 // CacheGenerator::WriteStringInMap                                    /*{{{*/
 map_stringitem_t pkgCacheGenerator::WriteStringInMap(const char *String) {
+   size_t oldSize = Map.Size();
    void const * const oldMap = Map.Data();
    map_stringitem_t const index = Map.WriteString(String);
    if (index != 0)
-      ReMap(oldMap, Map.Data());
+      ReMap(oldMap, Map.Data(), oldSize);
    return index;
 }
                                                                        /*}}}*/
 map_pointer_t pkgCacheGenerator::AllocateInMap(const unsigned long &size) {/*{{{*/
+   size_t oldSize = Map.Size();
    void const * const oldMap = Map.Data();
    map_pointer_t const index = Map.Allocate(size);
    if (index != 0)
-      ReMap(oldMap, Map.Data());
+      ReMap(oldMap, Map.Data(), oldSize);
    return index;
 }
                                                                        /*}}}*/
@@ -500,6 +511,7 @@ bool pkgCacheGenerator::AddNewDescription(ListParser &List, pkgCache::VerIterato
 /* This creates a new group structure and adds it to the hash table */
 bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, StringView Name)
 {
+   Dynamic<StringView> DName(Name);
    Grp = Cache.FindGrp(Name);
    if (Grp.end() == false)
       return true;
@@ -534,6 +546,8 @@ bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, StringView Name)
 bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg, StringView Name,
                                        StringView Arch) {
    pkgCache::GrpIterator Grp;
+   Dynamic<StringView> DName(Name);
+   Dynamic<StringView> DArch(Arch);
    Dynamic<pkgCache::GrpIterator> DynGrp(Grp);
    if (unlikely(NewGroup(Grp, Name) == false))
       return false;
@@ -646,29 +660,44 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg, StringView Name,
    if (Arch == "any")
    {
       size_t const found = Name.find(':');
-      StringView const NameA = Name.substr(0, found);
-      StringView const ArchA = Name.substr(found + 1);
-      pkgCache::PkgIterator PkgA = Cache.FindPkg(NameA, ArchA);
-      if (PkgA.end() == false)
+      StringView ArchA = Name.substr(found + 1);
+      if (ArchA != "any")
       {
+        // ArchA is used inside the loop which might remap (NameA is not used)
+        Dynamic<StringView> DynArchA(ArchA);
+        StringView NameA = Name.substr(0, found);
+        pkgCache::PkgIterator PkgA = Cache.FindPkg(NameA, ArchA);
         Dynamic<pkgCache::PkgIterator> DynPkgA(PkgA);
-        pkgCache::PrvIterator Prv = PkgA.ProvidesList();
-        for (; Prv.end() == false; ++Prv)
+        if (PkgA.end())
         {
-           if (Prv.IsMultiArchImplicit())
-              continue;
-           pkgCache::VerIterator V = Prv.OwnerVer();
-           if (ArchA != V.ParentPkg().Arch())
-              continue;
-           if (NewProvides(V, Pkg, V->VerStr, pkgCache::Flag::MultiArchImplicit | pkgCache::Flag::ArchSpecific) == false)
+           Dynamic<StringView> DynNameA(NameA);
+           if (NewPackage(PkgA, NameA, ArchA) == false)
               return false;
         }
-        pkgCache::VerIterator V = PkgA.VersionList();
-        Dynamic<pkgCache::VerIterator> DynV(V);
-        for (; V.end() == false; ++V)
+        if (unlikely(PkgA.end()))
+           return _error->Fatal("NewPackage was successful for %s:%s,"
+                 "but the package doesn't exist anyhow!",
+                 NameA.to_string().c_str(), ArchA.to_string().c_str());
+        else
         {
-           if (NewProvides(V, Pkg, V->VerStr, pkgCache::Flag::MultiArchImplicit | pkgCache::Flag::ArchSpecific) == false)
-              return false;
+           pkgCache::PrvIterator Prv = PkgA.ProvidesList();
+           for (; Prv.end() == false; ++Prv)
+           {
+              if (Prv.IsMultiArchImplicit())
+                 continue;
+              pkgCache::VerIterator V = Prv.OwnerVer();
+              if (ArchA != V.ParentPkg().Arch())
+                 continue;
+              if (NewProvides(V, Pkg, V->VerStr, pkgCache::Flag::MultiArchImplicit | pkgCache::Flag::ArchSpecific) == false)
+                 return false;
+           }
+           pkgCache::VerIterator V = PkgA.VersionList();
+           Dynamic<pkgCache::VerIterator> DynV(V);
+           for (; V.end() == false; ++V)
+           {
+              if (NewProvides(V, Pkg, V->VerStr, pkgCache::Flag::MultiArchImplicit | pkgCache::Flag::ArchSpecific) == false)
+                 return false;
+           }
         }
       }
    }
@@ -1011,6 +1040,9 @@ bool pkgCacheListParser::NewDepends(pkgCache::VerIterator &Ver,
 {
    pkgCache::GrpIterator Grp;
    Dynamic<pkgCache::GrpIterator> DynGrp(Grp);
+   Dynamic<StringView> DynPackageName(PackageName);
+   Dynamic<StringView> DynArch(Arch);
+   Dynamic<StringView> DynVersion(Version);
    if (unlikely(Owner->NewGroup(Grp, PackageName) == false))
       return false;
 
@@ -1078,6 +1110,9 @@ bool pkgCacheListParser::NewProvides(pkgCache::VerIterator &Ver,
                                                uint8_t const Flags)
 {
    pkgCache const &Cache = Owner->Cache;
+   Dynamic<StringView> DynPkgName(PkgName);
+   Dynamic<StringView> DynArch(PkgArch);
+   Dynamic<StringView> DynVersion(Version);
 
    // We do not add self referencing provides
    if (Ver.ParentPkg().Name() == PkgName && (PkgArch == Ver.ParentPkg().Arch() ||
@@ -1131,6 +1166,8 @@ bool pkgCacheListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, StringVi
    pkgCache &Cache = Owner->Cache;
    pkgCache::GrpIterator Grp = Cache.FindGrp(Package);
    Dynamic<pkgCache::GrpIterator> DynGrp(Grp);
+   Dynamic<StringView> DynPackage(Package);
+   Dynamic<StringView> DynVersion(Version);
 
    if (Grp.end() == true)
       return NewProvides(Ver, Package, Cache.NativeArch(), Version, Flags);