#include <apt-private/private-cacheset.h>
#include <apt-private/private-cmndline.h>
+#include <apt-private/private-depends.h>
#include <apt-private/private-show.h>
#include <apt-private/private-search.h>
+#include <apt-private/private-unmet.h>
#include <apt-private/private-main.h>
#include <regex.h>
using namespace std;
-// UnMet - Show unmet dependencies /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool ShowUnMet(pkgCache::VerIterator const &V, bool const Important)
-{
- bool Header = false;
- for (pkgCache::DepIterator D = V.DependsList(); D.end() == false;)
- {
- // Collect or groups
- pkgCache::DepIterator Start;
- pkgCache::DepIterator End;
- D.GlobOr(Start,End);
-
- // Important deps only
- if (Important == true)
- if (End->Type != pkgCache::Dep::PreDepends &&
- End->Type != pkgCache::Dep::Depends)
- continue;
-
- // Skip conflicts and replaces
- if (End.IsNegative() == true || End->Type == pkgCache::Dep::Replaces)
- continue;
-
- // Verify the or group
- bool OK = false;
- pkgCache::DepIterator RealStart = Start;
- do
- {
- // See if this dep is Ok
- pkgCache::Version **VList = Start.AllTargets();
- if (*VList != 0)
- {
- OK = true;
- delete [] VList;
- break;
- }
- delete [] VList;
-
- if (Start == End)
- break;
- ++Start;
- }
- while (1);
-
- // The group is OK
- if (OK == true)
- continue;
-
- // Oops, it failed..
- if (Header == false)
- ioprintf(cout,_("Package %s version %s has an unmet dep:\n"),
- V.ParentPkg().FullName(true).c_str(),V.VerStr());
- Header = true;
-
- // Print out the dep type
- cout << " " << End.DepType() << ": ";
-
- // Show the group
- Start = RealStart;
- do
- {
- cout << Start.TargetPkg().FullName(true);
- if (Start.TargetVer() != 0)
- cout << " (" << Start.CompType() << " " << Start.TargetVer() <<
- ")";
- if (Start == End)
- break;
- cout << " | ";
- ++Start;
- }
- while (1);
-
- cout << endl;
- }
- return true;
-}
-static bool UnMet(CommandLine &CmdL)
-{
- bool const Important = _config->FindB("APT::Cache::Important",false);
-
- pkgCacheFile CacheFile;
- if (unlikely(CacheFile.GetPkgCache() == NULL))
- return false;
-
- if (CmdL.FileSize() <= 1)
- {
- for (pkgCache::PkgIterator P = CacheFile.GetPkgCache()->PkgBegin(); P.end() == false; ++P)
- for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V)
- if (ShowUnMet(V, Important) == false)
- return false;
- }
- else
- {
- CacheSetHelperVirtuals helper(true, GlobalError::NOTICE);
- APT::VersionList verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1,
- APT::CacheSetHelper::CANDIDATE, helper);
- for (APT::VersionList::iterator V = verset.begin(); V != verset.end(); ++V)
- if (ShowUnMet(V, Important) == false)
- return false;
- }
- return true;
-}
- /*}}}*/
// DumpPackage - Show a dump of a package record /*{{{*/
// ---------------------------------------------------------------------
/* */
cout << "Total buckets in " << Type << ": " << NumBuckets << std::endl;
cout << " Unused: " << UnusedBuckets << std::endl;
cout << " Used: " << UsedBuckets << std::endl;
- cout << " Average entries: " << Entries/(double)NumBuckets << std::endl;
+ cout << " Utilization: " << 100.0 * UsedBuckets/NumBuckets << "%" << std::endl;
+ cout << " Average entries: " << Entries/(double)UsedBuckets << std::endl;
cout << " Longest: " << LongestBucket << std::endl;
cout << " Shortest: " << ShortestBucket << std::endl;
}
return !_error->PendingError();
}
/*}}}*/
-// ShowDepends - Helper for printing out a dependency tree /*{{{*/
-static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
-{
- pkgCacheFile CacheFile;
- pkgCache *Cache = CacheFile.GetPkgCache();
- if (unlikely(Cache == NULL))
- return false;
-
- CacheSetHelperVirtuals helper(false);
- APT::VersionList verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
- if (verset.empty() == true && helper.virtualPkgs.empty() == true)
- return _error->Error(_("No packages found"));
- std::vector<bool> Shown(Cache->Head().PackageCount);
-
- bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false);
- bool const Installed = _config->FindB("APT::Cache::Installed", false);
- bool const Important = _config->FindB("APT::Cache::Important", false);
- bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType", RevDepends == false);
- bool const ShowVersion = _config->FindB("APT::Cache::ShowVersion", false);
- bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true);
- bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true);
- bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false);
- bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false);
- bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false);
- bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false);
- bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false);
- bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false);
- bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false);
- bool const ShowImplicit = _config->FindB("APT::Cache::ShowImplicit", false);
-
- while (verset.empty() != true)
- {
- pkgCache::VerIterator Ver = *verset.begin();
- verset.erase(verset.begin());
- pkgCache::PkgIterator Pkg = Ver.ParentPkg();
- Shown[Pkg->ID] = true;
-
- cout << Pkg.FullName(true) << endl;
-
- if (RevDepends == true)
- cout << "Reverse Depends:" << endl;
- for (pkgCache::DepIterator D = RevDepends ? Pkg.RevDependsList() : Ver.DependsList();
- D.end() == false; ++D)
- {
- switch (D->Type) {
- case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break;
- case pkgCache::Dep::Depends: if (!ShowDepends) continue; break;
- case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break;
- case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break;
- case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break;
- case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break;
- case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break;
- case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break;
- }
- if (ShowImplicit == false && D.IsImplicit())
- continue;
-
- pkgCache::PkgIterator Trg = RevDepends ? D.ParentPkg() : D.TargetPkg();
-
- if((Installed && Trg->CurrentVer != 0) || !Installed)
- {
-
- if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false)
- cout << " |";
- else
- cout << " ";
-
- // Show the package
- if (ShowDepType == true)
- cout << D.DepType() << ": ";
- if (Trg->VersionList == 0)
- cout << "<" << Trg.FullName(true) << ">";
- else
- cout << Trg.FullName(true);
- if (ShowVersion == true && D->Version != 0)
- cout << " (" << pkgCache::CompTypeDeb(D->CompareOp) << ' ' << D.TargetVer() << ')';
- cout << std::endl;
-
- if (Recurse == true && Shown[Trg->ID] == false)
- {
- Shown[Trg->ID] = true;
- verset.insert(APT::VersionSet::FromPackage(CacheFile, Trg, APT::CacheSetHelper::CANDIDATE, helper));
- }
-
- }
-
- // Display all solutions
- std::unique_ptr<pkgCache::Version *[]> List(D.AllTargets());
- pkgPrioSortList(*Cache,List.get());
- for (pkgCache::Version **I = List.get(); *I != 0; I++)
- {
- pkgCache::VerIterator V(*Cache,*I);
- if (V != Cache->VerP + V.ParentPkg()->VersionList ||
- V->ParentPkg == D->Package)
- continue;
- cout << " " << V.ParentPkg().FullName(true) << endl;
-
- if (Recurse == true && Shown[V.ParentPkg()->ID] == false)
- {
- Shown[V.ParentPkg()->ID] = true;
- verset.insert(APT::VersionSet::FromPackage(CacheFile, V.ParentPkg(), APT::CacheSetHelper::CANDIDATE, helper));
- }
- }
-
- if (ShowOnlyFirstOr == true)
- while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D;
- }
- }
-
- for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin();
- Pkg != helper.virtualPkgs.end(); ++Pkg)
- cout << '<' << Pkg.FullName(true) << '>' << endl;
-
- return true;
-}
- /*}}}*/
-// Depends - Print out a dependency tree /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool Depends(CommandLine &CmdL)
-{
- return ShowDepends(CmdL, false);
-}
- /*}}}*/
-// RDepends - Print out a reverse dependency tree /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool RDepends(CommandLine &CmdL)
-{
- return ShowDepends(CmdL, true);
-}
- /*}}}*/
// xvcg - Generate a graph for xvcg /*{{{*/
// ---------------------------------------------------------------------
// Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
cout << I.Name() << endl;
}
- return true;
-}
- /*}}}*/
-// ShowSrcPackage - Show source package records /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool ShowSrcPackage(CommandLine &CmdL)
-{
- pkgCacheFile CacheFile;
- pkgSourceList *List = CacheFile.GetSourceList();
- if (unlikely(List == NULL))
- return false;
-
- // Create the text record parsers
- pkgSrcRecords SrcRecs(*List);
- if (_error->PendingError() == true)
- return false;
-
- unsigned found = 0;
- for (const char **I = CmdL.FileList + 1; *I != 0; I++)
- {
- SrcRecs.Restart();
-
- pkgSrcRecords::Parser *Parse;
- unsigned found_this = 0;
- while ((Parse = SrcRecs.Find(*I,false)) != 0) {
- // SrcRecs.Find() will find both binary and source names
- if (_config->FindB("APT::Cache::Only-Source", false) == true)
- if (Parse->Package() != *I)
- continue;
- cout << Parse->AsStr() << endl;;
- found++;
- found_this++;
- }
- if (found_this == 0) {
- _error->Warning(_("Unable to locate package %s"),*I);
- continue;
- }
- }
- if (found == 0)
- _error->Notice(_("No packages found"));
- return true;
-}
- /*}}}*/
-// Policy - Show the results of the preferences file /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool Policy(CommandLine &CmdL)
-{
- pkgCacheFile CacheFile;
- pkgCache *Cache = CacheFile.GetPkgCache();
- pkgPolicy *Plcy = CacheFile.GetPolicy();
- pkgSourceList *SrcList = CacheFile.GetSourceList();
- if (unlikely(Cache == NULL || Plcy == NULL || SrcList == NULL))
- return false;
-
- /* Should the MultiArchKiller be run to see which pseudo packages for an
- arch all package are currently installed? Activating it gives a speed
- penality for no real gain beside enhanced debugging, so in general no. */
- if (_config->FindB("APT::Cache::Policy::DepCache", false) == true)
- CacheFile.GetDepCache();
-
- // 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)
- {
- if (F.Flagged(pkgCache::Flag::NoPackages))
- continue;
- // 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)
- {
- // Old code for debugging
- if (_config->FindI("APT::Policy", 1) < 1) {
- if (Plcy->GetPriority(I) == 0)
- continue;
-
- // Print the package name and the version we are forcing to
- cout << " " << I.FullName(true) << " -> ";
-
- pkgCache::VerIterator V = Plcy->GetMatch(I);
- if (V.end() == true)
- cout << _("(not found)") << endl;
- else
- cout << V.VerStr() << endl;
-
- continue;
- }
- // New code
- for (pkgCache::VerIterator V = I.VersionList(); !V.end(); V++) {
- auto Prio = Plcy->GetPriority(V, false);
- if (Prio == 0)
- continue;
-
- cout << " ";
- // Print the package name and the version we are forcing to
- ioprintf(cout, _("%s -> %s with priority %d\n"), I.FullName(true).c_str(), V.VerStr(), Prio);
- }
- }
- return true;
- }
-
- char const * const msgInstalled = _(" Installed: ");
- char const * const msgCandidate = _(" Candidate: ");
- short const InstalledLessCandidate =
- mbstowcs(NULL, msgInstalled, 0) - mbstowcs(NULL, msgCandidate, 0);
- short const deepInstalled =
- (InstalledLessCandidate < 0 ? (InstalledLessCandidate*-1) : 0) - 1;
- short const deepCandidate =
- (InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1;
-
- // Print out detailed information for each package
- APT::CacheSetHelper helper(true, GlobalError::NOTICE);
- APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1, helper);
- for (APT::PackageList::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg)
- {
- cout << Pkg.FullName(true) << ":" << endl;
-
- // Installed version
- cout << msgInstalled << OutputInDepth(deepInstalled, " ");
- if (Pkg->CurrentVer == 0)
- cout << _("(none)") << endl;
- else
- cout << Pkg.CurrentVer().VerStr() << endl;
-
- // Candidate Version
- cout << msgCandidate << OutputInDepth(deepCandidate, " ");
- pkgCache::VerIterator V = Plcy->GetCandidateVer(Pkg);
- if (V.end() == true)
- cout << _("(none)") << endl;
- else
- cout << V.VerStr() << endl;
-
- // Pinned version
- if (_config->FindI("APT::Policy", 1) < 1 && 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();
- if (_config->FindI("APT::Policy", 1) < 1)
- cout << " " << Plcy->GetPriority(Pkg) << endl;
- else
- cout << " " << Plcy->GetPriority(V) << 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;
}
/*}}}*/
return CacheFile.BuildCaches(&Progress, true);
}
/*}}}*/
-// ShowHelp - Show a help screen /*{{{*/
-static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
+static bool ShowHelp(CommandLine &) /*{{{*/
{
- ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-
- if (_config->FindB("version") == true)
- return true;
-
std::cout <<
_("Usage: apt-cache [options] command\n"
" apt-cache [options] show pkg1 [pkg2 ...]\n"
"\n"
- "apt-cache is a low-level tool used to query information\n"
- "from APT's binary cache files\n")
- << std::endl
- << _("Commands:") << std::endl;
- for (; Cmds->Handler != nullptr; ++Cmds)
- {
- if (Cmds->Help == nullptr)
- continue;
- std::cout << " " << Cmds->Match << " - " << Cmds->Help << std::endl;
- }
-
- std::cout << std::endl
- << _("Options:\n"
- " -h This help text.\n"
- " -p=? The package cache.\n"
- " -s=? The source cache.\n"
- " -q Disable progress indicator.\n"
- " -i Show only important deps for the unmet command.\n"
- " -c=? Read this configuration file\n"
- " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
- "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n");
+ "apt-cache queries and displays available information about installed\n"
+ "and installable packages. It works exclusively on the data acquired\n"
+ "into the local cache via the 'update' command of e.g. apt-get. The\n"
+ "displayed information may therefore be outdated if the last update was\n"
+ "too long ago, but in exchange apt-cache works independently of the\n"
+ "availability of the configured sources (e.g. offline).\n");
return true;
}
/*}}}*/
-int main(int argc,const char *argv[]) /*{{{*/
+static std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/
{
- InitLocale();
-
- CommandLine::DispatchWithHelp Cmds[] = {
+ return {
{"gencaches",&GenCaches, nullptr},
{"showsrc",&ShowSrcPackage, _("Show source records")},
{"showpkg",&DumpPackage, nullptr},
{"madison",&Madison, nullptr},
{nullptr, nullptr, nullptr}
};
+}
+ /*}}}*/
+int main(int argc,const char *argv[]) /*{{{*/
+{
+ InitLocale();
// Parse the command line and initialize the package library
CommandLine CmdL;
- ParseCommandLine(CmdL, Cmds, "apt-cache", &_config, &_system, argc, argv, ShowHelp);
+ auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_CACHE, &_config, &_system, argc, argv, &ShowHelp, &GetCommands);
InitOutput();