X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/a7e66b170369fe1e1e7fdd2c3abd8c85e9b15bf9..1ae93c94429de697fb17f7067367fbf32fd3b6fc:/apt-pkg/pkgcache.cc diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index ac1de021a..37a9c3aab 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: pkgcache.cc,v 1.21 1998/12/14 03:39:15 jgg Exp $ +// $Id: pkgcache.cc,v 1.31 1999/12/10 23:40:29 jgg Exp $ /* ###################################################################### Package Cache - Accessor code for the cache @@ -27,11 +27,14 @@ #include #include #include -#include +#include #include #include #include + +#include + /*}}}*/ // Cache::Header::Header - Constructor /*{{{*/ @@ -43,8 +46,8 @@ pkgCache::Header::Header() /* Whenever the structures change the major version should be bumped, whenever the generator changes the minor version should be bumped. */ - MajorVersion = 2; - MinorVersion = 2; + MajorVersion = 3; + MinorVersion = 5; Dirty = true; HeaderSz = sizeof(pkgCache::Header); @@ -132,23 +135,20 @@ bool pkgCache::ReMap() /* This is used to generate the hash entries for the HashTable. With my package list from bo this function gets 94% table usage on a 512 item table (480 used items) */ -unsigned long pkgCache::sHash(string Str) +unsigned long pkgCache::sHash(string Str) const { unsigned long Hash = 0; for (const char *I = Str.begin(); I != Str.end(); I++) - Hash += *I * ((Str.end() - I + 1)); - Header H; - return Hash % _count(H.HashTable); + Hash = 5*Hash + tolower(*I); + return Hash % _count(HeaderP->HashTable); } -unsigned long pkgCache::sHash(const char *Str) +unsigned long pkgCache::sHash(const char *Str) const { unsigned long Hash = 0; - const char *End = Str + strlen(Str); - for (const char *I = Str; I != End; I++) - Hash += *I * ((End - I + 1)); - Header H; - return Hash % _count(H.HashTable); + for (const char *I = Str; *I != 0; I++) + Hash = 5*Hash + tolower(*I); + return Hash % _count(HeaderP->HashTable); } /*}}}*/ @@ -162,7 +162,7 @@ pkgCache::PkgIterator pkgCache::FindPkg(string Name) for (; Pkg != PkgP; Pkg = PkgP + Pkg->NextPackage) { if (Pkg->Name != 0 && StrP[Pkg->Name] == Name[0] && - StrP + Pkg->Name == Name) + stringcasecmp(Name.begin(),Name.end(),StrP + Pkg->Name) == 0) return PkgIterator(*this,Pkg); } return PkgIterator(*this,0); @@ -179,6 +179,43 @@ const char *pkgCache::Priority(unsigned char Prio) return 0; } /*}}}*/ +// Cache::GetCandidateVer - Returns the Candidate install version /*{{{*/ +// --------------------------------------------------------------------- +/* The default just returns the highest available version that is not + a source and automatic */ +pkgCache::VerIterator pkgCache::GetCandidateVer(PkgIterator Pkg, + bool AllowCurrent) +{ + /* Not source/not automatic versions cannot be a candidate version + unless they are already installed */ + VerIterator Last(*this,0); + + for (VerIterator I = Pkg.VersionList(); I.end() == false; I++) + { + if (Pkg.CurrentVer() == I && AllowCurrent == true) + return I; + + for (VerFileIterator J = I.FileList(); J.end() == false; J++) + { + if ((J.File()->Flags & Flag::NotSource) != 0) + continue; + + /* Stash the highest version of a not-automatic source, we use it + if there is nothing better */ + if ((J.File()->Flags & Flag::NotAutomatic) != 0) + { + if (Last.end() == true) + Last = I; + continue; + } + + return I; + } + } + + return Last; +} + /*}}}*/ // Bases for iterator classes /*{{{*/ void pkgCache::VerIterator::_dummy() {} @@ -215,8 +252,7 @@ pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const Pkg->CurrentState == pkgCache::State::HalfConfigured) return NeedsConfigure; - if (Pkg->CurrentState == pkgCache::State::UnInstalled || - Pkg->CurrentState == pkgCache::State::HalfInstalled || + if (Pkg->CurrentState == pkgCache::State::HalfInstalled || Pkg->InstState != pkgCache::State::Ok) return NeedsUnpack; @@ -438,6 +474,36 @@ const char *pkgCache::VerIterator::PriorityType() return ""; } /*}}}*/ +// VerIterator::Automatic - Check if this version is 'automatic' /*{{{*/ +// --------------------------------------------------------------------- +/* This checks to see if any of the versions files are not NotAutomatic. + True if this version is selectable for automatic installation. */ +bool pkgCache::VerIterator::Automatic() const +{ + VerFileIterator Files = FileList(); + for (; Files.end() == false; Files++) + if ((Files.File()->Flags & pkgCache::Flag::NotAutomatic) != pkgCache::Flag::NotAutomatic) + return true; + return false; +} + /*}}}*/ +// VerIterator::NewestFile - Return the newest file version relation /*{{{*/ +// --------------------------------------------------------------------- +/* This looks at the version numbers associated with all of the sources + this version is in and returns the highest.*/ +pkgCache::VerFileIterator pkgCache::VerIterator::NewestFile() const +{ + VerFileIterator Files = FileList(); + VerFileIterator Highest = Files; + for (; Files.end() == false; Files++) + { + if (pkgVersionCompare(Files.File().Version(),Highest.File().Version()) > 0) + Highest = Files; + } + + return Highest; +} + /*}}}*/ // PkgFileIterator::IsOk - Checks if the cache is in sync with the file /*{{{*/ // --------------------------------------------------------------------- /* This stats the file and compares its stats with the ones that were