X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/358f10d9d47a88cbf0568f042caccfef8678cbc8..b69968adeab3e04a6e7d68ebf2920b5e608b6fb1:/cmdline/apt-cache.cc diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index c790559e7..79654f477 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -30,8 +31,6 @@ #include #include -#include "cacheset.h" - #include #include @@ -47,6 +46,29 @@ using namespace std; +// CacheSetHelper saving virtual packages /*{{{*/ +class CacheSetHelperVirtuals: public APT::CacheSetHelper { +public: + APT::PackageSet virtualPkgs; + + virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtualPkgs.insert(Pkg); + return CacheSetHelper::canNotFindCandidateVer(Cache, Pkg); + } + + virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtualPkgs.insert(Pkg); + return CacheSetHelper::canNotFindNewestVer(Cache, Pkg); + } + + virtual APT::VersionSet canNotFindAllVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtualPkgs.insert(Pkg); + return CacheSetHelper::canNotFindAllVer(Cache, Pkg); + } + + CacheSetHelperVirtuals(bool const &ShowErrors = true, GlobalError::MsgType const &ErrorType = GlobalError::NOTICE) : CacheSetHelper(ShowErrors, ErrorType) {} +}; + /*}}}*/ // LocalitySort - Sort a version list by package file locality /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -174,7 +196,9 @@ bool UnMet(CommandLine &CmdL) } else { - APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + CacheSetHelperVirtuals helper(true, GlobalError::NOTICE); + APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, + APT::VersionSet::CANDIDATE, helper); for (APT::VersionSet::iterator V = verset.begin(); V != verset.end(); ++V) if (ShowUnMet(V, Important) == false) return false; @@ -188,7 +212,8 @@ bool UnMet(CommandLine &CmdL) bool DumpPackage(CommandLine &CmdL) { pkgCacheFile CacheFile; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + APT::CacheSetHelper helper(true, GlobalError::NOTICE); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1, helper); for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { @@ -552,72 +577,82 @@ bool DumpAvail(CommandLine &Cmd) return !_error->PendingError(); } /*}}}*/ -// Depends - Print out a dependency tree /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool Depends(CommandLine &CmdL) +// ShowDepends - Helper for printing out a dependency tree /*{{{*/ +bool ShowDepends(CommandLine &CmdL, bool const RevDepends) { pkgCacheFile CacheFile; pkgCache *Cache = CacheFile.GetPkgCache(); if (unlikely(Cache == NULL)) return false; - SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; - memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); - - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - Colours[Pkg->ID] = 1; - - bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false); - bool Installed = _config->FindB("APT::Cache::Installed",false); - bool Important = _config->FindB("APT::Cache::Important",false); - bool DidSomething; - do + CacheSetHelperVirtuals helper(false); + APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); + if (verset.empty() == true && helper.virtualPkgs.empty() == true) + return false; + std::vector 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 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); + + while (verset.empty() != true) { - DidSomething = false; - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) - { - if (Colours[Pkg->ID] != 1) - continue; - Colours[Pkg->ID] = 2; - DidSomething = true; - - pkgCache::VerIterator Ver = Pkg.VersionList(); - if (Ver.end() == true) - { - cout << '<' << Pkg.FullName(true) << '>' << endl; - continue; - } - + pkgCache::VerIterator Ver = *verset.begin(); + verset.erase(verset.begin()); + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + Shown[Pkg->ID] = true; + cout << Pkg.FullName(true) << endl; - - for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) + + if (RevDepends == true) + cout << "Reverse Depends:" << endl; + for (pkgCache::DepIterator D = RevDepends ? Pkg.RevDependsList() : Ver.DependsList(); + D.end() == false; D++) { - // Important deps only - if (Important == true) - if (D->Type != pkgCache::Dep::PreDepends && - D->Type != pkgCache::Dep::Depends) - continue; - - pkgCache::PkgIterator Trg = D.TargetPkg(); + 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; + } + + pkgCache::PkgIterator Trg = RevDepends ? D.ParentPkg() : D.TargetPkg(); if((Installed && Trg->CurrentVer != 0) || !Installed) { - if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) + 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 << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl; + cout << "<" << Trg.FullName(true) << ">" << endl; else - cout << D.DepType() << ": " << Trg.FullName(true) << endl; + cout << Trg.FullName(true) << endl; - if (Recurse == true) - Colours[D.TargetPkg()->ID]++; + if (Recurse == true && Shown[Trg->ID] == false) + { + Shown[Trg->ID] = true; + verset.insert(APT::VersionSet::FromPackage(CacheFile, Trg, APT::VersionSet::CANDIDATE, helper)); + } } @@ -631,101 +666,40 @@ bool Depends(CommandLine &CmdL) V->ParentPkg == D->Package) continue; cout << " " << V.ParentPkg().FullName(true) << endl; - - if (Recurse == true) - Colours[D.ParentPkg()->ID]++; + + if (Recurse == true && Shown[V.ParentPkg()->ID] == false) + { + Shown[V.ParentPkg()->ID] = true; + verset.insert(APT::VersionSet::FromPackage(CacheFile, V.ParentPkg(), APT::VersionSet::CANDIDATE, helper)); + } } + + if (ShowOnlyFirstOr == true) + while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; } - } - } - while (DidSomething == true); - + } + + for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin(); + Pkg != helper.virtualPkgs.end(); ++Pkg) + cout << '<' << Pkg.FullName(true) << '>' << endl; + return true; } /*}}}*/ -// RDepends - Print out a reverse dependency tree - mbc /*{{{*/ +// Depends - Print out a dependency tree /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool Depends(CommandLine &CmdL) +{ + return ShowDepends(CmdL, false); +} + /*}}}*/ +// RDepends - Print out a reverse dependency tree /*{{{*/ // --------------------------------------------------------------------- /* */ bool RDepends(CommandLine &CmdL) { - pkgCacheFile CacheFile; - pkgCache *Cache = CacheFile.GetPkgCache(); - if (unlikely(Cache == NULL)) - return false; - - SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; - memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); - - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - Colours[Pkg->ID] = 1; - - bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false); - bool Installed = _config->FindB("APT::Cache::Installed",false); - bool DidSomething; - do - { - DidSomething = false; - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) - { - if (Colours[Pkg->ID] != 1) - continue; - Colours[Pkg->ID] = 2; - DidSomething = true; - - pkgCache::VerIterator Ver = Pkg.VersionList(); - if (Ver.end() == true) - { - cout << '<' << Pkg.FullName(true) << '>' << endl; - continue; - } - - cout << Pkg.FullName(true) << endl; - - cout << "Reverse Depends:" << endl; - for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++) - { - // Show the package - pkgCache::PkgIterator Trg = D.ParentPkg(); - - if((Installed && Trg->CurrentVer != 0) || !Installed) - { - - if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) - cout << " |"; - else - cout << " "; - - if (Trg->VersionList == 0) - cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl; - else - cout << Trg.FullName(true) << endl; - - if (Recurse == true) - Colours[D.ParentPkg()->ID]++; - - } - - // Display all solutions - SPtrArray List = D.AllTargets(); - pkgPrioSortList(*Cache,List); - 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().FullName(true) << endl; - - if (Recurse == true) - Colours[D.ParentPkg()->ID]++; - } - } - } - } - while (DidSomething == true); - - return true; + return ShowDepends(CmdL, true); } /*}}}*/ // xvcg - Generate a graph for xvcg /*{{{*/ @@ -790,11 +764,12 @@ bool XVcg(CommandLine &CmdL) } // Load the list of packages from the command line into the show list + APT::CacheSetHelper helper(true, GlobalError::NOTICE); std::list mods; mods.push_back(APT::PackageSet::Modifier(0, ",", APT::PackageSet::Modifier::POSTFIX)); mods.push_back(APT::PackageSet::Modifier(1, "^", APT::PackageSet::Modifier::POSTFIX)); std::map pkgsets = - APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0); + APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0, helper); for (APT::PackageSet::const_iterator Pkg = pkgsets[0].begin(); Pkg != pkgsets[0].end(); ++Pkg) @@ -1004,11 +979,12 @@ bool Dotty(CommandLine &CmdL) } // Load the list of packages from the command line into the show list + APT::CacheSetHelper helper(true, GlobalError::NOTICE); std::list mods; mods.push_back(APT::PackageSet::Modifier(0, ",", APT::PackageSet::Modifier::POSTFIX)); mods.push_back(APT::PackageSet::Modifier(1, "^", APT::PackageSet::Modifier::POSTFIX)); std::map pkgsets = - APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0); + APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0, helper); for (APT::PackageSet::const_iterator Pkg = pkgsets[0].begin(); Pkg != pkgsets[0].end(); ++Pkg) @@ -1218,7 +1194,7 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V) return _error->Error(_("Package file %s is out of sync."),I.FileName()); FileFd PkgF; - if (PkgF.Open(I.FileName(), FileFd::ReadOnly) == false) + if (PkgF.Open(I.FileName(), FileFd::ReadOnlyGzip) == false) return false; // Read the record @@ -1345,7 +1321,7 @@ bool Search(CommandLine &CmdL) continue; pkgCache::VerIterator V = Plcy->GetCandidateVer(P); if (V.end() == false) - DFList[G->ID].Df = V.DescriptionList().FileList(); + DFList[G->ID].Df = V.TranslatedDescription().FileList(); if (DFList[G->ID].NameMatch == false) continue; @@ -1358,7 +1334,7 @@ bool Search(CommandLine &CmdL) continue; unsigned long id = Prv.OwnerPkg().Group()->ID; - DFList[id].Df = V.DescriptionList().FileList(); + DFList[id].Df = V.TranslatedDescription().FileList(); DFList[id].NameMatch = true; } } @@ -1439,16 +1415,22 @@ bool ShowAuto(CommandLine &CmdL) bool ShowPackage(CommandLine &CmdL) { pkgCacheFile CacheFile; + CacheSetHelperVirtuals helper(true, GlobalError::NOTICE); APT::VersionSet::Version const select = _config->FindB("APT::Cache::AllVersions", true) ? APT::VersionSet::ALL : APT::VersionSet::CANDIDATE; - APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, select); + APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper); for (APT::VersionSet::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) if (DisplayRecord(CacheFile, Ver) == false) return false; - if (verset.empty() == false) - return true; - return _error->Error(_("No packages found")); + if (verset.empty() == true) + { + if (helper.virtualPkgs.empty() == true) + return _error->Error(_("No packages found")); + else + _error->Notice(_("No packages found")); + } + return true; } /*}}}*/ // ShowPkgNames - Show package names /*{{{*/ @@ -1521,10 +1503,10 @@ bool ShowSrcPackage(CommandLine &CmdL) _error->Warning(_("Unable to locate package %s"),*I); continue; } - } - if (found > 0) - return true; - return _error->Error(_("No packages found")); + } + if (found == 0) + _error->Notice(_("No packages found")); + return true; } /*}}}*/ // Policy - Show the results of the preferences file /*{{{*/ @@ -1600,7 +1582,8 @@ bool Policy(CommandLine &CmdL) (InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1; // Print out detailed information for each package - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + APT::CacheSetHelper helper(true, GlobalError::NOTICE); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1, helper); for (APT::PackageSet::const_iterator I = pkgset.begin(); I != pkgset.end(); ++I) { pkgCache::PkgIterator Pkg = I.Group().FindPkg("any"); @@ -1680,10 +1663,12 @@ bool Madison(CommandLine &CmdL) if (_error->PendingError() == true) _error->Discard(); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + APT::CacheSetHelper helper(true, GlobalError::NOTICE); + for (const char **I = CmdL.FileList + 1; *I != 0; I++) { - if (Pkg.end() == false) + _error->PushToStack(); + APT::PackageSet pkgset = APT::PackageSet::FromString(CacheFile, *I, helper); + for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { for (pkgCache::VerIterator V = Pkg.VersionList(); V.end() == false; V++) { @@ -1714,16 +1699,21 @@ bool Madison(CommandLine &CmdL) } } - SrcRecs.Restart(); pkgSrcRecords::Parser *SrcParser; - while ((SrcParser = SrcRecs.Find(Pkg.Name(),false)) != 0) + bool foundSomething = false; + while ((SrcParser = SrcRecs.Find(*I, false)) != 0) { + foundSomething = true; // Maybe support Release info here too eventually cout << setw(10) << SrcParser->Package() << " | " << setw(10) << SrcParser->Version() << " | " << SrcParser->Index().Describe(true) << endl; } + if (foundSomething == true) + _error->RevertToStack(); + else + _error->MergeWithStack(); } return true; @@ -1791,15 +1781,6 @@ bool ShowHelp(CommandLine &Cmd) return true; } /*}}}*/ -// CacheInitialize - Initialize things for apt-cache /*{{{*/ -// --------------------------------------------------------------------- -/* */ -void CacheInitialize() -{ - _config->Set("quiet",0); - _config->Set("help",false); -} - /*}}}*/ int main(int argc,const char *argv[]) /*{{{*/ { CommandLine::Args Args[] = { @@ -1820,6 +1801,14 @@ int main(int argc,const char *argv[]) /*{{{*/ {'c',"config-file",0,CommandLine::ConfigFile}, {'o',"option",0,CommandLine::ArbItem}, {0,"installed","APT::Cache::Installed",0}, + {0,"pre-depends","APT::Cache::ShowPreDepends",0}, + {0,"depends","APT::Cache::ShowDepends",0}, + {0,"recommends","APT::Cache::ShowRecommends",0}, + {0,"suggests","APT::Cache::ShowSuggests",0}, + {0,"replaces","APT::Cache::ShowReplaces",0}, + {0,"breaks","APT::Cache::ShowBreaks",0}, + {0,"conflicts","APT::Cache::ShowConflicts",0}, + {0,"enhances","APT::Cache::ShowEnhances",0}, {0,0,0,0}}; CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp}, {"add",&DoAdd}, @@ -1843,8 +1832,6 @@ int main(int argc,const char *argv[]) /*{{{*/ {"madison",&Madison}, {0,0}}; - CacheInitialize(); - // Set up gettext support setlocale(LC_ALL,""); textdomain(PACKAGE);