apt-cache.cc 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869
  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 <apt-pkg/error.h>
  13. #include <apt-pkg/pkgcachegen.h>
  14. #include <apt-pkg/init.h>
  15. #include <apt-pkg/progress.h>
  16. #include <apt-pkg/sourcelist.h>
  17. #include <apt-pkg/cmndline.h>
  18. #include <apt-pkg/strutl.h>
  19. #include <apt-pkg/pkgrecords.h>
  20. #include <apt-pkg/srcrecords.h>
  21. #include <apt-pkg/version.h>
  22. #include <apt-pkg/policy.h>
  23. #include <apt-pkg/tagfile.h>
  24. #include <apt-pkg/algorithms.h>
  25. #include <apt-pkg/sptr.h>
  26. #include <config.h>
  27. #include <apti18n.h>
  28. #include <locale.h>
  29. #include <iostream>
  30. #include <unistd.h>
  31. #include <errno.h>
  32. #include <regex.h>
  33. #include <stdio.h>
  34. #include <iomanip>
  35. /*}}}*/
  36. using namespace std;
  37. pkgCache *GCache = 0;
  38. pkgSourceList *SrcList = 0;
  39. // LocalitySort - Sort a version list by package file locality /*{{{*/
  40. // ---------------------------------------------------------------------
  41. /* */
  42. int LocalityCompare(const void *a, const void *b)
  43. {
  44. pkgCache::VerFile *A = *(pkgCache::VerFile **)a;
  45. pkgCache::VerFile *B = *(pkgCache::VerFile **)b;
  46. if (A == 0 && B == 0)
  47. return 0;
  48. if (A == 0)
  49. return 1;
  50. if (B == 0)
  51. return -1;
  52. if (A->File == B->File)
  53. return A->Offset - B->Offset;
  54. return A->File - B->File;
  55. }
  56. void LocalitySort(pkgCache::VerFile **begin,
  57. unsigned long Count,size_t Size)
  58. {
  59. qsort(begin,Count,Size,LocalityCompare);
  60. }
  61. void LocalitySort(pkgCache::DescFile **begin,
  62. unsigned long Count,size_t Size)
  63. {
  64. qsort(begin,Count,Size,LocalityCompare);
  65. }
  66. /*}}}*/
  67. // UnMet - Show unmet dependencies /*{{{*/
  68. // ---------------------------------------------------------------------
  69. /* */
  70. bool UnMet(CommandLine &CmdL)
  71. {
  72. pkgCache &Cache = *GCache;
  73. bool Important = _config->FindB("APT::Cache::Important",false);
  74. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  75. {
  76. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
  77. {
  78. bool Header = false;
  79. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false;)
  80. {
  81. // Collect or groups
  82. pkgCache::DepIterator Start;
  83. pkgCache::DepIterator End;
  84. D.GlobOr(Start,End);
  85. // Skip conflicts and replaces
  86. if (End->Type != pkgCache::Dep::PreDepends &&
  87. End->Type != pkgCache::Dep::Depends &&
  88. End->Type != pkgCache::Dep::Suggests &&
  89. End->Type != pkgCache::Dep::Recommends)
  90. continue;
  91. // Important deps only
  92. if (Important == true)
  93. if (End->Type != pkgCache::Dep::PreDepends &&
  94. End->Type != pkgCache::Dep::Depends)
  95. continue;
  96. // Verify the or group
  97. bool OK = false;
  98. pkgCache::DepIterator RealStart = Start;
  99. do
  100. {
  101. // See if this dep is Ok
  102. pkgCache::Version **VList = Start.AllTargets();
  103. if (*VList != 0)
  104. {
  105. OK = true;
  106. delete [] VList;
  107. break;
  108. }
  109. delete [] VList;
  110. if (Start == End)
  111. break;
  112. Start++;
  113. }
  114. while (1);
  115. // The group is OK
  116. if (OK == true)
  117. continue;
  118. // Oops, it failed..
  119. if (Header == false)
  120. ioprintf(cout,_("Package %s version %s has an unmet dep:\n"),
  121. P.Name(),V.VerStr());
  122. Header = true;
  123. // Print out the dep type
  124. cout << " " << End.DepType() << ": ";
  125. // Show the group
  126. Start = RealStart;
  127. do
  128. {
  129. cout << Start.TargetPkg().Name();
  130. if (Start.TargetVer() != 0)
  131. cout << " (" << Start.CompType() << " " << Start.TargetVer() <<
  132. ")";
  133. if (Start == End)
  134. break;
  135. cout << " | ";
  136. Start++;
  137. }
  138. while (1);
  139. cout << endl;
  140. }
  141. }
  142. }
  143. return true;
  144. }
  145. /*}}}*/
  146. // DumpPackage - Show a dump of a package record /*{{{*/
  147. // ---------------------------------------------------------------------
  148. /* */
  149. bool DumpPackage(CommandLine &CmdL)
  150. {
  151. pkgCache &Cache = *GCache;
  152. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  153. {
  154. pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
  155. if (Pkg.end() == true)
  156. {
  157. _error->Warning(_("Unable to locate package %s"),*I);
  158. continue;
  159. }
  160. cout << "Package: " << Pkg.Name() << endl;
  161. cout << "Versions: " << endl;
  162. for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
  163. {
  164. cout << Cur.VerStr();
  165. for (pkgCache::VerFileIterator Vf = Cur.FileList(); Vf.end() == false; Vf++)
  166. cout << " (" << Vf.File().FileName() << ")";
  167. cout << endl;
  168. for (pkgCache::DescIterator D = Cur.DescriptionList(); D.end() == false; D++)
  169. {
  170. cout << " Description Language: " << D.LanguageCode() << endl
  171. << " File: " << D.FileList().File().FileName() << endl
  172. << " MD5: " << D.md5() << endl;
  173. }
  174. cout << endl;
  175. }
  176. cout << endl;
  177. cout << "Reverse Depends: " << endl;
  178. for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() != true; D++)
  179. {
  180. cout << " " << D.ParentPkg().Name() << ',' << D.TargetPkg().Name();
  181. if (D->Version != 0)
  182. cout << ' ' << DeNull(D.TargetVer()) << endl;
  183. else
  184. cout << endl;
  185. }
  186. cout << "Dependencies: " << endl;
  187. for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
  188. {
  189. cout << Cur.VerStr() << " - ";
  190. for (pkgCache::DepIterator Dep = Cur.DependsList(); Dep.end() != true; Dep++)
  191. cout << Dep.TargetPkg().Name() << " (" << (int)Dep->CompareOp << " " << DeNull(Dep.TargetVer()) << ") ";
  192. cout << endl;
  193. }
  194. cout << "Provides: " << endl;
  195. for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
  196. {
  197. cout << Cur.VerStr() << " - ";
  198. for (pkgCache::PrvIterator Prv = Cur.ProvidesList(); Prv.end() != true; Prv++)
  199. cout << Prv.ParentPkg().Name() << " ";
  200. cout << endl;
  201. }
  202. cout << "Reverse Provides: " << endl;
  203. for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; Prv++)
  204. cout << Prv.OwnerPkg().Name() << " " << Prv.OwnerVer().VerStr() << endl;
  205. }
  206. return true;
  207. }
  208. /*}}}*/
  209. // Stats - Dump some nice statistics /*{{{*/
  210. // ---------------------------------------------------------------------
  211. /* */
  212. bool Stats(CommandLine &Cmd)
  213. {
  214. pkgCache &Cache = *GCache;
  215. cout << _("Total package names : ") << Cache.Head().PackageCount << " (" <<
  216. SizeToStr(Cache.Head().PackageCount*Cache.Head().PackageSz) << ')' << endl;
  217. int Normal = 0;
  218. int Virtual = 0;
  219. int NVirt = 0;
  220. int DVirt = 0;
  221. int Missing = 0;
  222. pkgCache::PkgIterator I = Cache.PkgBegin();
  223. for (;I.end() != true; I++)
  224. {
  225. if (I->VersionList != 0 && I->ProvidesList == 0)
  226. {
  227. Normal++;
  228. continue;
  229. }
  230. if (I->VersionList != 0 && I->ProvidesList != 0)
  231. {
  232. NVirt++;
  233. continue;
  234. }
  235. if (I->VersionList == 0 && I->ProvidesList != 0)
  236. {
  237. // Only 1 provides
  238. if (I.ProvidesList()->NextProvides == 0)
  239. {
  240. DVirt++;
  241. }
  242. else
  243. Virtual++;
  244. continue;
  245. }
  246. if (I->VersionList == 0 && I->ProvidesList == 0)
  247. {
  248. Missing++;
  249. continue;
  250. }
  251. }
  252. cout << _(" Normal packages: ") << Normal << endl;
  253. cout << _(" Pure virtual packages: ") << Virtual << endl;
  254. cout << _(" Single virtual packages: ") << DVirt << endl;
  255. cout << _(" Mixed virtual packages: ") << NVirt << endl;
  256. cout << _(" Missing: ") << Missing << endl;
  257. cout << _("Total distinct versions: ") << Cache.Head().VersionCount << " (" <<
  258. SizeToStr(Cache.Head().VersionCount*Cache.Head().VersionSz) << ')' << endl;
  259. cout << _("Total Distinct Descriptions: ") << Cache.Head().DescriptionCount << " (" <<
  260. SizeToStr(Cache.Head().DescriptionCount*Cache.Head().DescriptionSz) << ')' << endl;
  261. cout << _("Total dependencies: ") << Cache.Head().DependsCount << " (" <<
  262. SizeToStr(Cache.Head().DependsCount*Cache.Head().DependencySz) << ')' << endl;
  263. cout << _("Total ver/file relations: ") << Cache.Head().VerFileCount << " (" <<
  264. SizeToStr(Cache.Head().VerFileCount*Cache.Head().VerFileSz) << ')' << endl;
  265. cout << _("Total Desc/File relations: ") << Cache.Head().DescFileCount << " (" <<
  266. SizeToStr(Cache.Head().DescFileCount*Cache.Head().DescFileSz) << ')' << endl;
  267. cout << _("Total Provides mappings: ") << Cache.Head().ProvidesCount << " (" <<
  268. SizeToStr(Cache.Head().ProvidesCount*Cache.Head().ProvidesSz) << ')' << endl;
  269. // String list stats
  270. unsigned long Size = 0;
  271. unsigned long Count = 0;
  272. for (pkgCache::StringItem *I = Cache.StringItemP + Cache.Head().StringList;
  273. I!= Cache.StringItemP; I = Cache.StringItemP + I->NextItem)
  274. {
  275. Count++;
  276. Size += strlen(Cache.StrP + I->String) + 1;
  277. }
  278. cout << _("Total globbed strings: ") << Count << " (" << SizeToStr(Size) << ')' << endl;
  279. unsigned long DepVerSize = 0;
  280. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  281. {
  282. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
  283. {
  284. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++)
  285. {
  286. if (D->Version != 0)
  287. DepVerSize += strlen(D.TargetVer()) + 1;
  288. }
  289. }
  290. }
  291. cout << _("Total dependency version space: ") << SizeToStr(DepVerSize) << endl;
  292. unsigned long Slack = 0;
  293. for (int I = 0; I != 7; I++)
  294. Slack += Cache.Head().Pools[I].ItemSize*Cache.Head().Pools[I].Count;
  295. cout << _("Total slack space: ") << SizeToStr(Slack) << endl;
  296. unsigned long Total = 0;
  297. Total = Slack + Size + Cache.Head().DependsCount*Cache.Head().DependencySz +
  298. Cache.Head().VersionCount*Cache.Head().VersionSz +
  299. Cache.Head().PackageCount*Cache.Head().PackageSz +
  300. Cache.Head().VerFileCount*Cache.Head().VerFileSz +
  301. Cache.Head().ProvidesCount*Cache.Head().ProvidesSz;
  302. cout << _("Total space accounted for: ") << SizeToStr(Total) << endl;
  303. return true;
  304. }
  305. /*}}}*/
  306. // Dump - show everything /*{{{*/
  307. // ---------------------------------------------------------------------
  308. /* This is worthless except fer debugging things */
  309. bool Dump(CommandLine &Cmd)
  310. {
  311. pkgCache &Cache = *GCache;
  312. cout << "Using Versioning System: " << Cache.VS->Label << endl;
  313. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  314. {
  315. cout << "Package: " << P.Name() << endl;
  316. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
  317. {
  318. cout << " Version: " << V.VerStr() << endl;
  319. cout << " File: " << V.FileList().File().FileName() << endl;
  320. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++)
  321. cout << " Depends: " << D.TargetPkg().Name() << ' ' <<
  322. DeNull(D.TargetVer()) << endl;
  323. for (pkgCache::DescIterator D = V.DescriptionList(); D.end() == false; D++)
  324. {
  325. cout << " Description Language: " << D.LanguageCode() << endl
  326. << " File: " << D.FileList().File().FileName() << endl
  327. << " MD5: " << D.md5() << endl;
  328. }
  329. }
  330. }
  331. for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++)
  332. {
  333. cout << "File: " << F.FileName() << endl;
  334. cout << " Type: " << F.IndexType() << endl;
  335. cout << " Size: " << F->Size << endl;
  336. cout << " ID: " << F->ID << endl;
  337. cout << " Flags: " << F->Flags << endl;
  338. cout << " Time: " << TimeRFC1123(F->mtime) << endl;
  339. cout << " Archive: " << DeNull(F.Archive()) << endl;
  340. cout << " Component: " << DeNull(F.Component()) << endl;
  341. cout << " Version: " << DeNull(F.Version()) << endl;
  342. cout << " Origin: " << DeNull(F.Origin()) << endl;
  343. cout << " Site: " << DeNull(F.Site()) << endl;
  344. cout << " Label: " << DeNull(F.Label()) << endl;
  345. cout << " Architecture: " << DeNull(F.Architecture()) << endl;
  346. }
  347. return true;
  348. }
  349. /*}}}*/
  350. // DumpAvail - Print out the available list /*{{{*/
  351. // ---------------------------------------------------------------------
  352. /* This is needed to make dpkg --merge happy.. I spent a bit of time to
  353. make this run really fast, perhaps I went a little overboard.. */
  354. bool DumpAvail(CommandLine &Cmd)
  355. {
  356. pkgCache &Cache = *GCache;
  357. pkgPolicy Plcy(&Cache);
  358. if (ReadPinFile(Plcy) == false)
  359. return false;
  360. unsigned long Count = Cache.HeaderP->PackageCount+1;
  361. pkgCache::VerFile **VFList = new pkgCache::VerFile *[Count];
  362. memset(VFList,0,sizeof(*VFList)*Count);
  363. // Map versions that we want to write out onto the VerList array.
  364. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  365. {
  366. if (P->VersionList == 0)
  367. continue;
  368. /* Find the proper version to use. If the policy says there are no
  369. possible selections we return the installed version, if available..
  370. This prevents dselect from making it obsolete. */
  371. pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
  372. if (V.end() == true)
  373. {
  374. if (P->CurrentVer == 0)
  375. continue;
  376. V = P.CurrentVer();
  377. }
  378. pkgCache::VerFileIterator VF = V.FileList();
  379. for (; VF.end() == false ; VF++)
  380. if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0)
  381. break;
  382. /* Okay, here we have a bit of a problem.. The policy has selected the
  383. currently installed package - however it only exists in the
  384. status file.. We need to write out something or dselect will mark
  385. the package as obsolete! Thus we emit the status file entry, but
  386. below we remove the status line to make it valid for the
  387. available file. However! We only do this if their do exist *any*
  388. non-source versions of the package - that way the dselect obsolete
  389. handling works OK. */
  390. if (VF.end() == true)
  391. {
  392. for (pkgCache::VerIterator Cur = P.VersionList(); Cur.end() != true; Cur++)
  393. {
  394. for (VF = Cur.FileList(); VF.end() == false; VF++)
  395. {
  396. if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0)
  397. {
  398. VF = V.FileList();
  399. break;
  400. }
  401. }
  402. if (VF.end() == false)
  403. break;
  404. }
  405. }
  406. VFList[P->ID] = VF;
  407. }
  408. LocalitySort(VFList,Count,sizeof(*VFList));
  409. // Iterate over all the package files and write them out.
  410. char *Buffer = new char[Cache.HeaderP->MaxVerFileSize+10];
  411. for (pkgCache::VerFile **J = VFList; *J != 0;)
  412. {
  413. pkgCache::PkgFileIterator File(Cache,(*J)->File + Cache.PkgFileP);
  414. if (File.IsOk() == false)
  415. {
  416. _error->Error(_("Package file %s is out of sync."),File.FileName());
  417. break;
  418. }
  419. FileFd PkgF(File.FileName(),FileFd::ReadOnly);
  420. if (_error->PendingError() == true)
  421. break;
  422. /* Write all of the records from this package file, since we
  423. already did locality sorting we can now just seek through the
  424. file in read order. We apply 1 more optimization here, since often
  425. there will be < 1 byte gaps between records (for the \n) we read that
  426. into the next buffer and offset a bit.. */
  427. unsigned long Pos = 0;
  428. for (; *J != 0; J++)
  429. {
  430. if ((*J)->File + Cache.PkgFileP != File)
  431. break;
  432. const pkgCache::VerFile &VF = **J;
  433. // Read the record and then write it out again.
  434. unsigned long Jitter = VF.Offset - Pos;
  435. if (Jitter > 8)
  436. {
  437. if (PkgF.Seek(VF.Offset) == false)
  438. break;
  439. Jitter = 0;
  440. }
  441. if (PkgF.Read(Buffer,VF.Size + Jitter) == false)
  442. break;
  443. Buffer[VF.Size + Jitter] = '\n';
  444. // See above..
  445. if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource)
  446. {
  447. pkgTagSection Tags;
  448. TFRewriteData RW[] = {{"Status",0},{"Config-Version",0},{}};
  449. const char *Zero = 0;
  450. if (Tags.Scan(Buffer+Jitter,VF.Size+1) == false ||
  451. TFRewrite(stdout,Tags,&Zero,RW) == false)
  452. {
  453. _error->Error("Internal Error, Unable to parse a package record");
  454. break;
  455. }
  456. fputc('\n',stdout);
  457. }
  458. else
  459. {
  460. if (fwrite(Buffer+Jitter,VF.Size+1,1,stdout) != 1)
  461. break;
  462. }
  463. Pos = VF.Offset + VF.Size;
  464. }
  465. fflush(stdout);
  466. if (_error->PendingError() == true)
  467. break;
  468. }
  469. delete [] Buffer;
  470. delete [] VFList;
  471. return !_error->PendingError();
  472. }
  473. /*}}}*/
  474. // Depends - Print out a dependency tree /*{{{*/
  475. // ---------------------------------------------------------------------
  476. /* */
  477. bool Depends(CommandLine &CmdL)
  478. {
  479. pkgCache &Cache = *GCache;
  480. SPtrArray<unsigned> Colours = new unsigned[Cache.Head().PackageCount];
  481. memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount);
  482. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  483. {
  484. pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
  485. if (Pkg.end() == true)
  486. {
  487. _error->Warning(_("Unable to locate package %s"),*I);
  488. continue;
  489. }
  490. Colours[Pkg->ID] = 1;
  491. }
  492. bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
  493. bool Installed = _config->FindB("APT::Cache::Installed",false);
  494. bool DidSomething;
  495. do
  496. {
  497. DidSomething = false;
  498. for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
  499. {
  500. if (Colours[Pkg->ID] != 1)
  501. continue;
  502. Colours[Pkg->ID] = 2;
  503. DidSomething = true;
  504. pkgCache::VerIterator Ver = Pkg.VersionList();
  505. if (Ver.end() == true)
  506. {
  507. cout << '<' << Pkg.Name() << '>' << endl;
  508. continue;
  509. }
  510. cout << Pkg.Name() << endl;
  511. for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
  512. {
  513. pkgCache::PkgIterator Trg = D.TargetPkg();
  514. if((Installed && Trg->CurrentVer != 0) || !Installed)
  515. {
  516. if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
  517. cout << " |";
  518. else
  519. cout << " ";
  520. // Show the package
  521. if (Trg->VersionList == 0)
  522. cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
  523. else
  524. cout << D.DepType() << ": " << Trg.Name() << endl;
  525. if (Recurse == true)
  526. Colours[D.TargetPkg()->ID]++;
  527. }
  528. // Display all solutions
  529. SPtrArray<pkgCache::Version *> List = D.AllTargets();
  530. pkgPrioSortList(Cache,List);
  531. for (pkgCache::Version **I = List; *I != 0; I++)
  532. {
  533. pkgCache::VerIterator V(Cache,*I);
  534. if (V != Cache.VerP + V.ParentPkg()->VersionList ||
  535. V->ParentPkg == D->Package)
  536. continue;
  537. cout << " " << V.ParentPkg().Name() << endl;
  538. if (Recurse == true)
  539. Colours[D.ParentPkg()->ID]++;
  540. }
  541. }
  542. }
  543. }
  544. while (DidSomething == true);
  545. return true;
  546. }
  547. // RDepends - Print out a reverse dependency tree - mbc /*{{{*/
  548. // ---------------------------------------------------------------------
  549. /* */
  550. bool RDepends(CommandLine &CmdL)
  551. {
  552. pkgCache &Cache = *GCache;
  553. SPtrArray<unsigned> Colours = new unsigned[Cache.Head().PackageCount];
  554. memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount);
  555. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  556. {
  557. pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
  558. if (Pkg.end() == true)
  559. {
  560. _error->Warning(_("Unable to locate package %s"),*I);
  561. continue;
  562. }
  563. Colours[Pkg->ID] = 1;
  564. }
  565. bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
  566. bool Installed = _config->FindB("APT::Cache::Installed",false);
  567. bool DidSomething;
  568. do
  569. {
  570. DidSomething = false;
  571. for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
  572. {
  573. if (Colours[Pkg->ID] != 1)
  574. continue;
  575. Colours[Pkg->ID] = 2;
  576. DidSomething = true;
  577. pkgCache::VerIterator Ver = Pkg.VersionList();
  578. if (Ver.end() == true)
  579. {
  580. cout << '<' << Pkg.Name() << '>' << endl;
  581. continue;
  582. }
  583. cout << Pkg.Name() << endl;
  584. cout << "Reverse Depends:" << endl;
  585. for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++)
  586. {
  587. // Show the package
  588. pkgCache::PkgIterator Trg = D.ParentPkg();
  589. if((Installed && Trg->CurrentVer != 0) || !Installed)
  590. {
  591. if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
  592. cout << " |";
  593. else
  594. cout << " ";
  595. if (Trg->VersionList == 0)
  596. cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
  597. else
  598. cout << Trg.Name() << endl;
  599. if (Recurse == true)
  600. Colours[D.ParentPkg()->ID]++;
  601. }
  602. // Display all solutions
  603. SPtrArray<pkgCache::Version *> List = D.AllTargets();
  604. pkgPrioSortList(Cache,List);
  605. for (pkgCache::Version **I = List; *I != 0; I++)
  606. {
  607. pkgCache::VerIterator V(Cache,*I);
  608. if (V != Cache.VerP + V.ParentPkg()->VersionList ||
  609. V->ParentPkg == D->Package)
  610. continue;
  611. cout << " " << V.ParentPkg().Name() << endl;
  612. if (Recurse == true)
  613. Colours[D.ParentPkg()->ID]++;
  614. }
  615. }
  616. }
  617. }
  618. while (DidSomething == true);
  619. return true;
  620. }
  621. /*}}}*/
  622. // xvcg - Generate a graph for xvcg /*{{{*/
  623. // ---------------------------------------------------------------------
  624. // Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
  625. bool XVcg(CommandLine &CmdL)
  626. {
  627. pkgCache &Cache = *GCache;
  628. bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false);
  629. /* Normal packages are boxes
  630. Pure Provides are triangles
  631. Mixed are diamonds
  632. rhomb are missing packages*/
  633. const char *Shapes[] = {"ellipse","triangle","box","rhomb"};
  634. /* Initialize the list of packages to show.
  635. 1 = To Show
  636. 2 = To Show no recurse
  637. 3 = Emitted no recurse
  638. 4 = Emitted
  639. 0 = None */
  640. enum States {None=0, ToShow, ToShowNR, DoneNR, Done};
  641. enum TheFlags {ForceNR=(1<<0)};
  642. unsigned char *Show = new unsigned char[Cache.Head().PackageCount];
  643. unsigned char *Flags = new unsigned char[Cache.Head().PackageCount];
  644. unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount];
  645. // Show everything if no arguments given
  646. if (CmdL.FileList[1] == 0)
  647. for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
  648. Show[I] = ToShow;
  649. else
  650. for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
  651. Show[I] = None;
  652. memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount);
  653. // Map the shapes
  654. for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
  655. {
  656. if (Pkg->VersionList == 0)
  657. {
  658. // Missing
  659. if (Pkg->ProvidesList == 0)
  660. ShapeMap[Pkg->ID] = 0;
  661. else
  662. ShapeMap[Pkg->ID] = 1;
  663. }
  664. else
  665. {
  666. // Normal
  667. if (Pkg->ProvidesList == 0)
  668. ShapeMap[Pkg->ID] = 2;
  669. else
  670. ShapeMap[Pkg->ID] = 3;
  671. }
  672. }
  673. // Load the list of packages from the command line into the show list
  674. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  675. {
  676. // Process per-package flags
  677. string P = *I;
  678. bool Force = false;
  679. if (P.length() > 3)
  680. {
  681. if (P.end()[-1] == '^')
  682. {
  683. Force = true;
  684. P.erase(P.end()-1);
  685. }
  686. if (P.end()[-1] == ',')
  687. P.erase(P.end()-1);
  688. }
  689. // Locate the package
  690. pkgCache::PkgIterator Pkg = Cache.FindPkg(P);
  691. if (Pkg.end() == true)
  692. {
  693. _error->Warning(_("Unable to locate package %s"),*I);
  694. continue;
  695. }
  696. Show[Pkg->ID] = ToShow;
  697. if (Force == true)
  698. Flags[Pkg->ID] |= ForceNR;
  699. }
  700. // Little header
  701. cout << "graph: { title: \"packages\"" << endl <<
  702. "xmax: 700 ymax: 700 x: 30 y: 30" << endl <<
  703. "layout_downfactor: 8" << endl;
  704. bool Act = true;
  705. while (Act == true)
  706. {
  707. Act = false;
  708. for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
  709. {
  710. // See we need to show this package
  711. if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR)
  712. continue;
  713. //printf ("node: { title: \"%s\" label: \"%s\" }\n", Pkg.Name(), Pkg.Name());
  714. // Colour as done
  715. if (Show[Pkg->ID] == ToShowNR || (Flags[Pkg->ID] & ForceNR) == ForceNR)
  716. {
  717. // Pure Provides and missing packages have no deps!
  718. if (ShapeMap[Pkg->ID] == 0 || ShapeMap[Pkg->ID] == 1)
  719. Show[Pkg->ID] = Done;
  720. else
  721. Show[Pkg->ID] = DoneNR;
  722. }
  723. else
  724. Show[Pkg->ID] = Done;
  725. Act = true;
  726. // No deps to map out
  727. if (Pkg->VersionList == 0 || Show[Pkg->ID] == DoneNR)
  728. continue;
  729. pkgCache::VerIterator Ver = Pkg.VersionList();
  730. for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
  731. {
  732. // See if anything can meet this dep
  733. // Walk along the actual package providing versions
  734. bool Hit = false;
  735. pkgCache::PkgIterator DPkg = D.TargetPkg();
  736. for (pkgCache::VerIterator I = DPkg.VersionList();
  737. I.end() == false && Hit == false; I++)
  738. {
  739. if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true)
  740. Hit = true;
  741. }
  742. // Follow all provides
  743. for (pkgCache::PrvIterator I = DPkg.ProvidesList();
  744. I.end() == false && Hit == false; I++)
  745. {
  746. if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false)
  747. Hit = true;
  748. }
  749. // Only graph critical deps
  750. if (D.IsCritical() == true)
  751. {
  752. printf ("edge: { sourcename: \"%s\" targetname: \"%s\" class: 2 ",Pkg.Name(), D.TargetPkg().Name() );
  753. // Colour the node for recursion
  754. if (Show[D.TargetPkg()->ID] <= DoneNR)
  755. {
  756. /* If a conflicts does not meet anything in the database
  757. then show the relation but do not recurse */
  758. if (Hit == false &&
  759. (D->Type == pkgCache::Dep::Conflicts ||
  760. D->Type == pkgCache::Dep::Obsoletes))
  761. {
  762. if (Show[D.TargetPkg()->ID] == None &&
  763. Show[D.TargetPkg()->ID] != ToShow)
  764. Show[D.TargetPkg()->ID] = ToShowNR;
  765. }
  766. else
  767. {
  768. if (GivenOnly == true && Show[D.TargetPkg()->ID] != ToShow)
  769. Show[D.TargetPkg()->ID] = ToShowNR;
  770. else
  771. Show[D.TargetPkg()->ID] = ToShow;
  772. }
  773. }
  774. // Edge colour
  775. switch(D->Type)
  776. {
  777. case pkgCache::Dep::Conflicts:
  778. printf("label: \"conflicts\" color: lightgreen }\n");
  779. break;
  780. case pkgCache::Dep::Obsoletes:
  781. printf("label: \"obsoletes\" color: lightgreen }\n");
  782. break;
  783. case pkgCache::Dep::PreDepends:
  784. printf("label: \"predepends\" color: blue }\n");
  785. break;
  786. default:
  787. printf("}\n");
  788. break;
  789. }
  790. }
  791. }
  792. }
  793. }
  794. /* Draw the box colours after the fact since we can not tell what colour
  795. they should be until everything is finished drawing */
  796. for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
  797. {
  798. if (Show[Pkg->ID] < DoneNR)
  799. continue;
  800. if (Show[Pkg->ID] == DoneNR)
  801. printf("node: { title: \"%s\" label: \"%s\" color: orange shape: %s }\n", Pkg.Name(), Pkg.Name(),
  802. Shapes[ShapeMap[Pkg->ID]]);
  803. else
  804. printf("node: { title: \"%s\" label: \"%s\" shape: %s }\n", Pkg.Name(), Pkg.Name(),
  805. Shapes[ShapeMap[Pkg->ID]]);
  806. }
  807. printf("}\n");
  808. return true;
  809. }
  810. /*}}}*/
  811. // Dotty - Generate a graph for Dotty /*{{{*/
  812. // ---------------------------------------------------------------------
  813. /* Dotty is the graphvis program for generating graphs. It is a fairly
  814. simple queuing algorithm that just writes dependencies and nodes.
  815. http://www.research.att.com/sw/tools/graphviz/ */
  816. bool Dotty(CommandLine &CmdL)
  817. {
  818. pkgCache &Cache = *GCache;
  819. bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false);
  820. /* Normal packages are boxes
  821. Pure Provides are triangles
  822. Mixed are diamonds
  823. Hexagons are missing packages*/
  824. const char *Shapes[] = {"hexagon","triangle","box","diamond"};
  825. /* Initialize the list of packages to show.
  826. 1 = To Show
  827. 2 = To Show no recurse
  828. 3 = Emitted no recurse
  829. 4 = Emitted
  830. 0 = None */
  831. enum States {None=0, ToShow, ToShowNR, DoneNR, Done};
  832. enum TheFlags {ForceNR=(1<<0)};
  833. unsigned char *Show = new unsigned char[Cache.Head().PackageCount];
  834. unsigned char *Flags = new unsigned char[Cache.Head().PackageCount];
  835. unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount];
  836. // Show everything if no arguments given
  837. if (CmdL.FileList[1] == 0)
  838. for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
  839. Show[I] = ToShow;
  840. else
  841. for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
  842. Show[I] = None;
  843. memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount);
  844. // Map the shapes
  845. for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
  846. {
  847. if (Pkg->VersionList == 0)
  848. {
  849. // Missing
  850. if (Pkg->ProvidesList == 0)
  851. ShapeMap[Pkg->ID] = 0;
  852. else
  853. ShapeMap[Pkg->ID] = 1;
  854. }
  855. else
  856. {
  857. // Normal
  858. if (Pkg->ProvidesList == 0)
  859. ShapeMap[Pkg->ID] = 2;
  860. else
  861. ShapeMap[Pkg->ID] = 3;
  862. }
  863. }
  864. // Load the list of packages from the command line into the show list
  865. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  866. {
  867. // Process per-package flags
  868. string P = *I;
  869. bool Force = false;
  870. if (P.length() > 3)
  871. {
  872. if (P.end()[-1] == '^')
  873. {
  874. Force = true;
  875. P.erase(P.end()-1);
  876. }
  877. if (P.end()[-1] == ',')
  878. P.erase(P.end()-1);
  879. }
  880. // Locate the package
  881. pkgCache::PkgIterator Pkg = Cache.FindPkg(P);
  882. if (Pkg.end() == true)
  883. {
  884. _error->Warning(_("Unable to locate package %s"),*I);
  885. continue;
  886. }
  887. Show[Pkg->ID] = ToShow;
  888. if (Force == true)
  889. Flags[Pkg->ID] |= ForceNR;
  890. }
  891. // Little header
  892. printf("digraph packages {\n");
  893. printf("concentrate=true;\n");
  894. printf("size=\"30,40\";\n");
  895. bool Act = true;
  896. while (Act == true)
  897. {
  898. Act = false;
  899. for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
  900. {
  901. // See we need to show this package
  902. if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR)
  903. continue;
  904. // Colour as done
  905. if (Show[Pkg->ID] == ToShowNR || (Flags[Pkg->ID] & ForceNR) == ForceNR)
  906. {
  907. // Pure Provides and missing packages have no deps!
  908. if (ShapeMap[Pkg->ID] == 0 || ShapeMap[Pkg->ID] == 1)
  909. Show[Pkg->ID] = Done;
  910. else
  911. Show[Pkg->ID] = DoneNR;
  912. }
  913. else
  914. Show[Pkg->ID] = Done;
  915. Act = true;
  916. // No deps to map out
  917. if (Pkg->VersionList == 0 || Show[Pkg->ID] == DoneNR)
  918. continue;
  919. pkgCache::VerIterator Ver = Pkg.VersionList();
  920. for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
  921. {
  922. // See if anything can meet this dep
  923. // Walk along the actual package providing versions
  924. bool Hit = false;
  925. pkgCache::PkgIterator DPkg = D.TargetPkg();
  926. for (pkgCache::VerIterator I = DPkg.VersionList();
  927. I.end() == false && Hit == false; I++)
  928. {
  929. if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true)
  930. Hit = true;
  931. }
  932. // Follow all provides
  933. for (pkgCache::PrvIterator I = DPkg.ProvidesList();
  934. I.end() == false && Hit == false; I++)
  935. {
  936. if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false)
  937. Hit = true;
  938. }
  939. // Only graph critical deps
  940. if (D.IsCritical() == true)
  941. {
  942. printf("\"%s\" -> \"%s\"",Pkg.Name(),D.TargetPkg().Name());
  943. // Colour the node for recursion
  944. if (Show[D.TargetPkg()->ID] <= DoneNR)
  945. {
  946. /* If a conflicts does not meet anything in the database
  947. then show the relation but do not recurse */
  948. if (Hit == false &&
  949. (D->Type == pkgCache::Dep::Conflicts ||
  950. D->Type == pkgCache::Dep::Obsoletes))
  951. {
  952. if (Show[D.TargetPkg()->ID] == None &&
  953. Show[D.TargetPkg()->ID] != ToShow)
  954. Show[D.TargetPkg()->ID] = ToShowNR;
  955. }
  956. else
  957. {
  958. if (GivenOnly == true && Show[D.TargetPkg()->ID] != ToShow)
  959. Show[D.TargetPkg()->ID] = ToShowNR;
  960. else
  961. Show[D.TargetPkg()->ID] = ToShow;
  962. }
  963. }
  964. // Edge colour
  965. switch(D->Type)
  966. {
  967. case pkgCache::Dep::Conflicts:
  968. case pkgCache::Dep::Obsoletes:
  969. printf("[color=springgreen];\n");
  970. break;
  971. case pkgCache::Dep::PreDepends:
  972. printf("[color=blue];\n");
  973. break;
  974. default:
  975. printf(";\n");
  976. break;
  977. }
  978. }
  979. }
  980. }
  981. }
  982. /* Draw the box colours after the fact since we can not tell what colour
  983. they should be until everything is finished drawing */
  984. for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
  985. {
  986. if (Show[Pkg->ID] < DoneNR)
  987. continue;
  988. // Orange box for early recursion stoppage
  989. if (Show[Pkg->ID] == DoneNR)
  990. printf("\"%s\" [color=orange,shape=%s];\n",Pkg.Name(),
  991. Shapes[ShapeMap[Pkg->ID]]);
  992. else
  993. printf("\"%s\" [shape=%s];\n",Pkg.Name(),
  994. Shapes[ShapeMap[Pkg->ID]]);
  995. }
  996. printf("}\n");
  997. return true;
  998. }
  999. /*}}}*/
  1000. // DoAdd - Perform an adding operation /*{{{*/
  1001. // ---------------------------------------------------------------------
  1002. /* */
  1003. bool DoAdd(CommandLine &CmdL)
  1004. {
  1005. return _error->Error("Unimplemented");
  1006. #if 0
  1007. // Make sure there is at least one argument
  1008. if (CmdL.FileSize() <= 1)
  1009. return _error->Error("You must give at least one file name");
  1010. // Open the cache
  1011. FileFd CacheF(_config->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny);
  1012. if (_error->PendingError() == true)
  1013. return false;
  1014. DynamicMMap Map(CacheF,MMap::Public);
  1015. if (_error->PendingError() == true)
  1016. return false;
  1017. OpTextProgress Progress(*_config);
  1018. pkgCacheGenerator Gen(Map,Progress);
  1019. if (_error->PendingError() == true)
  1020. return false;
  1021. unsigned long Length = CmdL.FileSize() - 1;
  1022. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  1023. {
  1024. Progress.OverallProgress(I - CmdL.FileList,Length,1,"Generating cache");
  1025. Progress.SubProgress(Length);
  1026. // Do the merge
  1027. FileFd TagF(*I,FileFd::ReadOnly);
  1028. debListParser Parser(TagF);
  1029. if (_error->PendingError() == true)
  1030. return _error->Error("Problem opening %s",*I);
  1031. if (Gen.SelectFile(*I,"") == false)
  1032. return _error->Error("Problem with SelectFile");
  1033. if (Gen.MergeList(Parser) == false)
  1034. return _error->Error("Problem with MergeList");
  1035. }
  1036. Progress.Done();
  1037. GCache = &Gen.GetCache();
  1038. Stats(CmdL);
  1039. return true;
  1040. #endif
  1041. }
  1042. /*}}}*/
  1043. // DisplayRecord - Displays the complete record for the package /*{{{*/
  1044. // ---------------------------------------------------------------------
  1045. /* This displays the package record from the proper package index file.
  1046. It is not used by DumpAvail for performance reasons. */
  1047. bool DisplayRecord(pkgCache::VerIterator V)
  1048. {
  1049. // Find an appropriate file
  1050. pkgCache::VerFileIterator Vf = V.FileList();
  1051. for (; Vf.end() == false; Vf++)
  1052. if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
  1053. break;
  1054. if (Vf.end() == true)
  1055. Vf = V.FileList();
  1056. // Check and load the package list file
  1057. pkgCache::PkgFileIterator I = Vf.File();
  1058. if (I.IsOk() == false)
  1059. return _error->Error(_("Package file %s is out of sync."),I.FileName());
  1060. FileFd PkgF(I.FileName(),FileFd::ReadOnly);
  1061. if (_error->PendingError() == true)
  1062. return false;
  1063. // Read the record
  1064. unsigned char *Buffer = new unsigned char[GCache->HeaderP->MaxVerFileSize+1];
  1065. Buffer[V.FileList()->Size] = '\n';
  1066. if (PkgF.Seek(V.FileList()->Offset) == false ||
  1067. PkgF.Read(Buffer,V.FileList()->Size) == false)
  1068. {
  1069. delete [] Buffer;
  1070. return false;
  1071. }
  1072. // Get a pointer to start of Description field
  1073. const unsigned char *DescP = (unsigned char*)strstr((char*)Buffer, "Description:");
  1074. // Write all but Description
  1075. if (fwrite(Buffer,1,DescP - Buffer,stdout) < (size_t)(DescP - Buffer))
  1076. {
  1077. delete [] Buffer;
  1078. return false;
  1079. }
  1080. // Show the right description
  1081. pkgRecords Recs(*GCache);
  1082. pkgCache::DescIterator Desc = V.TranslatedDescription();
  1083. pkgRecords::Parser &P = Recs.Lookup(Desc.FileList());
  1084. cout << "Description" << ( (strcmp(Desc.LanguageCode(),"") != 0) ? "-" : "" ) << Desc.LanguageCode() << ": " << P.LongDesc();
  1085. // Find the first field after the description (if there is any)
  1086. for(DescP++;DescP != &Buffer[V.FileList()->Size];DescP++)
  1087. {
  1088. if(*DescP == '\n' && *(DescP+1) != ' ')
  1089. {
  1090. // write the rest of the buffer
  1091. const unsigned char *end=&Buffer[V.FileList()->Size];
  1092. if (fwrite(DescP,1,end-DescP,stdout) < (size_t)(end-DescP))
  1093. {
  1094. delete [] Buffer;
  1095. return false;
  1096. }
  1097. break;
  1098. }
  1099. }
  1100. // write a final newline (after the description)
  1101. cout<<endl;
  1102. delete [] Buffer;
  1103. return true;
  1104. }
  1105. /*}}}*/
  1106. // Search - Perform a search /*{{{*/
  1107. // ---------------------------------------------------------------------
  1108. /* This searches the package names and pacakge descriptions for a pattern */
  1109. struct ExDescFile
  1110. {
  1111. pkgCache::DescFile *Df;
  1112. bool NameMatch;
  1113. };
  1114. bool Search(CommandLine &CmdL)
  1115. {
  1116. pkgCache &Cache = *GCache;
  1117. bool ShowFull = _config->FindB("APT::Cache::ShowFull",false);
  1118. bool NamesOnly = _config->FindB("APT::Cache::NamesOnly",false);
  1119. unsigned NumPatterns = CmdL.FileSize() -1;
  1120. pkgDepCache::Policy Plcy;
  1121. // Make sure there is at least one argument
  1122. if (NumPatterns < 1)
  1123. return _error->Error(_("You must give exactly one pattern"));
  1124. // Compile the regex pattern
  1125. regex_t *Patterns = new regex_t[NumPatterns];
  1126. memset(Patterns,0,sizeof(*Patterns)*NumPatterns);
  1127. for (unsigned I = 0; I != NumPatterns; I++)
  1128. {
  1129. if (regcomp(&Patterns[I],CmdL.FileList[I+1],REG_EXTENDED | REG_ICASE |
  1130. REG_NOSUB) != 0)
  1131. {
  1132. for (; I != 0; I--)
  1133. regfree(&Patterns[I]);
  1134. return _error->Error("Regex compilation error");
  1135. }
  1136. }
  1137. // Create the text record parser
  1138. pkgRecords Recs(Cache);
  1139. if (_error->PendingError() == true)
  1140. {
  1141. for (unsigned I = 0; I != NumPatterns; I++)
  1142. regfree(&Patterns[I]);
  1143. return false;
  1144. }
  1145. ExDescFile *DFList = new ExDescFile[Cache.HeaderP->PackageCount+1];
  1146. memset(DFList,0,sizeof(*DFList)*Cache.HeaderP->PackageCount+1);
  1147. // Map versions that we want to write out onto the VerList array.
  1148. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  1149. {
  1150. DFList[P->ID].NameMatch = NumPatterns != 0;
  1151. for (unsigned I = 0; I != NumPatterns; I++)
  1152. {
  1153. if (regexec(&Patterns[I],P.Name(),0,0,0) == 0)
  1154. DFList[P->ID].NameMatch &= true;
  1155. else
  1156. DFList[P->ID].NameMatch = false;
  1157. }
  1158. // Doing names only, drop any that dont match..
  1159. if (NamesOnly == true && DFList[P->ID].NameMatch == false)
  1160. continue;
  1161. // Find the proper version to use.
  1162. pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
  1163. if (V.end() == false)
  1164. DFList[P->ID].Df = V.DescriptionList().FileList();
  1165. }
  1166. // Include all the packages that provide matching names too
  1167. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  1168. {
  1169. if (DFList[P->ID].NameMatch == false)
  1170. continue;
  1171. for (pkgCache::PrvIterator Prv = P.ProvidesList() ; Prv.end() == false; Prv++)
  1172. {
  1173. pkgCache::VerIterator V = Plcy.GetCandidateVer(Prv.OwnerPkg());
  1174. if (V.end() == false)
  1175. {
  1176. DFList[Prv.OwnerPkg()->ID].Df = V.DescriptionList().FileList();
  1177. DFList[Prv.OwnerPkg()->ID].NameMatch = true;
  1178. }
  1179. }
  1180. }
  1181. LocalitySort(&DFList->Df,Cache.HeaderP->PackageCount,sizeof(*DFList));
  1182. // Iterate over all the version records and check them
  1183. for (ExDescFile *J = DFList; J->Df != 0; J++)
  1184. {
  1185. pkgRecords::Parser &P = Recs.Lookup(pkgCache::DescFileIterator(Cache,J->Df));
  1186. bool Match = true;
  1187. if (J->NameMatch == false)
  1188. {
  1189. string LongDesc = P.LongDesc();
  1190. Match = NumPatterns != 0;
  1191. for (unsigned I = 0; I != NumPatterns; I++)
  1192. {
  1193. if (regexec(&Patterns[I],LongDesc.c_str(),0,0,0) == 0)
  1194. Match &= true;
  1195. else
  1196. Match = false;
  1197. }
  1198. }
  1199. if (Match == true)
  1200. {
  1201. if (ShowFull == true)
  1202. {
  1203. const char *Start;
  1204. const char *End;
  1205. P.GetRec(Start,End);
  1206. fwrite(Start,End-Start,1,stdout);
  1207. putc('\n',stdout);
  1208. }
  1209. else
  1210. printf("%s - %s\n",P.Name().c_str(),P.ShortDesc().c_str());
  1211. }
  1212. }
  1213. delete [] DFList;
  1214. for (unsigned I = 0; I != NumPatterns; I++)
  1215. regfree(&Patterns[I]);
  1216. if (ferror(stdout))
  1217. return _error->Error("Write to stdout failed");
  1218. return true;
  1219. }
  1220. /*}}}*/
  1221. // ShowPackage - Dump the package record to the screen /*{{{*/
  1222. // ---------------------------------------------------------------------
  1223. /* */
  1224. bool ShowPackage(CommandLine &CmdL)
  1225. {
  1226. pkgCache &Cache = *GCache;
  1227. pkgDepCache::Policy Plcy;
  1228. unsigned found = 0;
  1229. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  1230. {
  1231. pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
  1232. if (Pkg.end() == true)
  1233. {
  1234. _error->Warning(_("Unable to locate package %s"),*I);
  1235. continue;
  1236. }
  1237. ++found;
  1238. // Find the proper version to use.
  1239. if (_config->FindB("APT::Cache::AllVersions","true") == true)
  1240. {
  1241. pkgCache::VerIterator V;
  1242. for (V = Pkg.VersionList(); V.end() == false; V++)
  1243. {
  1244. if (DisplayRecord(V) == false)
  1245. return false;
  1246. }
  1247. }
  1248. else
  1249. {
  1250. pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg);
  1251. if (V.end() == true || V.FileList().end() == true)
  1252. continue;
  1253. if (DisplayRecord(V) == false)
  1254. return false;
  1255. }
  1256. }
  1257. if (found > 0)
  1258. return true;
  1259. return _error->Error(_("No packages found"));
  1260. }
  1261. /*}}}*/
  1262. // ShowPkgNames - Show package names /*{{{*/
  1263. // ---------------------------------------------------------------------
  1264. /* This does a prefix match on the first argument */
  1265. bool ShowPkgNames(CommandLine &CmdL)
  1266. {
  1267. pkgCache &Cache = *GCache;
  1268. pkgCache::PkgIterator I = Cache.PkgBegin();
  1269. bool All = _config->FindB("APT::Cache::AllNames","false");
  1270. if (CmdL.FileList[1] != 0)
  1271. {
  1272. for (;I.end() != true; I++)
  1273. {
  1274. if (All == false && I->VersionList == 0)
  1275. continue;
  1276. if (strncmp(I.Name(),CmdL.FileList[1],strlen(CmdL.FileList[1])) == 0)
  1277. cout << I.Name() << endl;
  1278. }
  1279. return true;
  1280. }
  1281. // Show all pkgs
  1282. for (;I.end() != true; I++)
  1283. {
  1284. if (All == false && I->VersionList == 0)
  1285. continue;
  1286. cout << I.Name() << endl;
  1287. }
  1288. return true;
  1289. }
  1290. /*}}}*/
  1291. // ShowSrcPackage - Show source package records /*{{{*/
  1292. // ---------------------------------------------------------------------
  1293. /* */
  1294. bool ShowSrcPackage(CommandLine &CmdL)
  1295. {
  1296. pkgSourceList List;
  1297. List.ReadMainList();
  1298. // Create the text record parsers
  1299. pkgSrcRecords SrcRecs(List);
  1300. if (_error->PendingError() == true)
  1301. return false;
  1302. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  1303. {
  1304. SrcRecs.Restart();
  1305. pkgSrcRecords::Parser *Parse;
  1306. while ((Parse = SrcRecs.Find(*I,false)) != 0)
  1307. cout << Parse->AsStr() << endl;;
  1308. }
  1309. return true;
  1310. }
  1311. /*}}}*/
  1312. // Policy - Show the results of the preferences file /*{{{*/
  1313. // ---------------------------------------------------------------------
  1314. /* */
  1315. bool Policy(CommandLine &CmdL)
  1316. {
  1317. if (SrcList == 0)
  1318. return _error->Error("Generate must be enabled for this function");
  1319. pkgCache &Cache = *GCache;
  1320. pkgPolicy Plcy(&Cache);
  1321. if (ReadPinFile(Plcy) == false)
  1322. return false;
  1323. // Print out all of the package files
  1324. if (CmdL.FileList[1] == 0)
  1325. {
  1326. cout << _("Package files:") << endl;
  1327. for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++)
  1328. {
  1329. // Locate the associated index files so we can derive a description
  1330. pkgIndexFile *Indx;
  1331. if (SrcList->FindIndex(F,Indx) == false &&
  1332. _system->FindIndex(F,Indx) == false)
  1333. return _error->Error(_("Cache is out of sync, can't x-ref a package file"));
  1334. printf(_("%4i %s\n"),
  1335. Plcy.GetPriority(F),Indx->Describe(true).c_str());
  1336. // Print the reference information for the package
  1337. string Str = F.RelStr();
  1338. if (Str.empty() == false)
  1339. printf(" release %s\n",F.RelStr().c_str());
  1340. if (F.Site() != 0 && F.Site()[0] != 0)
  1341. printf(" origin %s\n",F.Site());
  1342. }
  1343. // Show any packages have explicit pins
  1344. cout << _("Pinned packages:") << endl;
  1345. pkgCache::PkgIterator I = Cache.PkgBegin();
  1346. for (;I.end() != true; I++)
  1347. {
  1348. if (Plcy.GetPriority(I) == 0)
  1349. continue;
  1350. // Print the package name and the version we are forcing to
  1351. cout << " " << I.Name() << " -> ";
  1352. pkgCache::VerIterator V = Plcy.GetMatch(I);
  1353. if (V.end() == true)
  1354. cout << _("(not found)") << endl;
  1355. else
  1356. cout << V.VerStr() << endl;
  1357. }
  1358. return true;
  1359. }
  1360. // Print out detailed information for each package
  1361. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  1362. {
  1363. pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
  1364. if (Pkg.end() == true)
  1365. {
  1366. _error->Warning(_("Unable to locate package %s"),*I);
  1367. continue;
  1368. }
  1369. cout << Pkg.Name() << ":" << endl;
  1370. // Installed version
  1371. cout << _(" Installed: ");
  1372. if (Pkg->CurrentVer == 0)
  1373. cout << _("(none)") << endl;
  1374. else
  1375. cout << Pkg.CurrentVer().VerStr() << endl;
  1376. // Candidate Version
  1377. cout << _(" Candidate: ");
  1378. pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg);
  1379. if (V.end() == true)
  1380. cout << _("(none)") << endl;
  1381. else
  1382. cout << V.VerStr() << endl;
  1383. // Pinned version
  1384. if (Plcy.GetPriority(Pkg) != 0)
  1385. {
  1386. cout << _(" Package pin: ");
  1387. V = Plcy.GetMatch(Pkg);
  1388. if (V.end() == true)
  1389. cout << _("(not found)") << endl;
  1390. else
  1391. cout << V.VerStr() << endl;
  1392. }
  1393. // Show the priority tables
  1394. cout << _(" Version table:") << endl;
  1395. for (V = Pkg.VersionList(); V.end() == false; V++)
  1396. {
  1397. if (Pkg.CurrentVer() == V)
  1398. cout << " *** " << V.VerStr();
  1399. else
  1400. cout << " " << V.VerStr();
  1401. cout << " " << Plcy.GetPriority(Pkg) << endl;
  1402. for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++)
  1403. {
  1404. // Locate the associated index files so we can derive a description
  1405. pkgIndexFile *Indx;
  1406. if (SrcList->FindIndex(VF.File(),Indx) == false &&
  1407. _system->FindIndex(VF.File(),Indx) == false)
  1408. return _error->Error(_("Cache is out of sync, can't x-ref a package file"));
  1409. printf(_(" %4i %s\n"),Plcy.GetPriority(VF.File()),
  1410. Indx->Describe(true).c_str());
  1411. }
  1412. }
  1413. }
  1414. return true;
  1415. }
  1416. /*}}}*/
  1417. // Madison - Look a bit like katie's madison /*{{{*/
  1418. // ---------------------------------------------------------------------
  1419. /* */
  1420. bool Madison(CommandLine &CmdL)
  1421. {
  1422. if (SrcList == 0)
  1423. return _error->Error("Generate must be enabled for this function");
  1424. SrcList->ReadMainList();
  1425. pkgCache &Cache = *GCache;
  1426. // Create the text record parsers
  1427. pkgSrcRecords SrcRecs(*SrcList);
  1428. if (_error->PendingError() == true)
  1429. return false;
  1430. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  1431. {
  1432. pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
  1433. if (Pkg.end() == false)
  1434. {
  1435. for (pkgCache::VerIterator V = Pkg.VersionList(); V.end() == false; V++)
  1436. {
  1437. for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; VF++)
  1438. {
  1439. // This might be nice, but wouldn't uniquely identify the source -mdz
  1440. // if (VF.File().Archive() != 0)
  1441. // {
  1442. // cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
  1443. // << VF.File().Archive() << endl;
  1444. // }
  1445. // Locate the associated index files so we can derive a description
  1446. for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); S++)
  1447. {
  1448. vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles();
  1449. for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin();
  1450. IF != Indexes->end(); IF++)
  1451. {
  1452. if ((*IF)->FindInCache(*(VF.File().Cache())) == VF.File())
  1453. {
  1454. cout << setw(10) << Pkg.Name() << " | " << setw(10) << V.VerStr() << " | "
  1455. << (*IF)->Describe(true) << endl;
  1456. }
  1457. }
  1458. }
  1459. }
  1460. }
  1461. }
  1462. SrcRecs.Restart();
  1463. pkgSrcRecords::Parser *SrcParser;
  1464. while ((SrcParser = SrcRecs.Find(*I,false)) != 0)
  1465. {
  1466. // Maybe support Release info here too eventually
  1467. cout << setw(10) << SrcParser->Package() << " | "
  1468. << setw(10) << SrcParser->Version() << " | "
  1469. << SrcParser->Index().Describe(true) << endl;
  1470. }
  1471. }
  1472. return true;
  1473. }
  1474. /*}}}*/
  1475. // GenCaches - Call the main cache generator /*{{{*/
  1476. // ---------------------------------------------------------------------
  1477. /* */
  1478. bool GenCaches(CommandLine &Cmd)
  1479. {
  1480. OpTextProgress Progress(*_config);
  1481. pkgSourceList List;
  1482. if (List.ReadMainList() == false)
  1483. return false;
  1484. return pkgMakeStatusCache(List,Progress);
  1485. }
  1486. /*}}}*/
  1487. // ShowHelp - Show a help screen /*{{{*/
  1488. // ---------------------------------------------------------------------
  1489. /* */
  1490. bool ShowHelp(CommandLine &Cmd)
  1491. {
  1492. ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION,
  1493. COMMON_OS,COMMON_CPU,__DATE__,__TIME__);
  1494. if (_config->FindB("version") == true)
  1495. return true;
  1496. cout <<
  1497. _("Usage: apt-cache [options] command\n"
  1498. " apt-cache [options] add file1 [file2 ...]\n"
  1499. " apt-cache [options] showpkg pkg1 [pkg2 ...]\n"
  1500. " apt-cache [options] showsrc pkg1 [pkg2 ...]\n"
  1501. "\n"
  1502. "apt-cache is a low-level tool used to manipulate APT's binary\n"
  1503. "cache files, and query information from them\n"
  1504. "\n"
  1505. "Commands:\n"
  1506. " add - Add a package file to the source cache\n"
  1507. " gencaches - Build both the package and source cache\n"
  1508. " showpkg - Show some general information for a single package\n"
  1509. " showsrc - Show source records\n"
  1510. " stats - Show some basic statistics\n"
  1511. " dump - Show the entire file in a terse form\n"
  1512. " dumpavail - Print an available file to stdout\n"
  1513. " unmet - Show unmet dependencies\n"
  1514. " search - Search the package list for a regex pattern\n"
  1515. " show - Show a readable record for the package\n"
  1516. " depends - Show raw dependency information for a package\n"
  1517. " rdepends - Show reverse dependency information for a package\n"
  1518. " pkgnames - List the names of all packages\n"
  1519. " dotty - Generate package graphs for GraphVis\n"
  1520. " xvcg - Generate package graphs for xvcg\n"
  1521. " policy - Show policy settings\n"
  1522. "\n"
  1523. "Options:\n"
  1524. " -h This help text.\n"
  1525. " -p=? The package cache.\n"
  1526. " -s=? The source cache.\n"
  1527. " -q Disable progress indicator.\n"
  1528. " -i Show only important deps for the unmet command.\n"
  1529. " -c=? Read this configuration file\n"
  1530. " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
  1531. "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n");
  1532. return true;
  1533. }
  1534. /*}}}*/
  1535. // CacheInitialize - Initialize things for apt-cache /*{{{*/
  1536. // ---------------------------------------------------------------------
  1537. /* */
  1538. void CacheInitialize()
  1539. {
  1540. _config->Set("quiet",0);
  1541. _config->Set("help",false);
  1542. }
  1543. /*}}}*/
  1544. int main(int argc,const char *argv[])
  1545. {
  1546. CommandLine::Args Args[] = {
  1547. {'h',"help","help",0},
  1548. {'v',"version","version",0},
  1549. {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg},
  1550. {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg},
  1551. {'q',"quiet","quiet",CommandLine::IntLevel},
  1552. {'i',"important","APT::Cache::Important",0},
  1553. {'f',"full","APT::Cache::ShowFull",0},
  1554. {'g',"generate","APT::Cache::Generate",0},
  1555. {'a',"all-versions","APT::Cache::AllVersions",0},
  1556. {'n',"names-only","APT::Cache::NamesOnly",0},
  1557. {0,"all-names","APT::Cache::AllNames",0},
  1558. {0,"recurse","APT::Cache::RecurseDepends",0},
  1559. {'c',"config-file",0,CommandLine::ConfigFile},
  1560. {'o',"option",0,CommandLine::ArbItem},
  1561. {0,"installed","APT::Cache::Installed",0},
  1562. {0,0,0,0}};
  1563. CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp},
  1564. {"add",&DoAdd},
  1565. {"gencaches",&GenCaches},
  1566. {"showsrc",&ShowSrcPackage},
  1567. {0,0}};
  1568. CommandLine::Dispatch CmdsB[] = {{"showpkg",&DumpPackage},
  1569. {"stats",&Stats},
  1570. {"dump",&Dump},
  1571. {"dumpavail",&DumpAvail},
  1572. {"unmet",&UnMet},
  1573. {"search",&Search},
  1574. {"depends",&Depends},
  1575. {"rdepends",&RDepends},
  1576. {"dotty",&Dotty},
  1577. {"xvcg",&XVcg},
  1578. {"show",&ShowPackage},
  1579. {"pkgnames",&ShowPkgNames},
  1580. {"policy",&Policy},
  1581. {"madison",&Madison},
  1582. {0,0}};
  1583. CacheInitialize();
  1584. // Set up gettext support
  1585. setlocale(LC_ALL,"");
  1586. textdomain(PACKAGE);
  1587. // Parse the command line and initialize the package library
  1588. CommandLine CmdL(Args,_config);
  1589. if (pkgInitConfig(*_config) == false ||
  1590. CmdL.Parse(argc,argv) == false ||
  1591. pkgInitSystem(*_config,_system) == false)
  1592. {
  1593. _error->DumpErrors();
  1594. return 100;
  1595. }
  1596. // See if the help should be shown
  1597. if (_config->FindB("help") == true ||
  1598. CmdL.FileSize() == 0)
  1599. {
  1600. ShowHelp(CmdL);
  1601. return 0;
  1602. }
  1603. // Deal with stdout not being a tty
  1604. if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1)
  1605. _config->Set("quiet","1");
  1606. if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false)
  1607. {
  1608. MMap *Map = 0;
  1609. if (_config->FindB("APT::Cache::Generate",true) == false)
  1610. {
  1611. Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"),
  1612. FileFd::ReadOnly),MMap::Public|MMap::ReadOnly);
  1613. }
  1614. else
  1615. {
  1616. // Open the cache file
  1617. SrcList = new pkgSourceList;
  1618. SrcList->ReadMainList();
  1619. // Generate it and map it
  1620. OpProgress Prog;
  1621. pkgMakeStatusCache(*SrcList,Prog,&Map,true);
  1622. }
  1623. if (_error->PendingError() == false)
  1624. {
  1625. pkgCache Cache(Map);
  1626. GCache = &Cache;
  1627. if (_error->PendingError() == false)
  1628. CmdL.DispatchArg(CmdsB);
  1629. }
  1630. delete Map;
  1631. }
  1632. // Print any errors or warnings found during parsing
  1633. if (_error->empty() == false)
  1634. {
  1635. bool Errors = _error->PendingError();
  1636. _error->DumpErrors();
  1637. return Errors == true?100:0;
  1638. }
  1639. return 0;
  1640. }