From af87ab54430b31a0e1840b2c1673c07d74813447 Mon Sep 17 00:00:00 2001 From: Arch Librarian Date: Mon, 20 Sep 2004 16:57:45 +0000 Subject: [PATCH] 'apt-cache policy' preferences debug tool. Author: jgg Date: 2001-04-29 05:13:51 GMT 'apt-cache policy' preferences debug tool. --- apt-pkg/cacheiterators.h | 5 +- apt-pkg/deb/debindexfile.cc | 21 ++++-- apt-pkg/deb/debindexfile.h | 8 +-- apt-pkg/deb/debsystem.cc | 31 ++++++++- apt-pkg/deb/debsystem.h | 8 ++- apt-pkg/indexfile.h | 4 +- apt-pkg/pkgcache.cc | 21 +++++- apt-pkg/pkgsystem.h | 4 +- apt-pkg/policy.cc | 50 +++++++++----- apt-pkg/policy.h | 10 ++- apt-pkg/versionmatch.cc | 8 +-- cmdline/apt-cache.cc | 129 ++++++++++++++++++++++++++++++++++-- debian/changelog | 1 + doc/apt-cache.8.sgml | 8 +++ 14 files changed, 261 insertions(+), 47 deletions(-) diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index e346f49b7..cb8e0cd94 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: cacheiterators.h,v 1.16 2001/02/20 07:03:17 jgg Exp $ +// $Id: cacheiterators.h,v 1.17 2001/04/29 05:13:51 jgg Exp $ /* ###################################################################### Cache Iterators - Iterators for navigating the cache structure @@ -297,7 +297,8 @@ class pkgCache::PkgFileIterator inline unsigned long Index() const {return File - Owner->PkgFileP;}; bool IsOk(); - + string RelStr(); + // Constructors inline PkgFileIterator() : Owner(0), File(0) {}; inline PkgFileIterator(pkgCache &Owner) : Owner(&Owner), File(Owner.PkgFileP) {}; diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 2cc1de8a1..38316d17e 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: debindexfile.cc,v 1.4 2001/03/13 06:51:46 jgg Exp $ +// $Id: debindexfile.cc,v 1.5 2001/04/29 05:13:51 jgg Exp $ /* ###################################################################### Debian Specific sources.list types and the three sorts of Debian @@ -74,11 +74,15 @@ pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const // SourcesIndex::Describe - Give a descriptive path to the index /*{{{*/ // --------------------------------------------------------------------- /* */ -string debSourcesIndex::Describe() const +string debSourcesIndex::Describe(bool Short) const { char S[300]; - snprintf(S,sizeof(S),"%s (%s)",Info("Packages").c_str(), - IndexFile("Sources").c_str()); + if (Short == true) + snprintf(S,sizeof(S),"%s",Info("Packages").c_str()); + else + snprintf(S,sizeof(S),"%s (%s)",Info("Packages").c_str(), + IndexFile("Sources").c_str()); + return S; } /*}}}*/ @@ -188,11 +192,14 @@ string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const // --------------------------------------------------------------------- /* This should help the user find the index in the sources.list and in the filesystem for problem solving */ -string debPackagesIndex::Describe() const +string debPackagesIndex::Describe(bool Short) const { char S[300]; - snprintf(S,sizeof(S),"%s (%s)",Info("Packages").c_str(), - IndexFile("Packages").c_str()); + if (Short == true) + snprintf(S,sizeof(S),"%s",Info("Packages").c_str()); + else + snprintf(S,sizeof(S),"%s (%s)",Info("Packages").c_str(), + IndexFile("Packages").c_str()); return S; } /*}}}*/ diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index b4dee3c22..9bce4da83 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: debindexfile.h,v 1.2 2001/02/20 07:03:17 jgg Exp $ +// $Id: debindexfile.h,v 1.3 2001/04/29 05:13:51 jgg Exp $ /* ###################################################################### Debian Index Files @@ -31,7 +31,7 @@ class debStatusIndex : public pkgIndexFile virtual const Type *GetType() const; // Interface for acquire - virtual string Describe() const {return File;}; + virtual string Describe(bool Short) const {return File;}; // Interface for the Cache Generator virtual bool Exists() const; @@ -62,7 +62,7 @@ class debPackagesIndex : public pkgIndexFile virtual string ArchiveURI(string File) const {return URI + File;}; // Interface for acquire - virtual string Describe() const; + virtual string Describe(bool Short) const; virtual bool GetIndexes(pkgAcquire *Owner) const; // Interface for the Cache Generator @@ -95,7 +95,7 @@ class debSourcesIndex : public pkgIndexFile virtual string ArchiveURI(string File) const {return URI + File;}; // Interface for acquire - virtual string Describe() const; + virtual string Describe(bool Short) const; virtual bool GetIndexes(pkgAcquire *Owner) const; // Interface for the record parsers diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc index 0abd4c8aa..5a4cbe654 100644 --- a/apt-pkg/deb/debsystem.cc +++ b/apt-pkg/deb/debsystem.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: debsystem.cc,v 1.2 2001/02/20 07:03:17 jgg Exp $ +// $Id: debsystem.cc,v 1.3 2001/04/29 05:13:51 jgg Exp $ /* ###################################################################### System - Abstraction for running on different systems. @@ -42,6 +42,14 @@ debSystem::debSystem() VS = &debVS; } /*}}}*/ +// System::~debSystem - Destructor /*{{{*/ +// --------------------------------------------------------------------- +/* */ +debSystem::~debSystem() +{ + delete StatusFile; +} + /*}}}*/ // System::Lock - Get the lock /*{{{*/ // --------------------------------------------------------------------- /* This mirrors the operations dpkg does when it starts up. Note the @@ -191,7 +199,26 @@ signed debSystem::Score(Configuration const &Cnf) /* */ bool debSystem::AddStatusFiles(vector &List) { - List.push_back(new debStatusIndex(_config->FindFile("Dir::State::status"))); + if (StatusFile == 0) + StatusFile = new debStatusIndex(_config->FindFile("Dir::State::status")); + List.push_back(StatusFile); return true; } /*}}}*/ +// System::FindIndex - Get an index file for status files /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool debSystem::FindIndex(pkgCache::PkgFileIterator File, + pkgIndexFile *&Found) const +{ + if (StatusFile == 0) + return false; + if (StatusFile->FindInCache(*File.Cache()) == File) + { + Found = StatusFile; + return true; + } + + return false; +} + /*}}}*/ diff --git a/apt-pkg/deb/debsystem.h b/apt-pkg/deb/debsystem.h index 4fd267f77..c4e27ced3 100644 --- a/apt-pkg/deb/debsystem.h +++ b/apt-pkg/deb/debsystem.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: debsystem.h,v 1.2 2001/02/20 07:03:17 jgg Exp $ +// $Id: debsystem.h,v 1.3 2001/04/29 05:13:51 jgg Exp $ /* ###################################################################### System - Debian version of the System Class @@ -16,6 +16,7 @@ #include +class debStatusIndex; class debSystem : public pkgSystem { // For locking support @@ -23,6 +24,8 @@ class debSystem : public pkgSystem unsigned LockCount; bool CheckUpdates(); + debStatusIndex *StatusFile; + public: virtual bool Lock(); @@ -32,8 +35,11 @@ class debSystem : public pkgSystem virtual bool ArchiveSupported(const char *Type); virtual signed Score(Configuration const &Cnf); virtual bool AddStatusFiles(vector &List); + virtual bool FindIndex(pkgCache::PkgFileIterator File, + pkgIndexFile *&Found) const; debSystem(); + ~debSystem(); }; extern debSystem debSys; diff --git a/apt-pkg/indexfile.h b/apt-pkg/indexfile.h index 06e5a7f35..beae1e7d8 100644 --- a/apt-pkg/indexfile.h +++ b/apt-pkg/indexfile.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: indexfile.h,v 1.3 2001/03/11 07:35:49 jgg Exp $ +// $Id: indexfile.h,v 1.4 2001/04/29 05:13:51 jgg Exp $ /* ###################################################################### Index File - Abstraction for an index of archive/source file. @@ -58,7 +58,7 @@ class pkgIndexFile virtual string ArchiveInfo(pkgCache::VerIterator Ver) const; virtual string SourceInfo(pkgSrcRecords::Parser const &Record, pkgSrcRecords::File const &File) const; - virtual string Describe() const = 0; + virtual string Describe(bool Short = false) const = 0; // Interface for acquire virtual string ArchiveURI(string /*File*/) const {return string();}; diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index ea5c264dc..fa231ef37 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.34 2001/04/29 05:13:51 jgg Exp $ /* ###################################################################### Package Cache - Accessor code for the cache @@ -578,3 +578,22 @@ 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; +} + /*}}}*/ diff --git a/apt-pkg/pkgsystem.h b/apt-pkg/pkgsystem.h index 0f0a11808..c6b34fd61 100644 --- a/apt-pkg/pkgsystem.h +++ b/apt-pkg/pkgsystem.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: pkgsystem.h,v 1.3 2001/03/11 07:35:49 jgg Exp $ +// $Id: pkgsystem.h,v 1.4 2001/04/29 05:13:51 jgg Exp $ /* ###################################################################### System - Abstraction for running on different systems. @@ -80,6 +80,8 @@ class pkgSystem // Return a list of system index files.. virtual bool AddStatusFiles(vector &List) = 0; + virtual bool FindIndex(pkgCache::PkgFileIterator File, + pkgIndexFile *&Found) const = 0; /* Evauluate how 'right' we are for this system based on the filesystem etc.. */ diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc index da72f193a..cde0920e6 100644 --- a/apt-pkg/policy.cc +++ b/apt-pkg/policy.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: policy.cc,v 1.5 2001/03/13 05:23:42 jgg Exp $ +// $Id: policy.cc,v 1.6 2001/04/29 05:13:51 jgg Exp $ /* ###################################################################### Package Version Policy implementation @@ -83,10 +83,6 @@ bool pkgPolicy::InitDefaults() pkgVersionMatch Match(I->Data,I->Type); for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); F++) { -/* hmm? - if ((F->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource) - continue;*/ - if (Match.FileMatch(F) == true && Fixed[F->ID] == false) { if (I->Priority != 0 && I->Priority > 0) @@ -118,19 +114,9 @@ bool pkgPolicy::InitDefaults() best package is. */ pkgCache::VerIterator pkgPolicy::GetCandidateVer(pkgCache::PkgIterator Pkg) { - const Pin &PPkg = Pins[Pkg->ID]; - // Look for a package pin and evaluate it. - signed Max = 0; - pkgCache::VerIterator Pref(*Cache); - if (PPkg.Type != pkgVersionMatch::None) - { - pkgVersionMatch Match(PPkg.Data,PPkg.Type); - Pref = Match.Find(Pkg); - Max = PPkg.Priority; - if (PPkg.Priority == 0) - Max = 989; - } + signed Max = GetPriority(Pkg); + pkgCache::VerIterator Pref = GetMatch(Pkg); /* Falling through to the default version.. Setting Max to zero effectively excludes everything <= 0 which are the non-automatic @@ -222,6 +208,36 @@ void pkgPolicy::CreatePin(pkgVersionMatch::MatchType Type,string Name, P->Data = Data; } /*}}}*/ +// Policy::GetMatch - Get the matching version for a package pin /*{{{*/ +// --------------------------------------------------------------------- +/* */ +pkgCache::VerIterator pkgPolicy::GetMatch(pkgCache::PkgIterator Pkg) +{ + const Pin &PPkg = Pins[Pkg->ID]; + if (PPkg.Type != pkgVersionMatch::None) + { + pkgVersionMatch Match(PPkg.Data,PPkg.Type); + return Match.Find(Pkg); + } + return pkgCache::VerIterator(*Pkg.Cache()); +} + /*}}}*/ +// Policy::GetPriority - Get the priority of the package pin /*{{{*/ +// --------------------------------------------------------------------- +/* */ +signed short pkgPolicy::GetPriority(pkgCache::PkgIterator const &Pkg) +{ + if (Pins[Pkg->ID].Type != pkgVersionMatch::None) + { + // In this case 0 means default priority + if (Pins[Pkg->ID].Priority == 0) + return 989; + return Pins[Pkg->ID].Priority; + } + + return 0; +} + /*}}}*/ // ReadPinFile - Load the pin file into a Policy /*{{{*/ // --------------------------------------------------------------------- diff --git a/apt-pkg/policy.h b/apt-pkg/policy.h index f89916202..149782b25 100644 --- a/apt-pkg/policy.h +++ b/apt-pkg/policy.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: policy.h,v 1.2 2001/02/20 07:03:17 jgg Exp $ +// $Id: policy.h,v 1.3 2001/04/29 05:13:51 jgg Exp $ /* ###################################################################### Package Version Policy implementation @@ -67,9 +67,15 @@ class pkgPolicy : public pkgDepCache::Policy public: + // Things for manipulating pins void CreatePin(pkgVersionMatch::MatchType Type,string Pkg, string Data,signed short Priority); - + inline signed short GetPriority(pkgCache::PkgFileIterator const &File) + {return PFPriority[File->ID];}; + signed short GetPriority(pkgCache::PkgIterator const &Pkg); + pkgCache::VerIterator GetMatch(pkgCache::PkgIterator Pkg); + + // Things for the cache interface. virtual pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator Pkg); virtual bool IsImportantDep(pkgCache::DepIterator Dep) {return pkgDepCache::Policy::IsImportantDep(Dep);}; bool InitDefaults(); diff --git a/apt-pkg/versionmatch.cc b/apt-pkg/versionmatch.cc index 45cdb117e..194df9ebc 100644 --- a/apt-pkg/versionmatch.cc +++ b/apt-pkg/versionmatch.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: versionmatch.cc,v 1.2 2001/02/20 07:03:17 jgg Exp $ +// $Id: versionmatch.cc,v 1.3 2001/04/29 05:13:51 jgg Exp $ /* ###################################################################### Version Matching @@ -164,8 +164,8 @@ bool pkgVersionMatch::FileMatch(pkgCache::PkgFileIterator File) if (Type == Release) { /* cout << RelVerStr << ',' << RelOrigin << ',' << RelArchive << ',' << RelLabel << endl; - cout << File.Version() << ',' << File.Origin() << ',' << File.Archive() << ',' << File.Label() << endl; -*/ + cout << File.Version() << ',' << File.Origin() << ',' << File.Archive() << ',' << File.Label() << endl;*/ + if (RelVerStr.empty() == true && RelOrigin.empty() == true && RelArchive.empty() == true && RelLabel.empty() == true && RelComponent.empty() == true) @@ -191,7 +191,7 @@ bool pkgVersionMatch::FileMatch(pkgCache::PkgFileIterator File) return false; if (RelComponent.empty() == false) if (File->Component == 0 || - stringcasecmp(RelLabel,File.Component()) != 0) + stringcasecmp(RelComponent,File.Component()) != 0) return false; return true; } diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 6dfd9ee87..803691cab 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: apt-cache.cc,v 1.46 2001/03/07 04:25:35 jgg Exp $ +// $Id: apt-cache.cc,v 1.47 2001/04/29 05:13:51 jgg Exp $ /* ###################################################################### apt-cache - Manages the cache files @@ -39,6 +39,7 @@ /*}}}*/ pkgCache *GCache = 0; +pkgSourceList *SrcList = 0; // LocalitySort - Sort a version list by package file locality /*{{{*/ // --------------------------------------------------------------------- @@ -1093,6 +1094,125 @@ bool ShowSrcPackage(CommandLine &CmdL) while ((Parse = SrcRecs.Find(*I,false)) != 0) cout << Parse->AsStr() << endl;; } + return true; +} + /*}}}*/ +// Policy - Show the results of the preferences file /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool Policy(CommandLine &CmdL) +{ + if (SrcList == 0) + return _error->Error("Generate must be enabled for this function"); + + pkgCache &Cache = *GCache; + pkgPolicy Plcy(&Cache); + if (ReadPinFile(Plcy) == false) + return false; + + // Print out all of the package files + if (CmdL.FileList[1] == 0) + { + cout << _("Package Files:") << endl; + for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++) + { + // Locate the associated index files so we can derive a description + pkgIndexFile *Indx; + if (SrcList->FindIndex(F,Indx) == false && + _system->FindIndex(F,Indx) == false) + return _error->Error(_("Cache is out of sync, can't x-ref a package file")); + printf(_("%4i %s\n"), + Plcy.GetPriority(F),Indx->Describe(true).c_str()); + + // Print the reference information for the package + string Str = F.RelStr(); + if (Str.empty() == false) + printf(" release %s\n",F.RelStr().c_str()); + if (F.Site() != 0 && F.Site()[0] != 0) + printf(" origin %s\n",F.Site()); + } + + // Show any packages have explicit pins + cout << _("Pinned Packages:") << endl; + pkgCache::PkgIterator I = Cache.PkgBegin(); + for (;I.end() != true; I++) + { + if (Plcy.GetPriority(I) == 0) + continue; + + // Print the package name and the version we are forcing to + cout << " " << I.Name() << " -> "; + + pkgCache::VerIterator V = Plcy.GetMatch(I); + if (V.end() == true) + cout << _("(not found)") << endl; + else + cout << V.VerStr() << endl; + } + + return true; + } + + // Print out detailed information for each package + for (const char **I = CmdL.FileList + 1; *I != 0; I++) + { + pkgCache::PkgIterator Pkg = Cache.FindPkg(*I); + if (Pkg.end() == true) + { + _error->Warning(_("Unable to locate package %s"),*I); + continue; + } + + cout << Pkg.Name() << ":" << endl; + + // Installed version + cout << _(" Installed: "); + if (Pkg->CurrentVer == 0) + cout << _("(none)") << endl; + else + cout << Pkg.CurrentVer().VerStr() << endl; + + // Candidate Version + cout << _(" Candidate: "); + pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg); + if (V.end() == true) + cout << _("(none)") << endl; + else + cout << V.VerStr() << endl; + + // Pinned version + if (Plcy.GetPriority(Pkg) != 0) + { + cout << _(" Package Pin: "); + V = Plcy.GetMatch(Pkg); + if (V.end() == true) + cout << _("(not found)") << endl; + else + cout << V.VerStr() << endl; + } + + // Show the priority tables + cout << _(" Version Table:") << endl; + for (V = Pkg.VersionList(); V.end() == false; V++) + { + if (Pkg.CurrentVer() == V) + cout << " *** " << V.VerStr(); + else + cout << " " << V.VerStr(); + cout << " " << Plcy.GetPriority(Pkg) << endl; + for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++) + { + // Locate the associated index files so we can derive a description + pkgIndexFile *Indx; + if (SrcList->FindIndex(VF.File(),Indx) == false && + _system->FindIndex(VF.File(),Indx) == false) + return _error->Error(_("Cache is out of sync, can't x-ref a package file")); + printf(_(" %4i %s\n"),Plcy.GetPriority(VF.File()), + Indx->Describe(true).c_str()); + } + } + } + return true; } /*}}}*/ @@ -1194,6 +1314,7 @@ int main(int argc,const char *argv[]) {"dotty",&Dotty}, {"show",&ShowPackage}, {"pkgnames",&ShowPkgNames}, + {"policy",&Policy}, {0,0}}; CacheInitialize(); @@ -1231,12 +1352,12 @@ int main(int argc,const char *argv[]) else { // Open the cache file - pkgSourceList List; - List.ReadMainList(); + SrcList = new pkgSourceList; + SrcList->ReadMainList(); // Generate it and map it OpProgress Prog; - pkgMakeStatusCache(List,Prog,&Map,true); + pkgMakeStatusCache(*SrcList,Prog,&Map,true); } if (_error->PendingError() == false) diff --git a/debian/changelog b/debian/changelog index 8da6d2025..e52558bde 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,6 +18,7 @@ apt (0.5.4) unstable; urgency=low * French man pages from philippe batailler - well sort of. They don't build yet.. * run-parts. Closes: #94286 + * 'apt-cache policy' preferences debug tool. -- Jason Gunthorpe Thu, 8 Mar 2001 22:48:06 -0700 diff --git a/doc/apt-cache.8.sgml b/doc/apt-cache.8.sgml index 05a81d378..d0ca4fd69 100644 --- a/doc/apt-cache.8.sgml +++ b/doc/apt-cache.8.sgml @@ -41,6 +41,7 @@ depends pkg pkgnames prefix dotty pkg + policy pkgs @@ -242,6 +243,13 @@ Reverse Provides: Caution, dotty cannot graph larger sets of packages. + + policy + + -- 2.45.2