X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/f55a958ff2251f0061ab907157c99a350e56025f..fc4b5c9f963c8292d0908a9dd30e47bbb00a6396:/apt-pkg/pkgcache.cc diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index fa0c363f7..040c672c8 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -1,11 +1,11 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: pkgcache.cc,v 1.2 1998/07/04 05:57:35 jgg Exp $ +// $Id: pkgcache.cc,v 1.26 1999/06/04 05:54:20 jgg Exp $ /* ###################################################################### Package Cache - Accessor code for the cache - Please see doc/pkglib/cache.sgml for a more detailed description of + Please see doc/apt-pkg/cache.sgml for a more detailed description of this format. Also be sure to keep that file up-to-date!! This is the general utility functions for cache managment. They provide @@ -20,9 +20,13 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#include -#include -#include +#ifdef __GNUG__ +#pragma implementation "apt-pkg/pkgcache.h" +#pragma implementation "apt-pkg/cacheiterators.h" +#endif +#include +#include +#include #include #include @@ -39,8 +43,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 = 0; + MajorVersion = 3; + MinorVersion = 2; Dirty = true; HeaderSz = sizeof(pkgCache::Header); @@ -49,11 +53,15 @@ pkgCache::Header::Header() VersionSz = sizeof(pkgCache::Version); DependencySz = sizeof(pkgCache::Dependency); ProvidesSz = sizeof(pkgCache::Provides); - + VerFileSz = sizeof(pkgCache::VerFile); + PackageCount = 0; VersionCount = 0; DependsCount = 0; PackageFileCount = 0; + VerFileCount = 0; + ProvidesCount = 0; + MaxVerFileSize = 0; FileList = 0; StringList = 0; @@ -70,7 +78,8 @@ bool pkgCache::Header::CheckSizes(Header &Against) const PackageSz == Against.PackageSz && PackageFileSz == Against.PackageFileSz && VersionSz == Against.VersionSz && - DependencySz == Against.DependencySz && + DependencySz == Against.DependencySz && + VerFileSz == Against.VerFileSz && ProvidesSz == Against.ProvidesSz) return true; return false; @@ -93,6 +102,7 @@ bool pkgCache::ReMap() // Apply the typecasts. HeaderP = (Header *)Map.Data(); PkgP = (Package *)Map.Data(); + VerFileP = (VerFile *)Map.Data(); PkgFileP = (PackageFile *)Map.Data(); VerP = (Version *)Map.Data(); ProvideP = (Provides *)Map.Data(); @@ -100,7 +110,6 @@ bool pkgCache::ReMap() StringItemP = (StringItem *)Map.Data(); StrP = (char *)Map.Data(); - cout << "Size is " << Map.Size() << endl; if (Map.Size() == 0) return false; @@ -123,23 +132,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 + *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 + *I; + return Hash % _count(HeaderP->HashTable); } /*}}}*/ @@ -152,12 +158,62 @@ pkgCache::PkgIterator pkgCache::FindPkg(string Name) Package *Pkg = PkgP + HeaderP->HashTable[Hash(Name)]; for (; Pkg != PkgP; Pkg = PkgP + Pkg->NextPackage) { - if (Pkg->Name != 0 && StrP + Pkg->Name == Name) + if (Pkg->Name != 0 && StrP[Pkg->Name] == Name[0] && + StrP + Pkg->Name == Name) return PkgIterator(*this,Pkg); +// cout << "b" << flush; } return PkgIterator(*this,0); } /*}}}*/ +// Cache::Priority - Convert a priority value to a string /*{{{*/ +// --------------------------------------------------------------------- +/* */ +const char *pkgCache::Priority(unsigned char Prio) +{ + const char *Mapping[] = {0,"important","required","standard","optional","extra"}; + if (Prio < _count(Mapping)) + return Mapping[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() {} @@ -185,14 +241,18 @@ void pkgCache::PkgIterator::operator ++(int) // --------------------------------------------------------------------- /* By this we mean if it is either cleanly installed or cleanly removed. */ pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const -{ - if (Pkg->CurrentState == UnPacked || - Pkg->CurrentState == HalfConfigured) +{ + if (Pkg->InstState == pkgCache::State::ReInstReq || + Pkg->InstState == pkgCache::State::HoldReInstReq) + return NeedsUnpack; + + if (Pkg->CurrentState == pkgCache::State::UnPacked || + Pkg->CurrentState == pkgCache::State::HalfConfigured) return NeedsConfigure; - if (Pkg->CurrentState == UnInstalled || - Pkg->CurrentState == HalfInstalled || - Pkg->InstState != Ok) + if (Pkg->CurrentState == pkgCache::State::UnInstalled || + Pkg->CurrentState == pkgCache::State::HalfInstalled || + Pkg->InstState != pkgCache::State::Ok) return NeedsUnpack; return NeedsNothing; @@ -204,8 +264,9 @@ pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const conflicts. */ bool pkgCache::DepIterator::IsCritical() { - if (Dep->Type == Conflicts || Dep->Type == Depends || - Dep->Type == PreDepends) + if (Dep->Type == pkgCache::Dep::Conflicts || + Dep->Type == pkgCache::Dep::Depends || + Dep->Type == pkgCache::Dep::PreDepends) return true; return false; } @@ -264,7 +325,8 @@ bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator &Result) // --------------------------------------------------------------------- /* This is a more usefull version of TargetPkg() that follows versioned provides. It includes every possible package-version that could satisfy - the dependency. The last item in the list has a 0. */ + the dependency. The last item in the list has a 0. The resulting pointer + must be delete [] 'd */ pkgCache::Version **pkgCache::DepIterator::AllTargets() { Version **Res = 0; @@ -280,7 +342,8 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() if (pkgCheckDep(TargetVer(),I.VerStr(),Dep->CompareOp) == false) continue; - if (Dep->Type == Conflicts && ParentPkg() == I.ParentPkg()) + if (Dep->Type == pkgCache::Dep::Conflicts && + ParentPkg() == I.ParentPkg()) continue; Size++; @@ -294,7 +357,8 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() if (pkgCheckDep(TargetVer(),I.ProvideVersion(),Dep->CompareOp) == false) continue; - if (Dep->Type == Conflicts && ParentPkg() == I.OwnerPkg()) + if (Dep->Type == pkgCache::Dep::Conflicts && + ParentPkg() == I.OwnerPkg()) continue; Size++; @@ -318,6 +382,50 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() return Res; } /*}}}*/ +// DepIterator::CompType - Return a string describing the compare type /*{{{*/ +// --------------------------------------------------------------------- +/* This returns a string representation of the dependency compare + type */ +const char *pkgCache::DepIterator::CompType() +{ + const char *Ops[] = {"","<=",">=","<",">","=","!="}; + if ((unsigned)(Dep->CompareOp & 0xF) < 7) + return Ops[Dep->CompareOp & 0xF]; + return ""; +} + /*}}}*/ +// DepIterator::DepType - Return a string describing the dep type /*{{{*/ +// --------------------------------------------------------------------- +/* */ +const char *pkgCache::DepIterator::DepType() +{ + const char *Types[] = {"","Depends","PreDepends","Suggests", + "Recommends","Conflicts","Replaces"}; + if (Dep->Type < 7) + return Types[Dep->Type]; + return ""; +} + /*}}}*/ +// DepIterator::GlobOr - Compute an OR group /*{{{*/ +// --------------------------------------------------------------------- +/* This Takes an iterator, iterates past the current dependency grouping + and returns Start and End so that so End is the final element + in the group, if End == Start then D is End++ and End is the + dependency D was pointing to. Use in loops to iterate sensibly. */ +void pkgCache::DepIterator::GlobOr(DepIterator &Start,DepIterator &End) +{ + // Compute a single dependency element (glob or) + Start = *this; + End = *this; + for (bool LastOR = true; end() == false && LastOR == true;) + { + LastOR = (Dep->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; + (*this)++; + if (LastOR == true) + End = (*this); + } +} + /*}}}*/ // VerIterator::CompareVer - Fast version compare for same pkgs /*{{{*/ // --------------------------------------------------------------------- /* This just looks over the version list to see if B is listed before A. In @@ -341,6 +449,60 @@ int pkgCache::VerIterator::CompareVer(const VerIterator &B) const return -1; } /*}}}*/ +// VerIterator::Downloadable - Checks if the version is downloadable /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgCache::VerIterator::Downloadable() const +{ + VerFileIterator Files = FileList(); + for (; Files.end() == false; Files++) + if ((Files.File()->Flags & pkgCache::Flag::NotSource) != pkgCache::Flag::NotSource) + return true; + return false; +} + /*}}}*/ +// VerIterator::PriorityType - Return a string describing the priority /*{{{*/ +// --------------------------------------------------------------------- +/* */ +const char *pkgCache::VerIterator::PriorityType() +{ + const char *Types[] = {"","Important","Required","Standard", + "Optional","Extra"}; + if (Ver->Priority < 6) + return Types[Ver->Priority]; + 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