X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/10639577016904cccab77c311e7c0b4363997504..860ff9593b6d706136518693b2a82db6b769e17e:/apt-pkg/pkgcache.cc diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index ea5c264dc..93ad56641 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.33 2001/03/05 02:43:28 jgg Exp $ +// $Id: pkgcache.cc,v 1.37 2003/02/10 01:40:58 doogie Exp $ /* ###################################################################### Package Cache - Accessor code for the cache @@ -26,6 +26,7 @@ #endif #include +#include #include #include #include @@ -37,10 +38,13 @@ #include #include +#include #include - /*}}}*/ +using std::string; + + // Cache::Header::Header - Constructor /*{{{*/ // --------------------------------------------------------------------- /* Simply initialize the header */ @@ -50,25 +54,30 @@ pkgCache::Header::Header() /* Whenever the structures change the major version should be bumped, whenever the generator changes the minor version should be bumped. */ - MajorVersion = 3; - MinorVersion = 5; + MajorVersion = 6; + MinorVersion = 0; Dirty = false; HeaderSz = sizeof(pkgCache::Header); PackageSz = sizeof(pkgCache::Package); PackageFileSz = sizeof(pkgCache::PackageFile); VersionSz = sizeof(pkgCache::Version); + DescriptionSz = sizeof(pkgCache::Description); DependencySz = sizeof(pkgCache::Dependency); ProvidesSz = sizeof(pkgCache::Provides); VerFileSz = sizeof(pkgCache::VerFile); + DescFileSz = sizeof(pkgCache::DescFile); PackageCount = 0; VersionCount = 0; + DescriptionCount = 0; DependsCount = 0; PackageFileCount = 0; VerFileCount = 0; + DescFileCount = 0; ProvidesCount = 0; MaxVerFileSize = 0; + MaxDescFileSize = 0; FileList = 0; StringList = 0; @@ -87,8 +96,10 @@ bool pkgCache::Header::CheckSizes(Header &Against) const PackageSz == Against.PackageSz && PackageFileSz == Against.PackageFileSz && VersionSz == Against.VersionSz && + DescriptionSz == Against.DescriptionSz && DependencySz == Against.DependencySz && VerFileSz == Against.VerFileSz && + DescFileSz == Against.DescFileSz && ProvidesSz == Against.ProvidesSz) return true; return false; @@ -113,8 +124,10 @@ bool pkgCache::ReMap() HeaderP = (Header *)Map.Data(); PkgP = (Package *)Map.Data(); VerFileP = (VerFile *)Map.Data(); + DescFileP = (DescFile *)Map.Data(); PkgFileP = (PackageFile *)Map.Data(); VerP = (Version *)Map.Data(); + DescP = (Description *)Map.Data(); ProvideP = (Provides *)Map.Data(); DepP = (Dependency *)Map.Data(); StringItemP = (StringItem *)Map.Data(); @@ -137,12 +150,12 @@ bool pkgCache::ReMap() // Locate our VS.. if (HeaderP->VerSysName == 0 || (VS = pkgVersioningSystem::GetVS(StrP + HeaderP->VerSysName)) == 0) - return _error->Error(_("This APT does not support the Versioning System '%s'"),StrP + HeaderP->VerSysName); + return _error->Error(_("This APT does not support the versioning system '%s'"),StrP + HeaderP->VerSysName); // Chcek the arhcitecture if (HeaderP->Architecture == 0 || _config->Find("APT::Architecture") != StrP + HeaderP->Architecture) - return _error->Error(_("The package cache was build for a different architecture")); + return _error->Error(_("The package cache was built for a different architecture")); return true; } /*}}}*/ @@ -151,10 +164,10 @@ 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) const +unsigned long pkgCache::sHash(const string &Str) const { unsigned long Hash = 0; - for (const char *I = Str.begin(); I != Str.end(); I++) + for (string::const_iterator I = Str.begin(); I != Str.end(); I++) Hash = 5*Hash + tolower(*I); return Hash % _count(HeaderP->HashTable); } @@ -171,14 +184,14 @@ unsigned long pkgCache::sHash(const char *Str) const // Cache::FindPkg - Locate a package by name /*{{{*/ // --------------------------------------------------------------------- /* Returns 0 on error, pointer to the package otherwise */ -pkgCache::PkgIterator pkgCache::FindPkg(string Name) +pkgCache::PkgIterator pkgCache::FindPkg(const string &Name) { // Look at the hash bucket Package *Pkg = PkgP + HeaderP->HashTable[Hash(Name)]; for (; Pkg != PkgP; Pkg = PkgP + Pkg->NextPackage) { if (Pkg->Name != 0 && StrP[Pkg->Name] == Name[0] && - stringcasecmp(Name.begin(),Name.end(),StrP + Pkg->Name) == 0) + stringcasecmp(Name,StrP + Pkg->Name) == 0) return PkgIterator(*this,Pkg); } return PkgIterator(*this,0); @@ -215,8 +228,8 @@ const char *pkgCache::DepType(unsigned char Type) { const char *Types[] = {"",_("Depends"),_("PreDepends"),_("Suggests"), _("Recommends"),_("Conflicts"),_("Replaces"), - _("Obsoletes")}; - if (Type < 8) + _("Obsoletes"),_("Breaks")}; + if (Type < sizeof(Types)/sizeof(*Types)) return Types[Type]; return ""; } @@ -233,11 +246,11 @@ const char *pkgCache::Priority(unsigned char Prio) return 0; } /*}}}*/ - // Bases for iterator classes /*{{{*/ void pkgCache::VerIterator::_dummy() {} void pkgCache::DepIterator::_dummy() {} void pkgCache::PrvIterator::_dummy() {} +void pkgCache::DescIterator::_dummy() {} /*}}}*/ // PkgIterator::operator ++ - Postfix incr /*{{{*/ // --------------------------------------------------------------------- @@ -279,10 +292,11 @@ pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const // DepIterator::IsCritical - Returns true if the dep is important /*{{{*/ // --------------------------------------------------------------------- /* Currently critical deps are defined as depends, predepends and - conflicts. */ + conflicts (including dpkg's Breaks fields). */ bool pkgCache::DepIterator::IsCritical() { if (Dep->Type == pkgCache::Dep::Conflicts || + Dep->Type == pkgCache::Dep::DpkgBreaks || Dep->Type == pkgCache::Dep::Obsoletes || Dep->Type == pkgCache::Dep::Depends || Dep->Type == pkgCache::Dep::PreDepends) @@ -368,6 +382,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() continue; if ((Dep->Type == pkgCache::Dep::Conflicts || + Dep->Type == pkgCache::Dep::DpkgBreaks || Dep->Type == pkgCache::Dep::Obsoletes) && ParentPkg() == I.ParentPkg()) continue; @@ -384,6 +399,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() continue; if ((Dep->Type == pkgCache::Dep::Conflicts || + Dep->Type == pkgCache::Dep::DpkgBreaks || Dep->Type == pkgCache::Dep::Obsoletes) && ParentPkg() == I.OwnerPkg()) continue; @@ -578,3 +594,39 @@ bool pkgCache::PkgFileIterator::IsOk() return true; } /*}}}*/ +// PkgFileIterator::RelStr - Return the release string /*{{{*/ +// --------------------------------------------------------------------- +/* */ +string pkgCache::PkgFileIterator::RelStr() +{ + string Res; + if (Version() != 0) + Res = Res + (Res.empty() == true?"v=":",v=") + Version(); + if (Origin() != 0) + Res = Res + (Res.empty() == true?"o=":",o=") + Origin(); + if (Archive() != 0) + Res = Res + (Res.empty() == true?"a=":",a=") + Archive(); + if (Label() != 0) + Res = Res + (Res.empty() == true?"l=":",l=") + Label(); + if (Component() != 0) + Res = Res + (Res.empty() == true?"c=":",c=") + Component(); + return Res; +} + /*}}}*/ +// VerIterator::TranslatedDescription - Return the a DescIter for locale/*{{{*/ +// --------------------------------------------------------------------- +/* return a DescIter for the current locale or the default if none is + * found + */ +pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescription() const +{ + pkgCache::DescIterator DescDefault = DescriptionList(); + pkgCache::DescIterator Desc = DescDefault; + for (; Desc.end() == false; Desc++) + if (pkgIndexFile::LanguageCode() == Desc.LanguageCode()) + break; + if (Desc.end() == true) Desc = DescDefault; + return Desc; +}; + + /*}}}*/