diff options
author | Arch Librarian <arch@canonical.com> | 2004-09-20 16:52:54 +0000 |
---|---|---|
committer | Arch Librarian <arch@canonical.com> | 2004-09-20 16:52:54 +0000 |
commit | 7e2e2d5d4bf08549a535a484be9a258b7e9dcc61 (patch) | |
tree | 1ab61f78b0ae767f97b5a072bfd76908b294f809 | |
parent | 9dbb421ffcf7da89f4010a14e64903189c5e472a (diff) |
apt-cache enhancments
Author: jgg
Date: 1999-02-19 08:57:41 GMT
apt-cache enhancments
-rw-r--r-- | cmdline/apt-cache.cc | 94 | ||||
-rw-r--r-- | doc/apt-cache.8.yo | 21 |
2 files changed, 105 insertions, 10 deletions
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index f9ba327fa..8a3a63695 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.27 1999/02/19 07:56:07 jgg Exp $ +// $Id: apt-cache.cc,v 1.28 1999/02/19 08:57:41 jgg Exp $ /* ###################################################################### apt-cache - Manages the cache files @@ -450,12 +450,52 @@ bool DoAdd(CommandLine &CmdL) return true; } /*}}}*/ +// DisplayRecord - Displays the complete record for the package /*{{{*/ +// --------------------------------------------------------------------- +/* This displays the package record from the proper package index file. + It is not used by DumpAvail for performance reasons. */ +bool DisplayRecord(pkgCache::VerIterator V) +{ + // Find an appropriate file + pkgCache::VerFileIterator Vf = V.FileList(); + for (; Vf.end() == false; Vf++) + if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0) + break; + if (Vf.end() == true) + Vf = V.FileList(); + + // Check and load the package list file + pkgCache::PkgFileIterator I = Vf.File(); + if (I.IsOk() == false) + return _error->Error("Package file %s is out of sync.",I.FileName()); + + FileFd PkgF(I.FileName(),FileFd::ReadOnly); + if (_error->PendingError() == true) + return false; + + // Read the record and then write it out again. + unsigned char *Buffer = new unsigned char[GCache->HeaderP->MaxVerFileSize]; + if (PkgF.Seek(V.FileList()->Offset) == false || + PkgF.Read(Buffer,V.FileList()->Size) == false || + write(STDOUT_FILENO,Buffer,V.FileList()->Size) != V.FileList()->Size) + { + delete [] Buffer; + return false; + } + + delete [] Buffer; + + return true; +} + /*}}}*/ // Search - Perform a search /*{{{*/ // --------------------------------------------------------------------- /* This searches the package names and pacakge descriptions for a pattern */ bool Search(CommandLine &CmdL) { pkgCache &Cache = *GCache; + bool ShowFull = _config->FindB("APT::Cache::ShowFull",false); + bool NamesOnly = _config->FindB("APT::Cache::NamesOnly",false); // Make sure there is at least one argument if (CmdL.FileSize() != 2) @@ -476,16 +516,21 @@ bool Search(CommandLine &CmdL) pkgCache::PkgIterator I = Cache.PkgBegin(); for (;I.end() != true; I++) { - if (regexec(&Pattern,I.Name(),0,0,0) == 0) + // We search against the install version as that makes the most sense.. + pkgCache::VerIterator V = GetCandidateVer(I); + if (V.end() == true) + continue; + + pkgRecords::Parser &P = Recs.Lookup(V.FileList()); + + if (regexec(&Pattern,I.Name(),0,0,0) == 0 || + (NamesOnly == false && + regexec(&Pattern,P.LongDesc().c_str(),0,0,0) == 0)) { - cout << I.Name(); - if (I->VersionList != 0) - { - pkgRecords::Parser &P = Recs.Lookup(I.VersionList().FileList()); - cout << " - " << P.ShortDesc() << endl; - } - else - cout << " [virtual package]" << endl; + if (ShowFull == true) + DisplayRecord(V); + else + cout << I.Name() << " - " << P.ShortDesc() << endl; } } @@ -493,6 +538,31 @@ bool Search(CommandLine &CmdL) return true; } /*}}}*/ +// ShowPackage - Dump the package record to the screen /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool ShowPackage(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; + } + + // 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; + } + return true; +} + /*}}}*/ // GenCaches - Call the main cache generator /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -533,6 +603,7 @@ bool ShowHelp(CommandLine &Cmd) cout << " unmet - Show unmet dependencies" << 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 << endl; cout << "Options:" << endl; cout << " -h This help text." << endl; @@ -565,6 +636,8 @@ int main(int argc,const char *argv[]) {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg}, {'q',"quiet","quiet",CommandLine::IntLevel}, {'i',"important","APT::Cache::Important",0}, + {'f',"full","APT::Cache::ShowFull",0}, + {0,"names-only","APT::Cache::NamesOnly",0}, {'c',"config-file",0,CommandLine::ConfigFile}, {'o',"option",0,CommandLine::ArbItem}, {0,0,0,0}}; @@ -579,6 +652,7 @@ int main(int argc,const char *argv[]) {"unmet",&UnMet}, {"check",&Check}, {"search",&Search}, + {"show",&ShowPackage}, {0,0}}; CacheInitialize(); diff --git a/doc/apt-cache.8.yo b/doc/apt-cache.8.yo index 1a6c5e3b4..1dc463325 100644 --- a/doc/apt-cache.8.yo +++ b/doc/apt-cache.8.yo @@ -20,6 +20,8 @@ itemize( it() dumpavail it() unmet it() check + it() search + it() show ) Unless the -h, or --help option is given one of the above commands @@ -135,6 +137,18 @@ dit(bf(check)) bf(check) is a random function for testing certain aspects of the cache. Do not use it. +dit(bf(show)) +bf(show) performs the same function as dpkg --print-avail, it displays +the package records for the named packages. + +dit(bf(search)) +bf(search) performs a full text search on all available package files for +the pattern given. It searchs the package names and the descriptions for +an occurance of the string and prints out the package name and the short +description. If --full is given then output identical to bf(show) is produced +for each matched package and if --names-only is given then the long +description is not searched, only the package name is. + enddit() manpageoptions() @@ -173,6 +187,13 @@ Print only important deps; for use with unmet causes only em(Depends) and em(Pre-Depends) relations to be printed. See bf(APT::Cache::Important). +dit(bf(-f --full)) +Print full package records when searching. See bf(APT::Cache::ShowFull). + +dit(bf(--names-only)) +Only search on the package names, not the long description. See +bf(APT::Cache::Names-Only). + dit(bf(-c, --config-file)) Configuration File; Specify a configuration file to use. bf(apt-get) will read the default configuration file and then this configuration file. See |