Kaynağa Gözat

abstract version hash comparison a bit

In #737085 we see that apt can be confused if informations about
versions only differ slightly. This commit adds a way of at least adding
a few more data points with the next abi break to help a bit with it.

Git-Dch: Ignore
David Kalnischkies 12 yıl önce
ebeveyn
işleme
68134bda88

+ 21 - 0
apt-pkg/deb/deblistparser.cc

@@ -938,3 +938,24 @@ unsigned char debListParser::GetPrio(string Str)
    return Out;
 }
 									/*}}}*/
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+bool debListParser::SameVersion(unsigned short const Hash,		/*{{{*/
+      pkgCache::VerIterator const &Ver)
+{
+   if (pkgCacheGenerator::ListParser::SameVersion(Hash, Ver) == false)
+      return false;
+   // status file has no (Download)Size, but all others are fair game
+   // status file is parsed last, so the first version we encounter is
+   // probably also the version we have downloaded
+   unsigned long long const Size = Section.FindULL("Size");
+   if (Size != 0 && Size != Ver->Size)
+      return false;
+   // available everywhere, but easier to check here than to include in VersionHash
+   unsigned char MultiArch = ParseMultiArch(false);
+   if (MultiArch != Ver->MultiArch)
+      return false;
+   // for all practical proposes (we can check): same version
+   return true;
+}
+									/*}}}*/
+#endif

+ 3 - 0
apt-pkg/deb/deblistparser.h

@@ -70,6 +70,9 @@ class debListParser : public pkgCacheGenerator::ListParser
    virtual std::string DescriptionLanguage();
    virtual MD5SumValue Description_md5();
    virtual unsigned short VersionHash();
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+   virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver);
+#endif
    virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
 			   pkgCache::VerIterator &Ver);
    virtual unsigned long Offset() {return iOffset;};

+ 4 - 0
apt-pkg/pkgcache.cc

@@ -55,7 +55,11 @@ pkgCache::Header::Header()
    /* Whenever the structures change the major version should be bumped,
       whenever the generator changes the minor version should be bumped. */
    MajorVersion = 8;
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+   MinorVersion = 2;
+#else
    MinorVersion = 1;
+#endif
    Dirty = false;
    
    HeaderSz = sizeof(pkgCache::Header);

+ 10 - 4
apt-pkg/pkgcachegen.cc

@@ -356,7 +356,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator
    map_ptrloc *LastVer = &Pkg->VersionList;
    void const * oldMap = Map.Data();
 
-   unsigned long const Hash = List.VersionHash();
+   unsigned short const Hash = List.VersionHash();
    if (Ver.end() == false)
    {
       /* We know the list is sorted so we use that fact in the search.
@@ -369,7 +369,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator
 	 if (Res > 0)
 	    break;
 	 // Versionstrings are equal - is hash also equal?
-	 if (Res == 0 && Ver->Hash == Hash)
+	 if (Res == 0 && List.SameVersion(Hash, Ver) == true)
 	    break;
 	 // proceed with the next till we have either the right
 	 // or we found another version (which will be lower)
@@ -558,12 +558,12 @@ bool pkgCacheGenerator::MergeFileProvides(ListParser &List)
       if (Counter % 100 == 0 && Progress != 0)
 	 Progress->Progress(List.Offset());
 
-      unsigned long Hash = List.VersionHash();
+      unsigned short Hash = List.VersionHash();
       pkgCache::VerIterator Ver = Pkg.VersionList();
       Dynamic<pkgCache::VerIterator> DynVer(Ver);
       for (; Ver.end() == false; ++Ver)
       {
-	 if (Ver->Hash == Hash && Version == Ver.VerStr())
+	 if (List.SameVersion(Hash, Ver) == true && Version == Ver.VerStr())
 	 {
 	    if (List.CollectFileProvides(Cache,Ver) == false)
 	       return _error->Error(_("Error occurred while processing %s (%s%d)"),
@@ -1051,6 +1051,12 @@ bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator &Ver,
    return true;
 }
 									/*}}}*/
+bool pkgCacheGenerator::ListParser::SameVersion(unsigned short const Hash,/*{{{*/
+      pkgCache::VerIterator const &Ver)
+{
+   return Hash == Ver->Hash;
+}
+									/*}}}*/
 // CacheGenerator::SelectFile - Select the current file being parsed	/*{{{*/
 // ---------------------------------------------------------------------
 /* This is used to select which file is to be associated with all newly

+ 9 - 0
apt-pkg/pkgcachegen.h

@@ -164,6 +164,15 @@ class pkgCacheGenerator::ListParser
    virtual std::string DescriptionLanguage() = 0;
    virtual MD5SumValue Description_md5() = 0;
    virtual unsigned short VersionHash() = 0;
+   /** compare currently parsed version with given version
+    *
+    * \param Hash of the currently parsed version
+    * \param Ver to compare with
+    */
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+   virtual
+#endif
+      APT_PURE bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver);
    virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
 			   pkgCache::VerIterator &Ver) = 0;
    virtual unsigned long Offset() = 0;