apt-cache.cc 38 KB

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