apt-cache.cc 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: apt-cache.cc,v 1.72 2004/04/30 04:34:03 mdz Exp $
  4. /* ######################################################################
  5. apt-cache - Manages the cache files
  6. apt-cache provides some functions fo manipulating the cache files.
  7. It uses the command line interface common to all the APT tools.
  8. Returns 100 on failure, 0 on success.
  9. ##################################################################### */
  10. /*}}}*/
  11. // Include Files /*{{{*/
  12. #include<config.h>
  13. #include <apt-pkg/algorithms.h>
  14. #include <apt-pkg/cachefile.h>
  15. #include <apt-pkg/cacheset.h>
  16. #include <apt-pkg/cmndline.h>
  17. #include <apt-pkg/error.h>
  18. #include <apt-pkg/fileutl.h>
  19. #include <apt-pkg/indexfile.h>
  20. #include <apt-pkg/init.h>
  21. #include <apt-pkg/metaindex.h>
  22. #include <apt-pkg/pkgrecords.h>
  23. #include <apt-pkg/pkgsystem.h>
  24. #include <apt-pkg/policy.h>
  25. #include <apt-pkg/progress.h>
  26. #include <apt-pkg/sourcelist.h>
  27. #include <apt-pkg/sptr.h>
  28. #include <apt-pkg/srcrecords.h>
  29. #include <apt-pkg/strutl.h>
  30. #include <apt-pkg/tagfile.h>
  31. #include <apt-pkg/version.h>
  32. #include <apt-pkg/cacheiterators.h>
  33. #include <apt-pkg/configuration.h>
  34. #include <apt-pkg/depcache.h>
  35. #include <apt-pkg/macros.h>
  36. #include <apt-pkg/mmap.h>
  37. #include <apt-pkg/pkgcache.h>
  38. #include <apt-private/private-cacheset.h>
  39. #include <apt-private/private-cmndline.h>
  40. #include <apt-private/private-depends.h>
  41. #include <apt-private/private-show.h>
  42. #include <apt-private/private-search.h>
  43. #include <apt-private/private-main.h>
  44. #include <regex.h>
  45. #include <stddef.h>
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <unistd.h>
  49. #include <algorithm>
  50. #include <cstring>
  51. #include <iomanip>
  52. #include <iostream>
  53. #include <list>
  54. #include <map>
  55. #include <set>
  56. #include <string>
  57. #include <vector>
  58. #include <apti18n.h>
  59. /*}}}*/
  60. using namespace std;
  61. // UnMet - Show unmet dependencies /*{{{*/
  62. // ---------------------------------------------------------------------
  63. /* */
  64. static bool ShowUnMet(pkgCache::VerIterator const &V, bool const Important)
  65. {
  66. bool Header = false;
  67. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false;)
  68. {
  69. // Collect or groups
  70. pkgCache::DepIterator Start;
  71. pkgCache::DepIterator End;
  72. D.GlobOr(Start,End);
  73. // Important deps only
  74. if (Important == true)
  75. if (End->Type != pkgCache::Dep::PreDepends &&
  76. End->Type != pkgCache::Dep::Depends)
  77. continue;
  78. // Skip conflicts and replaces
  79. if (End.IsNegative() == true || End->Type == pkgCache::Dep::Replaces)
  80. continue;
  81. // Verify the or group
  82. bool OK = false;
  83. pkgCache::DepIterator RealStart = Start;
  84. do
  85. {
  86. // See if this dep is Ok
  87. pkgCache::Version **VList = Start.AllTargets();
  88. if (*VList != 0)
  89. {
  90. OK = true;
  91. delete [] VList;
  92. break;
  93. }
  94. delete [] VList;
  95. if (Start == End)
  96. break;
  97. ++Start;
  98. }
  99. while (1);
  100. // The group is OK
  101. if (OK == true)
  102. continue;
  103. // Oops, it failed..
  104. if (Header == false)
  105. ioprintf(cout,_("Package %s version %s has an unmet dep:\n"),
  106. V.ParentPkg().FullName(true).c_str(),V.VerStr());
  107. Header = true;
  108. // Print out the dep type
  109. cout << " " << End.DepType() << ": ";
  110. // Show the group
  111. Start = RealStart;
  112. do
  113. {
  114. cout << Start.TargetPkg().FullName(true);
  115. if (Start.TargetVer() != 0)
  116. cout << " (" << Start.CompType() << " " << Start.TargetVer() <<
  117. ")";
  118. if (Start == End)
  119. break;
  120. cout << " | ";
  121. ++Start;
  122. }
  123. while (1);
  124. cout << endl;
  125. }
  126. return true;
  127. }
  128. static bool UnMet(CommandLine &CmdL)
  129. {
  130. bool const Important = _config->FindB("APT::Cache::Important",false);
  131. pkgCacheFile CacheFile;
  132. if (unlikely(CacheFile.GetPkgCache() == NULL))
  133. return false;
  134. if (CmdL.FileSize() <= 1)
  135. {
  136. for (pkgCache::PkgIterator P = CacheFile.GetPkgCache()->PkgBegin(); P.end() == false; ++P)
  137. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V)
  138. if (ShowUnMet(V, Important) == false)
  139. return false;
  140. }
  141. else
  142. {
  143. CacheSetHelperVirtuals helper(true, GlobalError::NOTICE);
  144. APT::VersionList verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1,
  145. APT::CacheSetHelper::CANDIDATE, helper);
  146. for (APT::VersionList::iterator V = verset.begin(); V != verset.end(); ++V)
  147. if (ShowUnMet(V, Important) == false)
  148. return false;
  149. }
  150. return true;
  151. }
  152. /*}}}*/
  153. // DumpPackage - Show a dump of a package record /*{{{*/
  154. // ---------------------------------------------------------------------
  155. /* */
  156. static bool DumpPackage(CommandLine &CmdL)
  157. {
  158. pkgCacheFile CacheFile;
  159. APT::CacheSetHelper helper(true, GlobalError::NOTICE);
  160. APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1, helper);
  161. for (APT::PackageList::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg)
  162. {
  163. cout << "Package: " << Pkg.FullName(true) << endl;
  164. cout << "Versions: " << endl;
  165. for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; ++Cur)
  166. {
  167. cout << Cur.VerStr();
  168. for (pkgCache::VerFileIterator Vf = Cur.FileList(); Vf.end() == false; ++Vf)
  169. cout << " (" << Vf.File().FileName() << ")";
  170. cout << endl;
  171. for (pkgCache::DescIterator D = Cur.DescriptionList(); D.end() == false; ++D)
  172. {
  173. cout << " Description Language: " << D.LanguageCode() << endl
  174. << " File: " << D.FileList().File().FileName() << endl
  175. << " MD5: " << D.md5() << endl;
  176. }
  177. cout << endl;
  178. }
  179. cout << endl;
  180. cout << "Reverse Depends: " << endl;
  181. for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() != true; ++D)
  182. {
  183. cout << " " << D.ParentPkg().FullName(true) << ',' << D.TargetPkg().FullName(true);
  184. if (D->Version != 0)
  185. cout << ' ' << DeNull(D.TargetVer()) << endl;
  186. else
  187. cout << endl;
  188. }
  189. cout << "Dependencies: " << endl;
  190. for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; ++Cur)
  191. {
  192. cout << Cur.VerStr() << " - ";
  193. for (pkgCache::DepIterator Dep = Cur.DependsList(); Dep.end() != true; ++Dep)
  194. cout << Dep.TargetPkg().FullName(true) << " (" << (int)Dep->CompareOp << " " << DeNull(Dep.TargetVer()) << ") ";
  195. cout << endl;
  196. }
  197. cout << "Provides: " << endl;
  198. for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; ++Cur)
  199. {
  200. cout << Cur.VerStr() << " - ";
  201. for (pkgCache::PrvIterator Prv = Cur.ProvidesList(); Prv.end() != true; ++Prv)
  202. cout << Prv.ParentPkg().FullName(true) << " (= " << (Prv->ProvideVersion == 0 ? "" : Prv.ProvideVersion()) << ") ";
  203. cout << endl;
  204. }
  205. cout << "Reverse Provides: " << endl;
  206. for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; ++Prv)
  207. cout << Prv.OwnerPkg().FullName(true) << " " << Prv.OwnerVer().VerStr() << " (= " << (Prv->ProvideVersion == 0 ? "" : Prv.ProvideVersion()) << ")"<< endl;
  208. }
  209. return true;
  210. }
  211. /*}}}*/
  212. // ShowHashTableStats - Show stats about a hashtable /*{{{*/
  213. // ---------------------------------------------------------------------
  214. /* */
  215. static map_pointer_t PackageNext(pkgCache::Package const * const P) { return P->NextPackage; }
  216. static map_pointer_t GroupNext(pkgCache::Group const * const G) { return G->Next; }
  217. template<class T>
  218. static void ShowHashTableStats(std::string Type,
  219. T *StartP,
  220. map_pointer_t *Hashtable,
  221. unsigned long Size,
  222. map_pointer_t(*Next)(T const * const))
  223. {
  224. // hashtable stats for the HashTable
  225. unsigned long NumBuckets = Size;
  226. unsigned long UsedBuckets = 0;
  227. unsigned long UnusedBuckets = 0;
  228. unsigned long LongestBucket = 0;
  229. unsigned long ShortestBucket = NumBuckets;
  230. unsigned long Entries = 0;
  231. for (unsigned int i=0; i < NumBuckets; ++i)
  232. {
  233. T *P = StartP + Hashtable[i];
  234. if(P == 0 || P == StartP)
  235. {
  236. ++UnusedBuckets;
  237. continue;
  238. }
  239. ++UsedBuckets;
  240. unsigned long ThisBucketSize = 0;
  241. for (; P != StartP; P = StartP + Next(P))
  242. ++ThisBucketSize;
  243. Entries += ThisBucketSize;
  244. LongestBucket = std::max(ThisBucketSize, LongestBucket);
  245. ShortestBucket = std::min(ThisBucketSize, ShortestBucket);
  246. }
  247. cout << "Total buckets in " << Type << ": " << NumBuckets << std::endl;
  248. cout << " Unused: " << UnusedBuckets << std::endl;
  249. cout << " Used: " << UsedBuckets << std::endl;
  250. cout << " Average entries: " << Entries/(double)NumBuckets << std::endl;
  251. cout << " Longest: " << LongestBucket << std::endl;
  252. cout << " Shortest: " << ShortestBucket << std::endl;
  253. }
  254. /*}}}*/
  255. // Stats - Dump some nice statistics /*{{{*/
  256. // ---------------------------------------------------------------------
  257. /* */
  258. static bool Stats(CommandLine &CmdL)
  259. {
  260. if (CmdL.FileSize() > 1) {
  261. _error->Error(_("apt-cache stats does not take any arguments"));
  262. return false;
  263. }
  264. pkgCacheFile CacheFile;
  265. pkgCache *Cache = CacheFile.GetPkgCache();
  266. if (unlikely(Cache == NULL))
  267. return false;
  268. cout << _("Total package names: ") << Cache->Head().GroupCount << " (" <<
  269. SizeToStr(Cache->Head().GroupCount*Cache->Head().GroupSz) << ')' << endl
  270. << _("Total package structures: ") << Cache->Head().PackageCount << " (" <<
  271. SizeToStr(Cache->Head().PackageCount*Cache->Head().PackageSz) << ')' << endl;
  272. int Normal = 0;
  273. int Virtual = 0;
  274. int NVirt = 0;
  275. int DVirt = 0;
  276. int Missing = 0;
  277. pkgCache::PkgIterator I = Cache->PkgBegin();
  278. for (;I.end() != true; ++I)
  279. {
  280. if (I->VersionList != 0 && I->ProvidesList == 0)
  281. {
  282. Normal++;
  283. continue;
  284. }
  285. if (I->VersionList != 0 && I->ProvidesList != 0)
  286. {
  287. NVirt++;
  288. continue;
  289. }
  290. if (I->VersionList == 0 && I->ProvidesList != 0)
  291. {
  292. // Only 1 provides
  293. if (I.ProvidesList()->NextProvides == 0)
  294. {
  295. DVirt++;
  296. }
  297. else
  298. Virtual++;
  299. continue;
  300. }
  301. if (I->VersionList == 0 && I->ProvidesList == 0)
  302. {
  303. Missing++;
  304. continue;
  305. }
  306. }
  307. cout << _(" Normal packages: ") << Normal << endl;
  308. cout << _(" Pure virtual packages: ") << Virtual << endl;
  309. cout << _(" Single virtual packages: ") << DVirt << endl;
  310. cout << _(" Mixed virtual packages: ") << NVirt << endl;
  311. cout << _(" Missing: ") << Missing << endl;
  312. cout << _("Total distinct versions: ") << Cache->Head().VersionCount << " (" <<
  313. SizeToStr(Cache->Head().VersionCount*Cache->Head().VersionSz) << ')' << endl;
  314. cout << _("Total distinct descriptions: ") << Cache->Head().DescriptionCount << " (" <<
  315. SizeToStr(Cache->Head().DescriptionCount*Cache->Head().DescriptionSz) << ')' << endl;
  316. cout << _("Total dependencies: ") << Cache->Head().DependsCount << "/" << Cache->Head().DependsDataCount << " (" <<
  317. SizeToStr((Cache->Head().DependsCount*Cache->Head().DependencySz) +
  318. (Cache->Head().DependsDataCount*Cache->Head().DependencyDataSz)) << ')' << endl;
  319. cout << _("Total ver/file relations: ") << Cache->Head().VerFileCount << " (" <<
  320. SizeToStr(Cache->Head().VerFileCount*Cache->Head().VerFileSz) << ')' << endl;
  321. cout << _("Total Desc/File relations: ") << Cache->Head().DescFileCount << " (" <<
  322. SizeToStr(Cache->Head().DescFileCount*Cache->Head().DescFileSz) << ')' << endl;
  323. cout << _("Total Provides mappings: ") << Cache->Head().ProvidesCount << " (" <<
  324. SizeToStr(Cache->Head().ProvidesCount*Cache->Head().ProvidesSz) << ')' << endl;
  325. // String list stats
  326. std::set<map_stringitem_t> stritems;
  327. for (pkgCache::GrpIterator G = Cache->GrpBegin(); G.end() == false; ++G)
  328. stritems.insert(G->Name);
  329. for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
  330. {
  331. stritems.insert(P->Arch);
  332. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V)
  333. {
  334. if (V->VerStr != 0)
  335. stritems.insert(V->VerStr);
  336. if (V->Section != 0)
  337. stritems.insert(V->Section);
  338. stritems.insert(V->SourcePkgName);
  339. stritems.insert(V->SourceVerStr);
  340. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; ++D)
  341. {
  342. if (D->Version != 0)
  343. stritems.insert(D->Version);
  344. }
  345. for (pkgCache::DescIterator D = V.DescriptionList(); D.end() == false; ++D)
  346. {
  347. stritems.insert(D->md5sum);
  348. stritems.insert(D->language_code);
  349. }
  350. }
  351. for (pkgCache::PrvIterator Prv = P.ProvidesList(); Prv.end() == false; ++Prv)
  352. {
  353. if (Prv->ProvideVersion != 0)
  354. stritems.insert(Prv->ProvideVersion);
  355. }
  356. }
  357. for (pkgCache::RlsFileIterator F = Cache->RlsFileBegin(); F != Cache->RlsFileEnd(); ++F)
  358. {
  359. stritems.insert(F->FileName);
  360. stritems.insert(F->Archive);
  361. stritems.insert(F->Codename);
  362. stritems.insert(F->Version);
  363. stritems.insert(F->Origin);
  364. stritems.insert(F->Label);
  365. stritems.insert(F->Site);
  366. }
  367. for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); ++F)
  368. {
  369. stritems.insert(F->FileName);
  370. stritems.insert(F->Architecture);
  371. stritems.insert(F->Component);
  372. stritems.insert(F->IndexType);
  373. }
  374. unsigned long Size = 0;
  375. for (std::set<map_stringitem_t>::const_iterator i = stritems.begin(); i != stritems.end(); ++i)
  376. Size += strlen(Cache->StrP + *i) + 1;
  377. cout << _("Total globbed strings: ") << stritems.size() << " (" << SizeToStr(Size) << ')' << endl;
  378. stritems.clear();
  379. unsigned long Slack = 0;
  380. for (int I = 0; I != 7; I++)
  381. Slack += Cache->Head().Pools[I].ItemSize*Cache->Head().Pools[I].Count;
  382. cout << _("Total slack space: ") << SizeToStr(Slack) << endl;
  383. unsigned long Total = 0;
  384. #define APT_CACHESIZE(X,Y) (Cache->Head().X * Cache->Head().Y)
  385. Total = Slack + Size +
  386. APT_CACHESIZE(GroupCount, GroupSz) +
  387. APT_CACHESIZE(PackageCount, PackageSz) +
  388. APT_CACHESIZE(VersionCount, VersionSz) +
  389. APT_CACHESIZE(DescriptionCount, DescriptionSz) +
  390. APT_CACHESIZE(DependsCount, DependencySz) +
  391. APT_CACHESIZE(DependsDataCount, DependencyDataSz) +
  392. APT_CACHESIZE(ReleaseFileCount, ReleaseFileSz) +
  393. APT_CACHESIZE(PackageFileCount, PackageFileSz) +
  394. APT_CACHESIZE(VerFileCount, VerFileSz) +
  395. APT_CACHESIZE(DescFileCount, DescFileSz) +
  396. APT_CACHESIZE(ProvidesCount, ProvidesSz) +
  397. (2 * Cache->Head().GetHashTableSize() * sizeof(map_id_t));
  398. cout << _("Total space accounted for: ") << SizeToStr(Total) << endl;
  399. #undef APT_CACHESIZE
  400. // hashtable stats
  401. ShowHashTableStats<pkgCache::Package>("PkgHashTable", Cache->PkgP, Cache->Head().PkgHashTableP(), Cache->Head().GetHashTableSize(), PackageNext);
  402. ShowHashTableStats<pkgCache::Group>("GrpHashTable", Cache->GrpP, Cache->Head().GrpHashTableP(), Cache->Head().GetHashTableSize(), GroupNext);
  403. return true;
  404. }
  405. /*}}}*/
  406. // Dump - show everything /*{{{*/
  407. // ---------------------------------------------------------------------
  408. /* This is worthless except fer debugging things */
  409. static bool Dump(CommandLine &)
  410. {
  411. pkgCacheFile CacheFile;
  412. pkgCache *Cache = CacheFile.GetPkgCache();
  413. if (unlikely(Cache == NULL))
  414. return false;
  415. std::cout << "Using Versioning System: " << Cache->VS->Label << std::endl;
  416. for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
  417. {
  418. std::cout << "Package: " << P.FullName(true) << std::endl;
  419. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V)
  420. {
  421. std::cout << " Version: " << V.VerStr() << std::endl;
  422. std::cout << " File: " << V.FileList().File().FileName() << std::endl;
  423. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; ++D)
  424. std::cout << " Depends: " << D.TargetPkg().FullName(true) << ' ' <<
  425. DeNull(D.TargetVer()) << std::endl;
  426. for (pkgCache::DescIterator D = V.DescriptionList(); D.end() == false; ++D)
  427. {
  428. std::cout << " Description Language: " << D.LanguageCode() << std::endl
  429. << " File: " << D.FileList().File().FileName() << std::endl
  430. << " MD5: " << D.md5() << std::endl;
  431. }
  432. }
  433. }
  434. for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F.end() == false; ++F)
  435. {
  436. std::cout << "File: " << F.FileName() << std::endl;
  437. std::cout << " Type: " << F.IndexType() << std::endl;
  438. std::cout << " Size: " << F->Size << std::endl;
  439. std::cout << " ID: " << F->ID << std::endl;
  440. std::cout << " Flags: " << F->Flags << std::endl;
  441. std::cout << " Time: " << TimeRFC1123(F->mtime) << std::endl;
  442. std::cout << " Archive: " << DeNull(F.Archive()) << std::endl;
  443. std::cout << " Component: " << DeNull(F.Component()) << std::endl;
  444. std::cout << " Version: " << DeNull(F.Version()) << std::endl;
  445. std::cout << " Origin: " << DeNull(F.Origin()) << std::endl;
  446. std::cout << " Site: " << DeNull(F.Site()) << std::endl;
  447. std::cout << " Label: " << DeNull(F.Label()) << std::endl;
  448. std::cout << " Architecture: " << DeNull(F.Architecture()) << std::endl;
  449. }
  450. return true;
  451. }
  452. /*}}}*/
  453. // DumpAvail - Print out the available list /*{{{*/
  454. // ---------------------------------------------------------------------
  455. /* This is needed to make dpkg --merge happy.. I spent a bit of time to
  456. make this run really fast, perhaps I went a little overboard.. */
  457. static bool DumpAvail(CommandLine &)
  458. {
  459. pkgCacheFile CacheFile;
  460. pkgCache *Cache = CacheFile.GetPkgCache();
  461. if (unlikely(Cache == NULL || CacheFile.BuildPolicy() == false))
  462. return false;
  463. unsigned long Count = Cache->HeaderP->PackageCount+1;
  464. pkgCache::VerFile **VFList = new pkgCache::VerFile *[Count];
  465. memset(VFList,0,sizeof(*VFList)*Count);
  466. // Map versions that we want to write out onto the VerList array.
  467. for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
  468. {
  469. if (P->VersionList == 0)
  470. continue;
  471. /* Find the proper version to use. If the policy says there are no
  472. possible selections we return the installed version, if available..
  473. This prevents dselect from making it obsolete. */
  474. pkgCache::VerIterator V = CacheFile.GetPolicy()->GetCandidateVer(P);
  475. if (V.end() == true)
  476. {
  477. if (P->CurrentVer == 0)
  478. continue;
  479. V = P.CurrentVer();
  480. }
  481. pkgCache::VerFileIterator VF = V.FileList();
  482. for (; VF.end() == false ; ++VF)
  483. if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0)
  484. break;
  485. /* Okay, here we have a bit of a problem.. The policy has selected the
  486. currently installed package - however it only exists in the
  487. status file.. We need to write out something or dselect will mark
  488. the package as obsolete! Thus we emit the status file entry, but
  489. below we remove the status line to make it valid for the
  490. available file. However! We only do this if their do exist *any*
  491. non-source versions of the package - that way the dselect obsolete
  492. handling works OK. */
  493. if (VF.end() == true)
  494. {
  495. for (pkgCache::VerIterator Cur = P.VersionList(); Cur.end() != true; ++Cur)
  496. {
  497. for (VF = Cur.FileList(); VF.end() == false; ++VF)
  498. {
  499. if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0)
  500. {
  501. VF = V.FileList();
  502. break;
  503. }
  504. }
  505. if (VF.end() == false)
  506. break;
  507. }
  508. }
  509. VFList[P->ID] = VF;
  510. }
  511. LocalitySort(VFList,Count,sizeof(*VFList));
  512. std::vector<pkgTagSection::Tag> RW;
  513. RW.push_back(pkgTagSection::Tag::Remove("Status"));
  514. RW.push_back(pkgTagSection::Tag::Remove("Config-Version"));
  515. FileFd stdoutfd;
  516. stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false);
  517. // Iterate over all the package files and write them out.
  518. char *Buffer = new char[Cache->HeaderP->MaxVerFileSize+10];
  519. for (pkgCache::VerFile **J = VFList; *J != 0;)
  520. {
  521. pkgCache::PkgFileIterator File(*Cache,(*J)->File + Cache->PkgFileP);
  522. if (File.IsOk() == false)
  523. {
  524. _error->Error(_("Package file %s is out of sync."),File.FileName());
  525. break;
  526. }
  527. FileFd PkgF(File.FileName(),FileFd::ReadOnly, FileFd::Extension);
  528. if (_error->PendingError() == true)
  529. break;
  530. /* Write all of the records from this package file, since we
  531. already did locality sorting we can now just seek through the
  532. file in read order. We apply 1 more optimization here, since often
  533. there will be < 1 byte gaps between records (for the \n) we read that
  534. into the next buffer and offset a bit.. */
  535. unsigned long Pos = 0;
  536. for (; *J != 0; J++)
  537. {
  538. if ((*J)->File + Cache->PkgFileP != File)
  539. break;
  540. const pkgCache::VerFile &VF = **J;
  541. // Read the record and then write it out again.
  542. unsigned long Jitter = VF.Offset - Pos;
  543. if (Jitter > 8)
  544. {
  545. if (PkgF.Seek(VF.Offset) == false)
  546. break;
  547. Jitter = 0;
  548. }
  549. if (PkgF.Read(Buffer,VF.Size + Jitter) == false)
  550. break;
  551. Buffer[VF.Size + Jitter] = '\n';
  552. // See above..
  553. if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource)
  554. {
  555. pkgTagSection Tags;
  556. if (Tags.Scan(Buffer+Jitter,VF.Size+1) == false ||
  557. Tags.Write(stdoutfd, NULL, RW) == false ||
  558. stdoutfd.Write("\n", 1) == false)
  559. {
  560. _error->Error("Internal Error, Unable to parse a package record");
  561. break;
  562. }
  563. }
  564. else
  565. {
  566. if (stdoutfd.Write(Buffer + Jitter, VF.Size + 1) == false)
  567. break;
  568. }
  569. Pos = VF.Offset + VF.Size;
  570. }
  571. if (_error->PendingError() == true)
  572. break;
  573. }
  574. delete [] Buffer;
  575. delete [] VFList;
  576. return !_error->PendingError();
  577. }
  578. /*}}}*/
  579. // xvcg - Generate a graph for xvcg /*{{{*/
  580. // ---------------------------------------------------------------------
  581. // Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
  582. static bool XVcg(CommandLine &CmdL)
  583. {
  584. pkgCacheFile CacheFile;
  585. pkgCache *Cache = CacheFile.GetPkgCache();
  586. if (unlikely(Cache == NULL))
  587. return false;
  588. bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false);
  589. /* Normal packages are boxes
  590. Pure Provides are triangles
  591. Mixed are diamonds
  592. rhomb are missing packages*/
  593. const char *Shapes[] = {"ellipse","triangle","box","rhomb"};
  594. /* Initialize the list of packages to show.
  595. 1 = To Show
  596. 2 = To Show no recurse
  597. 3 = Emitted no recurse
  598. 4 = Emitted
  599. 0 = None */
  600. enum States {None=0, ToShow, ToShowNR, DoneNR, Done};
  601. enum TheFlags {ForceNR=(1<<0)};
  602. unsigned char *Show = new unsigned char[Cache->Head().PackageCount];
  603. unsigned char *Flags = new unsigned char[Cache->Head().PackageCount];
  604. unsigned char *ShapeMap = new unsigned char[Cache->Head().PackageCount];
  605. // Show everything if no arguments given
  606. if (CmdL.FileList[1] == 0)
  607. for (unsigned long I = 0; I != Cache->Head().PackageCount; I++)
  608. Show[I] = ToShow;
  609. else
  610. for (unsigned long I = 0; I != Cache->Head().PackageCount; I++)
  611. Show[I] = None;
  612. memset(Flags,0,sizeof(*Flags)*Cache->Head().PackageCount);
  613. // Map the shapes
  614. for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg)
  615. {
  616. if (Pkg->VersionList == 0)
  617. {
  618. // Missing
  619. if (Pkg->ProvidesList == 0)
  620. ShapeMap[Pkg->ID] = 0;
  621. else
  622. ShapeMap[Pkg->ID] = 1;
  623. }
  624. else
  625. {
  626. // Normal
  627. if (Pkg->ProvidesList == 0)
  628. ShapeMap[Pkg->ID] = 2;
  629. else
  630. ShapeMap[Pkg->ID] = 3;
  631. }
  632. }
  633. // Load the list of packages from the command line into the show list
  634. APT::CacheSetHelper helper(true, GlobalError::NOTICE);
  635. std::list<APT::CacheSetHelper::PkgModifier> mods;
  636. mods.push_back(APT::CacheSetHelper::PkgModifier(0, ",", APT::PackageSet::Modifier::POSTFIX));
  637. mods.push_back(APT::CacheSetHelper::PkgModifier(1, "^", APT::PackageSet::Modifier::POSTFIX));
  638. std::map<unsigned short, APT::PackageSet> pkgsets =
  639. APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0, helper);
  640. for (APT::PackageSet::const_iterator Pkg = pkgsets[0].begin();
  641. Pkg != pkgsets[0].end(); ++Pkg)
  642. Show[Pkg->ID] = ToShow;
  643. for (APT::PackageSet::const_iterator Pkg = pkgsets[1].begin();
  644. Pkg != pkgsets[1].end(); ++Pkg)
  645. {
  646. Show[Pkg->ID] = ToShow;
  647. Flags[Pkg->ID] |= ForceNR;
  648. }
  649. // Little header
  650. cout << "graph: { title: \"packages\"" << endl <<
  651. "xmax: 700 ymax: 700 x: 30 y: 30" << endl <<
  652. "layout_downfactor: 8" << endl;
  653. bool Act = true;
  654. while (Act == true)
  655. {
  656. Act = false;
  657. for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg)
  658. {
  659. // See we need to show this package
  660. if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR)
  661. continue;
  662. //printf ("node: { title: \"%s\" label: \"%s\" }\n", Pkg.Name(), Pkg.Name());
  663. // Colour as done
  664. if (Show[Pkg->ID] == ToShowNR || (Flags[Pkg->ID] & ForceNR) == ForceNR)
  665. {
  666. // Pure Provides and missing packages have no deps!
  667. if (ShapeMap[Pkg->ID] == 0 || ShapeMap[Pkg->ID] == 1)
  668. Show[Pkg->ID] = Done;
  669. else
  670. Show[Pkg->ID] = DoneNR;
  671. }
  672. else
  673. Show[Pkg->ID] = Done;
  674. Act = true;
  675. // No deps to map out
  676. if (Pkg->VersionList == 0 || Show[Pkg->ID] == DoneNR)
  677. continue;
  678. pkgCache::VerIterator Ver = Pkg.VersionList();
  679. for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; ++D)
  680. {
  681. // See if anything can meet this dep
  682. // Walk along the actual package providing versions
  683. bool Hit = false;
  684. pkgCache::PkgIterator DPkg = D.TargetPkg();
  685. for (pkgCache::VerIterator I = DPkg.VersionList();
  686. I.end() == false && Hit == false; ++I)
  687. {
  688. if (Cache->VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true)
  689. Hit = true;
  690. }
  691. // Follow all provides
  692. for (pkgCache::PrvIterator I = DPkg.ProvidesList();
  693. I.end() == false && Hit == false; ++I)
  694. {
  695. if (Cache->VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false)
  696. Hit = true;
  697. }
  698. // Only graph critical deps
  699. if (D.IsCritical() == true)
  700. {
  701. printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg.FullName(true).c_str(), D.TargetPkg().FullName(true).c_str() );
  702. // Colour the node for recursion
  703. if (Show[D.TargetPkg()->ID] <= DoneNR)
  704. {
  705. /* If a conflicts does not meet anything in the database
  706. then show the relation but do not recurse */
  707. if (Hit == false && D.IsNegative() == true)
  708. {
  709. if (Show[D.TargetPkg()->ID] == None &&
  710. Show[D.TargetPkg()->ID] != ToShow)
  711. Show[D.TargetPkg()->ID] = ToShowNR;
  712. }
  713. else
  714. {
  715. if (GivenOnly == true && Show[D.TargetPkg()->ID] != ToShow)
  716. Show[D.TargetPkg()->ID] = ToShowNR;
  717. else
  718. Show[D.TargetPkg()->ID] = ToShow;
  719. }
  720. }
  721. // Edge colour
  722. switch(D->Type)
  723. {
  724. case pkgCache::Dep::Conflicts:
  725. printf("label: \"conflicts\" color: lightgreen }\n");
  726. break;
  727. case pkgCache::Dep::DpkgBreaks:
  728. printf("label: \"breaks\" color: lightgreen }\n");
  729. break;
  730. case pkgCache::Dep::Obsoletes:
  731. printf("label: \"obsoletes\" color: lightgreen }\n");
  732. break;
  733. case pkgCache::Dep::PreDepends:
  734. printf("label: \"predepends\" color: blue }\n");
  735. break;
  736. default:
  737. printf("}\n");
  738. break;
  739. }
  740. }
  741. }
  742. }
  743. }
  744. /* Draw the box colours after the fact since we can not tell what colour
  745. they should be until everything is finished drawing */
  746. for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg)
  747. {
  748. if (Show[Pkg->ID] < DoneNR)
  749. continue;
  750. if (Show[Pkg->ID] == DoneNR)
  751. printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg.FullName(true).c_str(), Pkg.FullName(true).c_str(),
  752. Shapes[ShapeMap[Pkg->ID]]);
  753. else
  754. printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg.FullName(true).c_str(), Pkg.FullName(true).c_str(),
  755. Shapes[ShapeMap[Pkg->ID]]);
  756. }
  757. delete[] Show;
  758. delete[] Flags;
  759. delete[] ShapeMap;
  760. printf("}\n");
  761. return true;
  762. }
  763. /*}}}*/
  764. // Dotty - Generate a graph for Dotty /*{{{*/
  765. // ---------------------------------------------------------------------
  766. /* Dotty is the graphvis program for generating graphs. It is a fairly
  767. simple queuing algorithm that just writes dependencies and nodes.
  768. http://www.research.att.com/sw/tools/graphviz/ */
  769. static bool Dotty(CommandLine &CmdL)
  770. {
  771. pkgCacheFile CacheFile;
  772. pkgCache *Cache = CacheFile.GetPkgCache();
  773. if (unlikely(Cache == NULL))
  774. return false;
  775. bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false);
  776. /* Normal packages are boxes
  777. Pure Provides are triangles
  778. Mixed are diamonds
  779. Hexagons are missing packages*/
  780. const char *Shapes[] = {"hexagon","triangle","box","diamond"};
  781. /* Initialize the list of packages to show.
  782. 1 = To Show
  783. 2 = To Show no recurse
  784. 3 = Emitted no recurse
  785. 4 = Emitted
  786. 0 = None */
  787. enum States {None=0, ToShow, ToShowNR, DoneNR, Done};
  788. enum TheFlags {ForceNR=(1<<0)};
  789. unsigned char *Show = new unsigned char[Cache->Head().PackageCount];
  790. unsigned char *Flags = new unsigned char[Cache->Head().PackageCount];
  791. unsigned char *ShapeMap = new unsigned char[Cache->Head().PackageCount];
  792. // Show everything if no arguments given
  793. if (CmdL.FileList[1] == 0)
  794. for (unsigned long I = 0; I != Cache->Head().PackageCount; I++)
  795. Show[I] = ToShow;
  796. else
  797. for (unsigned long I = 0; I != Cache->Head().PackageCount; I++)
  798. Show[I] = None;
  799. memset(Flags,0,sizeof(*Flags)*Cache->Head().PackageCount);
  800. // Map the shapes
  801. for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg)
  802. {
  803. if (Pkg->VersionList == 0)
  804. {
  805. // Missing
  806. if (Pkg->ProvidesList == 0)
  807. ShapeMap[Pkg->ID] = 0;
  808. else
  809. ShapeMap[Pkg->ID] = 1;
  810. }
  811. else
  812. {
  813. // Normal
  814. if (Pkg->ProvidesList == 0)
  815. ShapeMap[Pkg->ID] = 2;
  816. else
  817. ShapeMap[Pkg->ID] = 3;
  818. }
  819. }
  820. // Load the list of packages from the command line into the show list
  821. APT::CacheSetHelper helper(true, GlobalError::NOTICE);
  822. std::list<APT::CacheSetHelper::PkgModifier> mods;
  823. mods.push_back(APT::CacheSetHelper::PkgModifier(0, ",", APT::PackageSet::Modifier::POSTFIX));
  824. mods.push_back(APT::CacheSetHelper::PkgModifier(1, "^", APT::PackageSet::Modifier::POSTFIX));
  825. std::map<unsigned short, APT::PackageSet> pkgsets =
  826. APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0, helper);
  827. for (APT::PackageSet::const_iterator Pkg = pkgsets[0].begin();
  828. Pkg != pkgsets[0].end(); ++Pkg)
  829. Show[Pkg->ID] = ToShow;
  830. for (APT::PackageSet::const_iterator Pkg = pkgsets[1].begin();
  831. Pkg != pkgsets[1].end(); ++Pkg)
  832. {
  833. Show[Pkg->ID] = ToShow;
  834. Flags[Pkg->ID] |= ForceNR;
  835. }
  836. // Little header
  837. printf("digraph packages {\n");
  838. printf("concentrate=true;\n");
  839. printf("size=\"30,40\";\n");
  840. bool Act = true;
  841. while (Act == true)
  842. {
  843. Act = false;
  844. for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg)
  845. {
  846. // See we need to show this package
  847. if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR)
  848. continue;
  849. // Colour as done
  850. if (Show[Pkg->ID] == ToShowNR || (Flags[Pkg->ID] & ForceNR) == ForceNR)
  851. {
  852. // Pure Provides and missing packages have no deps!
  853. if (ShapeMap[Pkg->ID] == 0 || ShapeMap[Pkg->ID] == 1)
  854. Show[Pkg->ID] = Done;
  855. else
  856. Show[Pkg->ID] = DoneNR;
  857. }
  858. else
  859. Show[Pkg->ID] = Done;
  860. Act = true;
  861. // No deps to map out
  862. if (Pkg->VersionList == 0 || Show[Pkg->ID] == DoneNR)
  863. continue;
  864. pkgCache::VerIterator Ver = Pkg.VersionList();
  865. for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; ++D)
  866. {
  867. // See if anything can meet this dep
  868. // Walk along the actual package providing versions
  869. bool Hit = false;
  870. pkgCache::PkgIterator DPkg = D.TargetPkg();
  871. for (pkgCache::VerIterator I = DPkg.VersionList();
  872. I.end() == false && Hit == false; ++I)
  873. {
  874. if (Cache->VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true)
  875. Hit = true;
  876. }
  877. // Follow all provides
  878. for (pkgCache::PrvIterator I = DPkg.ProvidesList();
  879. I.end() == false && Hit == false; ++I)
  880. {
  881. if (Cache->VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false)
  882. Hit = true;
  883. }
  884. // Only graph critical deps
  885. if (D.IsCritical() == true)
  886. {
  887. printf("\"%s\" -> \"%s\"",Pkg.FullName(true).c_str(),D.TargetPkg().FullName(true).c_str());
  888. // Colour the node for recursion
  889. if (Show[D.TargetPkg()->ID] <= DoneNR)
  890. {
  891. /* If a conflicts does not meet anything in the database
  892. then show the relation but do not recurse */
  893. if (Hit == false && D.IsNegative() == true)
  894. {
  895. if (Show[D.TargetPkg()->ID] == None &&
  896. Show[D.TargetPkg()->ID] != ToShow)
  897. Show[D.TargetPkg()->ID] = ToShowNR;
  898. }
  899. else
  900. {
  901. if (GivenOnly == true && Show[D.TargetPkg()->ID] != ToShow)
  902. Show[D.TargetPkg()->ID] = ToShowNR;
  903. else
  904. Show[D.TargetPkg()->ID] = ToShow;
  905. }
  906. }
  907. // Edge colour
  908. switch(D->Type)
  909. {
  910. case pkgCache::Dep::Conflicts:
  911. case pkgCache::Dep::Obsoletes:
  912. case pkgCache::Dep::DpkgBreaks:
  913. printf("[color=springgreen];\n");
  914. break;
  915. case pkgCache::Dep::PreDepends:
  916. printf("[color=blue];\n");
  917. break;
  918. default:
  919. printf(";\n");
  920. break;
  921. }
  922. }
  923. }
  924. }
  925. }
  926. /* Draw the box colours after the fact since we can not tell what colour
  927. they should be until everything is finished drawing */
  928. for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg)
  929. {
  930. if (Show[Pkg->ID] < DoneNR)
  931. continue;
  932. // Orange box for early recursion stoppage
  933. if (Show[Pkg->ID] == DoneNR)
  934. printf("\"%s\" [color=orange,shape=%s];\n",Pkg.FullName(true).c_str(),
  935. Shapes[ShapeMap[Pkg->ID]]);
  936. else
  937. printf("\"%s\" [shape=%s];\n",Pkg.FullName(true).c_str(),
  938. Shapes[ShapeMap[Pkg->ID]]);
  939. }
  940. printf("}\n");
  941. delete[] Show;
  942. delete[] Flags;
  943. delete[] ShapeMap;
  944. return true;
  945. }
  946. /*}}}*/
  947. /* ShowAuto - show automatically installed packages (sorted) {{{*/
  948. static bool ShowAuto(CommandLine &)
  949. {
  950. pkgCacheFile CacheFile;
  951. pkgCache *Cache = CacheFile.GetPkgCache();
  952. pkgDepCache *DepCache = CacheFile.GetDepCache();
  953. if (unlikely(Cache == NULL || DepCache == NULL))
  954. return false;
  955. std::vector<string> packages;
  956. packages.reserve(Cache->HeaderP->PackageCount / 3);
  957. for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
  958. if ((*DepCache)[P].Flags & pkgCache::Flag::Auto)
  959. packages.push_back(P.Name());
  960. std::sort(packages.begin(), packages.end());
  961. for (vector<string>::iterator I = packages.begin(); I != packages.end(); ++I)
  962. cout << *I << "\n";
  963. _error->Notice(_("This command is deprecated. Please use 'apt-mark showauto' instead."));
  964. return true;
  965. }
  966. /*}}}*/
  967. // ShowPkgNames - Show package names /*{{{*/
  968. // ---------------------------------------------------------------------
  969. /* This does a prefix match on the first argument */
  970. static bool ShowPkgNames(CommandLine &CmdL)
  971. {
  972. pkgCacheFile CacheFile;
  973. if (unlikely(CacheFile.BuildCaches(NULL, false) == false))
  974. return false;
  975. pkgCache::GrpIterator I = CacheFile.GetPkgCache()->GrpBegin();
  976. bool const All = _config->FindB("APT::Cache::AllNames","false");
  977. if (CmdL.FileList[1] != 0)
  978. {
  979. for (;I.end() != true; ++I)
  980. {
  981. if (All == false && I->FirstPackage == 0)
  982. continue;
  983. if (I.FindPkg("any")->VersionList == 0)
  984. continue;
  985. if (strncmp(I.Name(),CmdL.FileList[1],strlen(CmdL.FileList[1])) == 0)
  986. cout << I.Name() << endl;
  987. }
  988. return true;
  989. }
  990. // Show all pkgs
  991. for (;I.end() != true; ++I)
  992. {
  993. if (All == false && I->FirstPackage == 0)
  994. continue;
  995. if (I.FindPkg("any")->VersionList == 0)
  996. continue;
  997. cout << I.Name() << endl;
  998. }
  999. return true;
  1000. }
  1001. /*}}}*/
  1002. // Madison - Look a bit like katie's madison /*{{{*/
  1003. // ---------------------------------------------------------------------
  1004. /* */
  1005. static bool Madison(CommandLine &CmdL)
  1006. {
  1007. pkgCacheFile CacheFile;
  1008. pkgSourceList *SrcList = CacheFile.GetSourceList();
  1009. if (SrcList == 0)
  1010. return false;
  1011. // Create the src text record parsers and ignore errors about missing
  1012. // deb-src lines that are generated from pkgSrcRecords::pkgSrcRecords
  1013. pkgSrcRecords SrcRecs(*SrcList);
  1014. if (_error->PendingError() == true)
  1015. _error->Discard();
  1016. APT::CacheSetHelper helper(true, GlobalError::NOTICE);
  1017. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  1018. {
  1019. _error->PushToStack();
  1020. APT::PackageList pkgset = APT::PackageList::FromString(CacheFile, *I, helper);
  1021. for (APT::PackageList::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg)
  1022. {
  1023. for (pkgCache::VerIterator V = Pkg.VersionList(); V.end() == false; ++V)
  1024. {
  1025. for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; ++VF)
  1026. {
  1027. // This might be nice, but wouldn't uniquely identify the source -mdz
  1028. // if (VF.File().Archive() != 0)
  1029. // {
  1030. // cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
  1031. // << VF.File().Archive() << endl;
  1032. // }
  1033. // Locate the associated index files so we can derive a description
  1034. for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); ++S)
  1035. {
  1036. vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles();
  1037. for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin();
  1038. IF != Indexes->end(); ++IF)
  1039. {
  1040. if ((*IF)->FindInCache(*(VF.File().Cache())) == VF.File())
  1041. {
  1042. cout << setw(10) << Pkg.FullName(true) << " | " << setw(10) << V.VerStr() << " | "
  1043. << (*IF)->Describe(true) << endl;
  1044. }
  1045. }
  1046. }
  1047. }
  1048. }
  1049. }
  1050. SrcRecs.Restart();
  1051. pkgSrcRecords::Parser *SrcParser;
  1052. bool foundSomething = false;
  1053. while ((SrcParser = SrcRecs.Find(*I, false)) != 0)
  1054. {
  1055. foundSomething = true;
  1056. // Maybe support Release info here too eventually
  1057. cout << setw(10) << SrcParser->Package() << " | "
  1058. << setw(10) << SrcParser->Version() << " | "
  1059. << SrcParser->Index().Describe(true) << endl;
  1060. }
  1061. if (foundSomething == true)
  1062. _error->RevertToStack();
  1063. else
  1064. _error->MergeWithStack();
  1065. }
  1066. return true;
  1067. }
  1068. /*}}}*/
  1069. // GenCaches - Call the main cache generator /*{{{*/
  1070. // ---------------------------------------------------------------------
  1071. /* */
  1072. static bool GenCaches(CommandLine &)
  1073. {
  1074. OpTextProgress Progress(*_config);
  1075. pkgCacheFile CacheFile;
  1076. return CacheFile.BuildCaches(&Progress, true);
  1077. }
  1078. /*}}}*/
  1079. bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds) /*{{{*/
  1080. {
  1081. std::cout <<
  1082. _("Usage: apt-cache [options] command\n"
  1083. " apt-cache [options] show pkg1 [pkg2 ...]\n"
  1084. "\n"
  1085. "apt-cache is a low-level tool used to query information\n"
  1086. "from APT's binary cache files\n")
  1087. << std::endl;
  1088. ShowHelpListCommands(Cmds);
  1089. std::cout << std::endl
  1090. << _("Options:\n"
  1091. " -h This help text.\n"
  1092. " -p=? The package cache.\n"
  1093. " -s=? The source cache.\n"
  1094. " -q Disable progress indicator.\n"
  1095. " -i Show only important deps for the unmet command.\n"
  1096. " -c=? Read this configuration file\n"
  1097. " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
  1098. "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n");
  1099. return true;
  1100. }
  1101. /*}}}*/
  1102. std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/
  1103. {
  1104. return {
  1105. {"gencaches",&GenCaches, nullptr},
  1106. {"showsrc",&ShowSrcPackage, _("Show source records")},
  1107. {"showpkg",&DumpPackage, nullptr},
  1108. {"stats",&Stats, nullptr},
  1109. {"dump",&Dump, nullptr},
  1110. {"dumpavail",&DumpAvail, nullptr},
  1111. {"unmet",&UnMet, nullptr},
  1112. {"search",&DoSearch, _("Search the package list for a regex pattern")},
  1113. {"depends",&Depends, _("Show raw dependency information for a package")},
  1114. {"rdepends",&RDepends, _("Show reverse dependency information for a package")},
  1115. {"dotty",&Dotty, nullptr},
  1116. {"xvcg",&XVcg, nullptr},
  1117. {"show",&ShowPackage, _("Show a readable record for the package")},
  1118. {"pkgnames",&ShowPkgNames, _("List the names of all packages in the system")},
  1119. {"showauto",&ShowAuto, nullptr},
  1120. {"policy",&Policy, _("Show policy settings")},
  1121. {"madison",&Madison, nullptr},
  1122. {nullptr, nullptr, nullptr}
  1123. };
  1124. }
  1125. /*}}}*/
  1126. int main(int argc,const char *argv[]) /*{{{*/
  1127. {
  1128. InitLocale();
  1129. // Parse the command line and initialize the package library
  1130. CommandLine CmdL;
  1131. auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_CACHE, &_config, &_system, argc, argv);
  1132. InitOutput();
  1133. if (_config->Exists("APT::Cache::Generate") == true)
  1134. _config->Set("pkgCacheFile::Generate", _config->FindB("APT::Cache::Generate", true));
  1135. return DispatchCommandLine(CmdL, Cmds);
  1136. }
  1137. /*}}}*/