1212#include < config.h>
1313
1414#include < apt-pkg/configuration.h>
15+ #include < apt-pkg/deblistparser.h>
1516#include < apt-pkg/error.h>
1617#include < apt-pkg/fileutl.h>
1718#include < apt-pkg/indexfile.h>
@@ -376,6 +377,12 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator
376377 void const * oldMap = Map.Data ();
377378
378379 auto Hash = List.VersionHash ();
380+ APT::StringView ListSHA256;
381+
382+ bool const Debug = _config->FindB (" Debug::pkgCacheGen" , false );
383+ auto DebList = dynamic_cast <debListParser *>(&List);
384+ if (DebList != nullptr )
385+ ListSHA256 = DebList->SHA256 ();
379386 if (Ver.end () == false )
380387 {
381388 /* We know the list is sorted so we use that fact in the search.
@@ -392,8 +399,18 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator
392399 // Versionstrings are equal - is hash also equal?
393400 if (Res == 0 )
394401 {
395- if (List.SameVersion (Hash, Ver) == true )
396- break ;
402+ if (List.SameVersion (Hash, Ver))
403+ {
404+ // We do not have SHA256 for both, so we cannot compare them, trust the call from SameVersion()
405+ if (ListSHA256.empty () || VersionExtra[Ver->ID ].SHA256 [0 ] == 0 )
406+ break ;
407+ // We have SHA256 for both, so they must match.
408+ if (ListSHA256 == APT::StringView (VersionExtra[Ver->ID ].SHA256 , 64 ))
409+ break ;
410+ if (Debug)
411+ std::cerr << " Found differing SHA256 for " << Pkg.Name () << " =" << Version.to_string () << std::endl;
412+ }
413+
397414 // sort (volatile) sources above not-sources like the status file
398415 if (CurrentFile == nullptr || (CurrentFile->Flags & pkgCache::Flag::NotSource) == 0 )
399416 {
@@ -440,6 +457,8 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator
440457 if (oldMap != Map.Data ())
441458 LastVer = static_cast <map_pointer<pkgCache::Version> *>(Map.Data ()) + (LastVer - static_cast <map_pointer<pkgCache::Version> const *>(oldMap));
442459 *LastVer = verindex;
460+ if (ListSHA256.size () == 64 )
461+ memcpy (VersionExtra[Ver->ID ].SHA256 , ListSHA256.data (), 64 );
443462
444463 if (unlikely (List.NewVersion (Ver) == false ))
445464 return _error->Error (_ (" Error occurred while processing %s (%s%d)" ),
@@ -869,6 +888,10 @@ map_pointer<pkgCache::Version> pkgCacheGenerator::NewVersion(pkgCache::VerIterat
869888 Ver->Hash = Hash;
870889 Ver->ID = Cache.HeaderP ->VersionCount ++;
871890
891+ // Allocate size for extra store
892+ if (VersionExtra.size () <= Ver->ID )
893+ VersionExtra.resize (Ver->ID + 1 );
894+
872895 // try to find the version string in the group for reuse
873896 pkgCache::PkgIterator Pkg = Ver.ParentPkg ();
874897 pkgCache::GrpIterator Grp = Pkg.Group ();
0 commit comments