// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: apt-cache.cc,v 1.29 1999/03/17 03:25:25 jgg Exp $
+// $Id: apt-cache.cc,v 1.41 1999/10/22 04:05:47 jgg Exp $
/* ######################################################################
apt-cache - Manages the cache files
apt-cache provides some functions fo manipulating the cache files.
It uses the command line interface common to all the APT tools. The
only really usefull function right now is dumpavail which is used
- by the dselect method. Everything else is ment as a debug aide.
+ by the dselect method. Everything else is meant as a debug aide.
Returns 100 on failure, 0 on success.
#include <apt-pkg/cmndline.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/pkgrecords.h>
+#include <apt-pkg/srcrecords.h>
#include <config.h>
#include <iostream.h>
}
cout << "Reverse Provides: " << endl;
for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; Prv++)
- cout << Prv.OwnerPkg().Name() << " " << Prv.OwnerVer().VerStr();
- cout << endl;
-
+ cout << Prv.OwnerPkg().Name() << " " << Prv.OwnerVer().VerStr() << endl;
}
return true;
return true;
}
/*}}}*/
-// GetCandidateVer - Returns the Candidate install version /*{{{*/
-// ---------------------------------------------------------------------
-/* This should really use the DepCache or something.. Copied from there. */
-static pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator Pkg)
-{
- /* Not source/not automatic versions cannot be a candidate version
- unless they are already installed */
- for (pkgCache::VerIterator I = Pkg.VersionList(); I.end() == false; I++)
- {
- if (Pkg.CurrentVer() == I)
- return I;
- for (pkgCache::VerFileIterator J = I.FileList(); J.end() == false; J++)
- if ((J.File()->Flags & pkgCache::Flag::NotSource) == 0 &&
- (J.File()->Flags & pkgCache::Flag::NotAutomatic) == 0)
- return I;
- }
-
- return pkgCache::VerIterator(*GCache,0);
-}
- /*}}}*/
// DumpAvail - Print out the available list /*{{{*/
// ---------------------------------------------------------------------
/* This is needed to make dpkg --merge happy */
for (pkgCache::PkgFileIterator I = Cache.FileBegin(); I.end() == false; I++)
{
+ if ((I->Flags & pkgCache::Flag::NotSource) != 0)
+ continue;
+
if (I.IsOk() == false)
{
delete [] Buffer;
for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
{
// Find the proper version to use. We should probably use the DepCache.
- pkgCache::VerIterator V = GetCandidateVer(P);
+ pkgCache::VerIterator V = Cache.GetCandidateVer(P,false);
if (V.end() == true || V.FileList().File() != I)
continue;
}
}
+ return true;
+}
+ /*}}}*/
+// Depends - Print out a dependency tree /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool Depends(CommandLine &CmdL)
+{
+ pkgCache &Cache = *GCache;
+
+ 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;
+ }
+
+ pkgCache::VerIterator Ver = Pkg.VersionList();
+ if (Ver.end() == true)
+ {
+ cout << '<' << Pkg.Name() << '>' << endl;
+ continue;
+ }
+
+ cout << Pkg.Name() << endl;
+
+ for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
+ {
+ if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
+ cout << " |";
+ else
+ cout << " ";
+
+ // Show the package
+ pkgCache::PkgIterator Trg = D.TargetPkg();
+ if (Trg->VersionList == 0)
+ cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
+ else
+ cout << D.DepType() << ": " << Trg.Name() << endl;
+
+ // Display all solutions
+ pkgCache::Version **List = D.AllTargets();
+ for (pkgCache::Version **I = List; *I != 0; I++)
+ {
+ pkgCache::VerIterator V(Cache,*I);
+ if (V != Cache.VerP + V.ParentPkg()->VersionList ||
+ V->ParentPkg == D->Package)
+ continue;
+ cout << " " << V.ParentPkg().Name() << endl;
+ }
+ delete [] List;
+ }
+ }
+
return true;
}
/*}}}*/
for (;I.end() != true; I++)
{
// We search against the install version as that makes the most sense..
- pkgCache::VerIterator V = GetCandidateVer(I);
+ pkgCache::VerIterator V = Cache.GetCandidateVer(I);
if (V.end() == true)
continue;
}
// Find the proper version to use. We should probably use the DepCache.
- pkgCache::VerIterator V = GetCandidateVer(Pkg);
- if (V.end() == true || V.FileList().end() == true)
- continue;
- if (DisplayRecord(V) == false)
- return false;
+ if (_config->FindB("APT::Cache::AllVersions","true") == true)
+ {
+ pkgCache::VerIterator V;
+ for (V = Pkg.VersionList(); V.end() == false; V++)
+ {
+ if (DisplayRecord(V) == false)
+ return false;
+ }
+ }
+ else
+ {
+ pkgCache::VerIterator V = Cache.GetCandidateVer(Pkg);
+ if (V.end() == true || V.FileList().end() == true)
+ continue;
+ if (DisplayRecord(V) == false)
+ return false;
+ }
}
return true;
}
/*}}}*/
+// ShowSrcPackage - Show source package records /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool ShowSrcPackage(CommandLine &CmdL)
+{
+ pkgSourceList List;
+ List.ReadMainList();
+
+ // Create the text record parsers
+ pkgSrcRecords SrcRecs(List);
+ if (_error->PendingError() == true)
+ return false;
+
+ for (const char **I = CmdL.FileList + 1; *I != 0; I++)
+ {
+ SrcRecs.Restart();
+
+ pkgSrcRecords::Parser *Parse;
+ while ((Parse = SrcRecs.Find(*I,false)) != 0)
+ cout << Parse->AsStr();
+ }
+ return true;
+}
+ /*}}}*/
// GenCaches - Call the main cache generator /*{{{*/
// ---------------------------------------------------------------------
/* */
cout << endl;
cout << "apt-cache is a low-level tool used to manipulate APT's binary" << endl;
cout << "cache files stored in " << _config->FindFile("Dir::Cache") << endl;
- cout << "It is not ment for ordinary use only as a debug aide." << endl;
+ cout << "It is not meant for ordinary use only as a debug aide." << endl;
cout << endl;
cout << "Commands:" << endl;
cout << " add - Add an package file to the source cache" << endl;
cout << " check - Check the cache a bit" << endl;
cout << " search - Search the package list for a regex pattern" << endl;
cout << " show - Show a readable record for the package" << endl;
+ cout << " depends - Show raw dependency information for a package" << endl;
cout << endl;
cout << "Options:" << endl;
cout << " -h This help text." << endl;
cout << " -q Disable progress indicator." << endl;
cout << " -i Show only important deps for the unmet command." << endl;
cout << " -c=? Read this configuration file" << endl;
- cout << " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl;
+ cout << " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl;
cout << "See the apt-cache(8) and apt.conf(5) manual pages for more information." << endl;
return 100;
}
{'q',"quiet","quiet",CommandLine::IntLevel},
{'i',"important","APT::Cache::Important",0},
{'f',"full","APT::Cache::ShowFull",0},
+ {'g',"no-generate","APT::Cache::NoGenerate",0},
+ {'a',"all-versions","APT::Cache::AllVersions",0},
{0,"names-only","APT::Cache::NamesOnly",0},
{'c',"config-file",0,CommandLine::ConfigFile},
{'o',"option",0,CommandLine::ArbItem},
CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp},
{"add",&DoAdd},
{"gencaches",&GenCaches},
+ {"showsrc",&ShowSrcPackage},
{0,0}};
CommandLine::Dispatch CmdsB[] = {{"showpkg",&DumpPackage},
{"stats",&Stats},
{"unmet",&UnMet},
{"check",&Check},
{"search",&Search},
+ {"depends",&Depends},
{"show",&ShowPackage},
{0,0}};
CmdL.FileSize() == 0)
return ShowHelp(CmdL);
+ // Deal with stdout not being a tty
+ if (ttyname(STDOUT_FILENO) == 0 && _config->FindI("quiet",0) < 1)
+ _config->Set("quiet","1");
+
if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false)
- {
- // Open the cache file
- FileFd CacheF(_config->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly);
- MMap Map(CacheF,MMap::Public | MMap::ReadOnly);
+ {
+ MMap *Map;
+ if (_config->FindB("APT::Cache::NoGenerate",false) == true)
+ {
+ Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"),
+ FileFd::ReadOnly),MMap::Public|MMap::ReadOnly);
+ }
+ else
+ {
+ // Open the cache file
+ pkgSourceList List;
+ List.ReadMainList();
+
+ // Generate it and map it
+ OpProgress Prog;
+ Map = pkgMakeStatusCacheMem(List,Prog);
+ }
+
if (_error->PendingError() == false)
{
- pkgCache Cache(Map);
+ pkgCache Cache(*Map);
GCache = &Cache;
if (_error->PendingError() == false)
CmdL.DispatchArg(CmdsB);
- }
+ }
+ delete Map;
}
// Print any errors or warnings found during parsing