Explorar el Código

'apt-cache policy' preferences debug tool.
Author: jgg
Date: 2001-04-29 05:13:51 GMT
'apt-cache policy' preferences debug tool.

Arch Librarian hace 22 años
padre
commit
af87ab5443

+ 3 - 2
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) {};

+ 14 - 7
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;
 }
 									/*}}}*/

+ 4 - 4
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

+ 29 - 2
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<pkgIndexFile *> &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;
+}
+									/*}}}*/

+ 7 - 1
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 <apt-pkg/pkgsystem.h>
     
+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<pkgIndexFile *> &List);
+   virtual bool FindIndex(pkgCache::PkgFileIterator File,
+			  pkgIndexFile *&Found) const;
 
    debSystem();
+   ~debSystem();
 };
 
 extern debSystem debSys;

+ 2 - 2
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();};

+ 20 - 1
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;
+}
+									/*}}}*/

+ 3 - 1
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<pkgIndexFile *> &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.. */

+ 33 - 17
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			/*{{{*/
 // ---------------------------------------------------------------------

+ 8 - 2
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();

+ 4 - 4
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;
    }

+ 125 - 4
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)

+ 1 - 0
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 <jgg@debian.org>  Thu,  8 Mar 2001 22:48:06 -0700
 

+ 8 - 0
doc/apt-cache.8.sgml

@@ -41,6 +41,7 @@
          <arg>depends <arg choice="plain" rep="repeat"><replaceable>pkg</replaceable></arg></arg>
          <arg>pkgnames <arg choice="plain"><replaceable>prefix</replaceable></arg></arg>
          <arg>dotty <arg choice="plain" rep="repeat"><replaceable>pkg</replaceable></arg></arg>
+         <arg>policy <arg choice="plain" rep="repeat"><replaceable>pkgs</replaceable></arg></arg>
       </group>   
    </cmdsynopsis>
  </refsynopsisdiv>
@@ -242,6 +243,13 @@ Reverse Provides:
 
      <para>
      Caution, dotty cannot graph larger sets of packages.
+     
+     <VarListEntry><Term>policy</Term>
+     <ListItem><Para>
+     <literal/policy/ is ment to help debug issues relating to the 
+     preferences file. With no arguments it will print out the 
+     priorities of each source. Otherwise it prints out detailed information
+     about the priority selection of the named package.
      </VarListEntry>
    </VariableList>
  </RefSect1>