apt-cache.cc 38 KB

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