apt-cache.cc 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: apt-cache.cc,v 1.45 2001/02/22 06:26:27 jgg 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 <iostream.h>
  29. #include <unistd.h>
  30. #include <errno.h>
  31. #include <regex.h>
  32. #include <stdio.h>
  33. /*}}}*/
  34. pkgCache *GCache = 0;
  35. // LocalitySort - Sort a version list by package file locality /*{{{*/
  36. // ---------------------------------------------------------------------
  37. /* */
  38. int LocalityCompare(const void *a, const void *b)
  39. {
  40. pkgCache::VerFile *A = *(pkgCache::VerFile **)a;
  41. pkgCache::VerFile *B = *(pkgCache::VerFile **)b;
  42. if (A == 0 && B == 0)
  43. return 0;
  44. if (A == 0)
  45. return 1;
  46. if (B == 0)
  47. return -1;
  48. if (A->File == B->File)
  49. return A->Offset - B->Offset;
  50. return A->File - B->File;
  51. }
  52. void LocalitySort(pkgCache::VerFile **begin,
  53. unsigned long Count,size_t Size)
  54. {
  55. qsort(begin,Count,Size,LocalityCompare);
  56. }
  57. /*}}}*/
  58. // UnMet - Show unmet dependencies /*{{{*/
  59. // ---------------------------------------------------------------------
  60. /* */
  61. bool UnMet(CommandLine &CmdL)
  62. {
  63. pkgCache &Cache = *GCache;
  64. bool Important = _config->FindB("APT::Cache::Important",false);
  65. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  66. {
  67. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
  68. {
  69. bool Header = false;
  70. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false;)
  71. {
  72. // Collect or groups
  73. pkgCache::DepIterator Start;
  74. pkgCache::DepIterator End;
  75. D.GlobOr(Start,End);
  76. // Skip conflicts and replaces
  77. if (End->Type != pkgCache::Dep::PreDepends &&
  78. End->Type != pkgCache::Dep::Depends &&
  79. End->Type != pkgCache::Dep::Suggests &&
  80. End->Type != pkgCache::Dep::Recommends)
  81. continue;
  82. // Important deps only
  83. if (Important == true)
  84. if (End->Type != pkgCache::Dep::PreDepends &&
  85. End->Type != pkgCache::Dep::Depends)
  86. continue;
  87. // Verify the or group
  88. bool OK = false;
  89. pkgCache::DepIterator RealStart = Start;
  90. do
  91. {
  92. // See if this dep is Ok
  93. pkgCache::Version **VList = Start.AllTargets();
  94. if (*VList != 0)
  95. {
  96. OK = true;
  97. delete [] VList;
  98. break;
  99. }
  100. delete [] VList;
  101. if (Start == End)
  102. break;
  103. Start++;
  104. }
  105. while (1);
  106. // The group is OK
  107. if (OK == true)
  108. continue;
  109. // Oops, it failed..
  110. if (Header == false)
  111. ioprintf(cout,_("Package %s version %s has an unmet dep:\n"),
  112. P.Name(),V.VerStr());
  113. Header = true;
  114. // Print out the dep type
  115. cout << " " << End.DepType() << ": ";
  116. // Show the group
  117. Start = RealStart;
  118. do
  119. {
  120. cout << Start.TargetPkg().Name();
  121. if (Start.TargetVer() != 0)
  122. cout << " (" << Start.CompType() << " " << Start.TargetVer() <<
  123. ")";
  124. if (Start == End)
  125. break;
  126. cout << " | ";
  127. Start++;
  128. }
  129. while (1);
  130. cout << endl;
  131. }
  132. }
  133. }
  134. return true;
  135. }
  136. /*}}}*/
  137. // DumpPackage - Show a dump of a package record /*{{{*/
  138. // ---------------------------------------------------------------------
  139. /* */
  140. bool DumpPackage(CommandLine &CmdL)
  141. {
  142. pkgCache &Cache = *GCache;
  143. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  144. {
  145. pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
  146. if (Pkg.end() == true)
  147. {
  148. _error->Warning(_("Unable to locate package %s"),*I);
  149. continue;
  150. }
  151. cout << "Package: " << Pkg.Name() << endl;
  152. cout << "Versions: " << endl;
  153. for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
  154. {
  155. cout << Cur.VerStr();
  156. for (pkgCache::VerFileIterator Vf = Cur.FileList(); Vf.end() == false; Vf++)
  157. cout << "(" << Vf.File().FileName() << ")";
  158. cout << endl;
  159. }
  160. cout << endl;
  161. cout << "Reverse Depends: " << endl;
  162. for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() != true; D++)
  163. {
  164. cout << " " << D.ParentPkg().Name() << ',' << D.TargetPkg().Name();
  165. if (D->Version != 0)
  166. cout << ' ' << D.TargetVer() << endl;
  167. else
  168. cout << endl;
  169. }
  170. cout << "Dependencies: " << endl;
  171. for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
  172. {
  173. cout << Cur.VerStr() << " - ";
  174. for (pkgCache::DepIterator Dep = Cur.DependsList(); Dep.end() != true; Dep++)
  175. cout << Dep.TargetPkg().Name() << " (" << (int)Dep->CompareOp << " " << Dep.TargetVer() << ") ";
  176. cout << endl;
  177. }
  178. cout << "Provides: " << endl;
  179. for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
  180. {
  181. cout << Cur.VerStr() << " - ";
  182. for (pkgCache::PrvIterator Prv = Cur.ProvidesList(); Prv.end() != true; Prv++)
  183. cout << Prv.ParentPkg().Name() << " ";
  184. cout << endl;
  185. }
  186. cout << "Reverse Provides: " << endl;
  187. for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; Prv++)
  188. cout << Prv.OwnerPkg().Name() << " " << Prv.OwnerVer().VerStr() << endl;
  189. }
  190. return true;
  191. }
  192. /*}}}*/
  193. // Stats - Dump some nice statistics /*{{{*/
  194. // ---------------------------------------------------------------------
  195. /* */
  196. bool Stats(CommandLine &Cmd)
  197. {
  198. pkgCache &Cache = *GCache;
  199. cout << _("Total Package Names : ") << Cache.Head().PackageCount << " (" <<
  200. SizeToStr(Cache.Head().PackageCount*Cache.Head().PackageSz) << ')' << endl;
  201. int Normal = 0;
  202. int Virtual = 0;
  203. int NVirt = 0;
  204. int DVirt = 0;
  205. int Missing = 0;
  206. pkgCache::PkgIterator I = Cache.PkgBegin();
  207. for (;I.end() != true; I++)
  208. {
  209. if (I->VersionList != 0 && I->ProvidesList == 0)
  210. {
  211. Normal++;
  212. continue;
  213. }
  214. if (I->VersionList != 0 && I->ProvidesList != 0)
  215. {
  216. NVirt++;
  217. continue;
  218. }
  219. if (I->VersionList == 0 && I->ProvidesList != 0)
  220. {
  221. // Only 1 provides
  222. if (I.ProvidesList()->NextProvides == 0)
  223. {
  224. DVirt++;
  225. }
  226. else
  227. Virtual++;
  228. continue;
  229. }
  230. if (I->VersionList == 0 && I->ProvidesList == 0)
  231. {
  232. Missing++;
  233. continue;
  234. }
  235. }
  236. cout << _(" Normal Packages: ") << Normal << endl;
  237. cout << _(" Pure Virtual Packages: ") << Virtual << endl;
  238. cout << _(" Single Virtual Packages: ") << DVirt << endl;
  239. cout << _(" Mixed Virtual Packages: ") << NVirt << endl;
  240. cout << _(" Missing: ") << Missing << endl;
  241. cout << _("Total Distinct Versions: ") << Cache.Head().VersionCount << " (" <<
  242. SizeToStr(Cache.Head().VersionCount*Cache.Head().VersionSz) << ')' << endl;
  243. cout << _("Total Dependencies: ") << Cache.Head().DependsCount << " (" <<
  244. SizeToStr(Cache.Head().DependsCount*Cache.Head().DependencySz) << ')' << endl;
  245. cout << _("Total Ver/File relations: ") << Cache.Head().VerFileCount << " (" <<
  246. SizeToStr(Cache.Head().VerFileCount*Cache.Head().VerFileSz) << ')' << endl;
  247. cout << _("Total Provides Mappings: ") << Cache.Head().ProvidesCount << " (" <<
  248. SizeToStr(Cache.Head().ProvidesCount*Cache.Head().ProvidesSz) << ')' << endl;
  249. // String list stats
  250. unsigned long Size = 0;
  251. unsigned long Count = 0;
  252. for (pkgCache::StringItem *I = Cache.StringItemP + Cache.Head().StringList;
  253. I!= Cache.StringItemP; I = Cache.StringItemP + I->NextItem)
  254. {
  255. Count++;
  256. Size += strlen(Cache.StrP + I->String) + 1;
  257. }
  258. cout << _("Total Globbed Strings: ") << Count << " (" << SizeToStr(Size) << ')' << endl;
  259. unsigned long DepVerSize = 0;
  260. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  261. {
  262. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
  263. {
  264. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++)
  265. {
  266. if (D->Version != 0)
  267. DepVerSize += strlen(D.TargetVer()) + 1;
  268. }
  269. }
  270. }
  271. cout << _("Total Dependency Version space: ") << SizeToStr(DepVerSize) << endl;
  272. unsigned long Slack = 0;
  273. for (int I = 0; I != 7; I++)
  274. Slack += Cache.Head().Pools[I].ItemSize*Cache.Head().Pools[I].Count;
  275. cout << _("Total Slack space: ") << SizeToStr(Slack) << endl;
  276. unsigned long Total = 0;
  277. Total = Slack + Size + Cache.Head().DependsCount*Cache.Head().DependencySz +
  278. Cache.Head().VersionCount*Cache.Head().VersionSz +
  279. Cache.Head().PackageCount*Cache.Head().PackageSz +
  280. Cache.Head().VerFileCount*Cache.Head().VerFileSz +
  281. Cache.Head().ProvidesCount*Cache.Head().ProvidesSz;
  282. cout << _("Total Space Accounted for: ") << SizeToStr(Total) << endl;
  283. return true;
  284. }
  285. /*}}}*/
  286. // Dump - show everything /*{{{*/
  287. // ---------------------------------------------------------------------
  288. /* This is worthless except fer debugging things */
  289. bool Dump(CommandLine &Cmd)
  290. {
  291. pkgCache &Cache = *GCache;
  292. cout << "Using Versioning System: " << Cache.VS->Label << endl;
  293. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  294. {
  295. cout << "Package: " << P.Name() << endl;
  296. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
  297. {
  298. cout << " Version: " << V.VerStr() << endl;
  299. cout << " File: " << V.FileList().File().FileName() << endl;
  300. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++)
  301. cout << " Depends: " << D.TargetPkg().Name() << ' ' << D.TargetVer() << endl;
  302. }
  303. }
  304. for (pkgCache::PkgFileIterator F = Cache.FileBegin(); F.end() == false; F++)
  305. {
  306. cout << "File: " << F.FileName() << endl;
  307. cout << " Type: " << F.IndexType() << endl;
  308. cout << " Size: " << F->Size << endl;
  309. cout << " ID: " << F->ID << endl;
  310. cout << " Flags: " << F->Flags << endl;
  311. cout << " Time: " << TimeRFC1123(F->mtime) << endl;
  312. cout << " Archive: " << F.Archive() << endl;
  313. cout << " Component: " << F.Component() << endl;
  314. cout << " Version: " << F.Version() << endl;
  315. cout << " Origin: " << F.Origin() << endl;
  316. cout << " Site: " << F.Site() << endl;
  317. cout << " Label: " << F.Label() << endl;
  318. cout << " Architecture: " << F.Architecture() << endl;
  319. }
  320. return true;
  321. }
  322. /*}}}*/
  323. // DumpAvail - Print out the available list /*{{{*/
  324. // ---------------------------------------------------------------------
  325. /* This is needed to make dpkg --merge happy.. I spent a bit of time to
  326. make this run really fast, perhaps I went a little overboard.. */
  327. bool DumpAvail(CommandLine &Cmd)
  328. {
  329. pkgCache &Cache = *GCache;
  330. pkgPolicy Plcy(&Cache);
  331. if (ReadPinFile(Plcy) == false)
  332. return false;
  333. pkgCache::VerFile **VFList = new pkgCache::VerFile *[Cache.HeaderP->PackageCount];
  334. memset(VFList,0,sizeof(*VFList)*Cache.HeaderP->PackageCount);
  335. // Map versions that we want to write out onto the VerList array.
  336. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  337. {
  338. if (P->VersionList == 0)
  339. continue;
  340. /* Find the proper version to use. If the policy says there are no
  341. possible selections we return the installed version, if available..
  342. This prevents dselect from making it obsolete. */
  343. pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
  344. if (V.end() == true)
  345. {
  346. if (P->CurrentVer == 0)
  347. continue;
  348. V = P.CurrentVer();
  349. }
  350. pkgCache::VerFileIterator VF = V.FileList();
  351. for (; VF.end() == false ; VF++)
  352. if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0)
  353. break;
  354. /* Okay, here we have a bit of a problem.. The policy has selected the
  355. currently installed package - however it only exists in the
  356. status file.. We need to write out something or dselect will mark
  357. the package as obsolete! Thus we emit the status file entry, but
  358. below we remove the status line to make it valid for the
  359. available file. However! We only do this if their do exist *any*
  360. non-source versions of the package - that way the dselect obsolete
  361. handling works OK. */
  362. if (VF.end() == true)
  363. {
  364. for (pkgCache::VerIterator Cur = P.VersionList(); Cur.end() != true; Cur++)
  365. {
  366. for (VF = Cur.FileList(); VF.end() == false; VF++)
  367. {
  368. if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 0)
  369. {
  370. VF = V.FileList();
  371. break;
  372. }
  373. }
  374. if (VF.end() == false)
  375. break;
  376. }
  377. }
  378. VFList[P->ID] = VF;
  379. }
  380. LocalitySort(VFList,Cache.HeaderP->PackageCount,sizeof(*VFList));
  381. // Iterate over all the package files and write them out.
  382. char *Buffer = new char[Cache.HeaderP->MaxVerFileSize+10];
  383. for (pkgCache::VerFile **J = VFList; *J != 0;)
  384. {
  385. pkgCache::PkgFileIterator File(Cache,(*J)->File + Cache.PkgFileP);
  386. if (File.IsOk() == false)
  387. {
  388. _error->Error(_("Package file %s is out of sync."),File.FileName());
  389. break;
  390. }
  391. FileFd PkgF(File.FileName(),FileFd::ReadOnly);
  392. if (_error->PendingError() == true)
  393. break;
  394. /* Write all of the records from this package file, since we
  395. already did locality sorting we can now just seek through the
  396. file in read order. We apply 1 more optimization here, since often
  397. there will be < 1 byte gaps between records (for the \n) we read that
  398. into the next buffer and offset a bit.. */
  399. unsigned long Pos = 0;
  400. for (; *J != 0; J++)
  401. {
  402. if ((*J)->File + Cache.PkgFileP != File)
  403. break;
  404. const pkgCache::VerFile &VF = **J;
  405. // Read the record and then write it out again.
  406. unsigned long Jitter = VF.Offset - Pos;
  407. if (Jitter > 8)
  408. {
  409. if (PkgF.Seek(VF.Offset) == false)
  410. break;
  411. Jitter = 0;
  412. }
  413. if (PkgF.Read(Buffer,VF.Size + Jitter) == false)
  414. break;
  415. Buffer[VF.Size + Jitter] = '\n';
  416. // See above..
  417. if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource)
  418. {
  419. pkgTagSection Tags;
  420. TFRewriteData RW[] = {{"Status",0},{}};
  421. const char *Zero = 0;
  422. if (Tags.Scan(Buffer+Jitter,VF.Size+1) == false ||
  423. TFRewrite(stdout,Tags,&Zero,RW) == false)
  424. {
  425. _error->Error("Internal Error, Unable to parse a package record");
  426. break;
  427. }
  428. fputc('\n',stdout);
  429. }
  430. else
  431. {
  432. if (fwrite(Buffer+Jitter,VF.Size+1,1,stdout) != 1)
  433. break;
  434. }
  435. Pos = VF.Offset + VF.Size;
  436. }
  437. fflush(stdout);
  438. if (_error->PendingError() == true)
  439. break;
  440. }
  441. delete [] Buffer;
  442. delete [] VFList;
  443. return !_error->PendingError();
  444. }
  445. /*}}}*/
  446. // Depends - Print out a dependency tree /*{{{*/
  447. // ---------------------------------------------------------------------
  448. /* */
  449. bool Depends(CommandLine &CmdL)
  450. {
  451. pkgCache &Cache = *GCache;
  452. SPtrArray<unsigned> Colours = new unsigned[Cache.Head().PackageCount];
  453. memset(Colours,0,sizeof(*Colours)*Cache.Head().PackageCount);
  454. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  455. {
  456. pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
  457. if (Pkg.end() == true)
  458. {
  459. _error->Warning(_("Unable to locate package %s"),*I);
  460. continue;
  461. }
  462. Colours[Pkg->ID] = 1;
  463. }
  464. bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false);
  465. bool DidSomething;
  466. do
  467. {
  468. DidSomething = false;
  469. for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
  470. {
  471. if (Colours[Pkg->ID] != 1)
  472. continue;
  473. Colours[Pkg->ID] = 2;
  474. DidSomething = true;
  475. pkgCache::VerIterator Ver = Pkg.VersionList();
  476. if (Ver.end() == true)
  477. {
  478. cout << '<' << Pkg.Name() << '>' << endl;
  479. continue;
  480. }
  481. cout << Pkg.Name() << endl;
  482. for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
  483. {
  484. if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
  485. cout << " |";
  486. else
  487. cout << " ";
  488. // Show the package
  489. pkgCache::PkgIterator Trg = D.TargetPkg();
  490. if (Trg->VersionList == 0)
  491. cout << D.DepType() << ": <" << Trg.Name() << ">" << endl;
  492. else
  493. cout << D.DepType() << ": " << Trg.Name() << endl;
  494. if (Recurse == true)
  495. Colours[D.TargetPkg()->ID]++;
  496. // Display all solutions
  497. SPtrArray<pkgCache::Version *> List = D.AllTargets();
  498. pkgPrioSortList(Cache,List);
  499. for (pkgCache::Version **I = List; *I != 0; I++)
  500. {
  501. pkgCache::VerIterator V(Cache,*I);
  502. if (V != Cache.VerP + V.ParentPkg()->VersionList ||
  503. V->ParentPkg == D->Package)
  504. continue;
  505. cout << " " << V.ParentPkg().Name() << endl;
  506. if (Recurse == true)
  507. Colours[D.ParentPkg()->ID]++;
  508. }
  509. }
  510. }
  511. }
  512. while (DidSomething == true);
  513. return true;
  514. }
  515. /*}}}*/
  516. // Dotty - Generate a graph for Dotty /*{{{*/
  517. // ---------------------------------------------------------------------
  518. /* Dotty is the graphvis program for generating graphs. It is a fairly
  519. simple queuing algorithm that just writes dependencies and nodes.
  520. http://www.research.att.com/sw/tools/graphviz/ */
  521. bool Dotty(CommandLine &CmdL)
  522. {
  523. pkgCache &Cache = *GCache;
  524. bool GivenOnly = _config->FindB("APT::Cache::GivenOnly",false);
  525. /* Normal packages are boxes
  526. Pure Provides are triangles
  527. Mixed are diamonds
  528. Hexagons are missing packages*/
  529. const char *Shapes[] = {"hexagon","triangle","box","diamond"};
  530. /* Initialize the list of packages to show.
  531. 1 = To Show
  532. 2 = To Show no recurse
  533. 3 = Emitted no recurse
  534. 4 = Emitted
  535. 0 = None */
  536. enum States {None=0, ToShow, ToShowNR, DoneNR, Done};
  537. enum TheFlags {ForceNR=(1<<0)};
  538. unsigned char *Show = new unsigned char[Cache.Head().PackageCount];
  539. unsigned char *Flags = new unsigned char[Cache.Head().PackageCount];
  540. unsigned char *ShapeMap = new unsigned char[Cache.Head().PackageCount];
  541. // Show everything if no arguments given
  542. if (CmdL.FileList[1] == 0)
  543. for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
  544. Show[I] = ToShow;
  545. else
  546. for (unsigned long I = 0; I != Cache.Head().PackageCount; I++)
  547. Show[I] = None;
  548. memset(Flags,0,sizeof(*Flags)*Cache.Head().PackageCount);
  549. // Map the shapes
  550. for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
  551. {
  552. if (Pkg->VersionList == 0)
  553. {
  554. // Missing
  555. if (Pkg->ProvidesList == 0)
  556. ShapeMap[Pkg->ID] = 0;
  557. else
  558. ShapeMap[Pkg->ID] = 1;
  559. }
  560. else
  561. {
  562. // Normal
  563. if (Pkg->ProvidesList == 0)
  564. ShapeMap[Pkg->ID] = 2;
  565. else
  566. ShapeMap[Pkg->ID] = 3;
  567. }
  568. }
  569. // Load the list of packages from the command line into the show list
  570. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  571. {
  572. // Process per-package flags
  573. string P = *I;
  574. bool Force = false;
  575. if (P.length() > 3)
  576. {
  577. if (P.end()[-1] == '^')
  578. {
  579. Force = true;
  580. P.erase(P.end()-1);
  581. }
  582. if (P.end()[-1] == ',')
  583. P.erase(P.end()-1);
  584. }
  585. // Locate the package
  586. pkgCache::PkgIterator Pkg = Cache.FindPkg(P);
  587. if (Pkg.end() == true)
  588. {
  589. _error->Warning(_("Unable to locate package %s"),*I);
  590. continue;
  591. }
  592. Show[Pkg->ID] = ToShow;
  593. if (Force == true)
  594. Flags[Pkg->ID] |= ForceNR;
  595. }
  596. // Little header
  597. printf("digraph packages {\n");
  598. printf("concentrate=true;\n");
  599. printf("size=\"30,40\";\n");
  600. bool Act = true;
  601. while (Act == true)
  602. {
  603. Act = false;
  604. for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
  605. {
  606. // See we need to show this package
  607. if (Show[Pkg->ID] == None || Show[Pkg->ID] >= DoneNR)
  608. continue;
  609. // Colour as done
  610. if (Show[Pkg->ID] == ToShowNR || (Flags[Pkg->ID] & ForceNR) == ForceNR)
  611. {
  612. // Pure Provides and missing packages have no deps!
  613. if (ShapeMap[Pkg->ID] == 0 || ShapeMap[Pkg->ID] == 1)
  614. Show[Pkg->ID] = Done;
  615. else
  616. Show[Pkg->ID] = DoneNR;
  617. }
  618. else
  619. Show[Pkg->ID] = Done;
  620. Act = true;
  621. // No deps to map out
  622. if (Pkg->VersionList == 0 || Show[Pkg->ID] == DoneNR)
  623. continue;
  624. pkgCache::VerIterator Ver = Pkg.VersionList();
  625. for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++)
  626. {
  627. // See if anything can meet this dep
  628. // Walk along the actual package providing versions
  629. bool Hit = false;
  630. pkgCache::PkgIterator DPkg = D.TargetPkg();
  631. for (pkgCache::VerIterator I = DPkg.VersionList();
  632. I.end() == false && Hit == false; I++)
  633. {
  634. if (Cache.VS->CheckDep(I.VerStr(),D->CompareOp,D.TargetVer()) == true)
  635. Hit = true;
  636. }
  637. // Follow all provides
  638. for (pkgCache::PrvIterator I = DPkg.ProvidesList();
  639. I.end() == false && Hit == false; I++)
  640. {
  641. if (Cache.VS->CheckDep(I.ProvideVersion(),D->CompareOp,D.TargetVer()) == false)
  642. Hit = true;
  643. }
  644. // Only graph critical deps
  645. if (D.IsCritical() == true)
  646. {
  647. printf("\"%s\" -> \"%s\"",Pkg.Name(),D.TargetPkg().Name());
  648. // Colour the node for recursion
  649. if (Show[D.TargetPkg()->ID] <= DoneNR)
  650. {
  651. /* If a conflicts does not meet anything in the database
  652. then show the relation but do not recurse */
  653. if (Hit == false &&
  654. (D->Type == pkgCache::Dep::Conflicts ||
  655. D->Type == pkgCache::Dep::Obsoletes))
  656. {
  657. if (Show[D.TargetPkg()->ID] == None &&
  658. Show[D.TargetPkg()->ID] != ToShow)
  659. Show[D.TargetPkg()->ID] = ToShowNR;
  660. }
  661. else
  662. {
  663. if (GivenOnly == true && Show[D.TargetPkg()->ID] != ToShow)
  664. Show[D.TargetPkg()->ID] = ToShowNR;
  665. else
  666. Show[D.TargetPkg()->ID] = ToShow;
  667. }
  668. }
  669. // Edge colour
  670. switch(D->Type)
  671. {
  672. case pkgCache::Dep::Conflicts:
  673. case pkgCache::Dep::Obsoletes:
  674. printf("[color=springgreen];\n");
  675. break;
  676. case pkgCache::Dep::PreDepends:
  677. printf("[color=blue];\n");
  678. break;
  679. default:
  680. printf(";\n");
  681. break;
  682. }
  683. }
  684. }
  685. }
  686. }
  687. /* Draw the box colours after the fact since we can not tell what colour
  688. they should be until everything is finished drawing */
  689. for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++)
  690. {
  691. if (Show[Pkg->ID] < DoneNR)
  692. continue;
  693. // Orange box for early recursion stoppage
  694. if (Show[Pkg->ID] == DoneNR)
  695. printf("\"%s\" [color=orange,shape=%s];\n",Pkg.Name(),
  696. Shapes[ShapeMap[Pkg->ID]]);
  697. else
  698. printf("\"%s\" [shape=%s];\n",Pkg.Name(),
  699. Shapes[ShapeMap[Pkg->ID]]);
  700. }
  701. printf("}\n");
  702. return true;
  703. }
  704. /*}}}*/
  705. // DoAdd - Perform an adding operation /*{{{*/
  706. // ---------------------------------------------------------------------
  707. /* */
  708. bool DoAdd(CommandLine &CmdL)
  709. {
  710. return _error->Error("Unimplemented");
  711. #if 0
  712. // Make sure there is at least one argument
  713. if (CmdL.FileSize() <= 1)
  714. return _error->Error("You must give at least one file name");
  715. // Open the cache
  716. FileFd CacheF(_config->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny);
  717. if (_error->PendingError() == true)
  718. return false;
  719. DynamicMMap Map(CacheF,MMap::Public);
  720. if (_error->PendingError() == true)
  721. return false;
  722. OpTextProgress Progress(*_config);
  723. pkgCacheGenerator Gen(Map,Progress);
  724. if (_error->PendingError() == true)
  725. return false;
  726. unsigned long Length = CmdL.FileSize() - 1;
  727. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  728. {
  729. Progress.OverallProgress(I - CmdL.FileList,Length,1,"Generating cache");
  730. Progress.SubProgress(Length);
  731. // Do the merge
  732. FileFd TagF(*I,FileFd::ReadOnly);
  733. debListParser Parser(TagF);
  734. if (_error->PendingError() == true)
  735. return _error->Error("Problem opening %s",*I);
  736. if (Gen.SelectFile(*I,"") == false)
  737. return _error->Error("Problem with SelectFile");
  738. if (Gen.MergeList(Parser) == false)
  739. return _error->Error("Problem with MergeList");
  740. }
  741. Progress.Done();
  742. GCache = &Gen.GetCache();
  743. Stats(CmdL);
  744. return true;
  745. #endif
  746. }
  747. /*}}}*/
  748. // DisplayRecord - Displays the complete record for the package /*{{{*/
  749. // ---------------------------------------------------------------------
  750. /* This displays the package record from the proper package index file.
  751. It is not used by DumpAvail for performance reasons. */
  752. bool DisplayRecord(pkgCache::VerIterator V)
  753. {
  754. // Find an appropriate file
  755. pkgCache::VerFileIterator Vf = V.FileList();
  756. for (; Vf.end() == false; Vf++)
  757. if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
  758. break;
  759. if (Vf.end() == true)
  760. Vf = V.FileList();
  761. // Check and load the package list file
  762. pkgCache::PkgFileIterator I = Vf.File();
  763. if (I.IsOk() == false)
  764. return _error->Error(_("Package file %s is out of sync."),I.FileName());
  765. FileFd PkgF(I.FileName(),FileFd::ReadOnly);
  766. if (_error->PendingError() == true)
  767. return false;
  768. // Read the record and then write it out again.
  769. unsigned char *Buffer = new unsigned char[GCache->HeaderP->MaxVerFileSize+1];
  770. Buffer[V.FileList()->Size] = '\n';
  771. if (PkgF.Seek(V.FileList()->Offset) == false ||
  772. PkgF.Read(Buffer,V.FileList()->Size) == false ||
  773. write(STDOUT_FILENO,Buffer,V.FileList()->Size+1) != V.FileList()->Size+1)
  774. {
  775. delete [] Buffer;
  776. return false;
  777. }
  778. delete [] Buffer;
  779. return true;
  780. }
  781. /*}}}*/
  782. // Search - Perform a search /*{{{*/
  783. // ---------------------------------------------------------------------
  784. /* This searches the package names and pacakge descriptions for a pattern */
  785. struct ExVerFile
  786. {
  787. pkgCache::VerFile *Vf;
  788. bool NameMatch;
  789. };
  790. bool Search(CommandLine &CmdL)
  791. {
  792. pkgCache &Cache = *GCache;
  793. bool ShowFull = _config->FindB("APT::Cache::ShowFull",false);
  794. bool NamesOnly = _config->FindB("APT::Cache::NamesOnly",false);
  795. unsigned NumPatterns = CmdL.FileSize() -1;
  796. pkgDepCache::Policy Plcy;
  797. // Make sure there is at least one argument
  798. if (NumPatterns < 1)
  799. return _error->Error(_("You must give exactly one pattern"));
  800. // Compile the regex pattern
  801. regex_t *Patterns = new regex_t[NumPatterns];
  802. memset(Patterns,0,sizeof(*Patterns)*NumPatterns);
  803. for (unsigned I = 0; I != NumPatterns; I++)
  804. {
  805. if (regcomp(&Patterns[I],CmdL.FileList[I+1],REG_EXTENDED | REG_ICASE |
  806. REG_NOSUB) != 0)
  807. {
  808. for (; I != 0; I--)
  809. regfree(&Patterns[I]);
  810. return _error->Error("Regex compilation error");
  811. }
  812. }
  813. // Create the text record parser
  814. pkgRecords Recs(Cache);
  815. if (_error->PendingError() == true)
  816. {
  817. for (unsigned I = 0; I != NumPatterns; I++)
  818. regfree(&Patterns[I]);
  819. return false;
  820. }
  821. ExVerFile *VFList = new ExVerFile[Cache.HeaderP->PackageCount+1];
  822. memset(VFList,0,sizeof(*VFList)*Cache.HeaderP->PackageCount+1);
  823. // Map versions that we want to write out onto the VerList array.
  824. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  825. {
  826. VFList[P->ID].NameMatch = NumPatterns != 0;
  827. for (unsigned I = 0; I != NumPatterns; I++)
  828. {
  829. if (regexec(&Patterns[I],P.Name(),0,0,0) == 0)
  830. VFList[P->ID].NameMatch &= true;
  831. else
  832. VFList[P->ID].NameMatch = false;
  833. }
  834. // Doing names only, drop any that dont match..
  835. if (NamesOnly == true && VFList[P->ID].NameMatch == false)
  836. continue;
  837. // Find the proper version to use.
  838. pkgCache::VerIterator V = Plcy.GetCandidateVer(P);
  839. if (V.end() == true)
  840. continue;
  841. VFList[P->ID].Vf = V.FileList();
  842. }
  843. LocalitySort(&VFList->Vf,Cache.HeaderP->PackageCount,sizeof(*VFList));
  844. // Iterate over all the version records and check them
  845. for (ExVerFile *J = VFList; J->Vf != 0; J++)
  846. {
  847. pkgRecords::Parser &P = Recs.Lookup(pkgCache::VerFileIterator(Cache,J->Vf));
  848. bool Match = true;
  849. if (J->NameMatch == false)
  850. {
  851. string LongDesc = P.LongDesc();
  852. Match = NumPatterns != 0;
  853. for (unsigned I = 0; I != NumPatterns; I++)
  854. {
  855. if (regexec(&Patterns[I],LongDesc.c_str(),0,0,0) == 0)
  856. Match &= true;
  857. else
  858. Match = false;
  859. }
  860. }
  861. if (Match == true)
  862. {
  863. if (ShowFull == true)
  864. {
  865. const char *Start;
  866. const char *End;
  867. P.GetRec(Start,End);
  868. fwrite(Start,End-Start,1,stdout);
  869. putc('\n',stdout);
  870. }
  871. else
  872. printf("%s - %s\n",P.Name().c_str(),P.ShortDesc().c_str());
  873. }
  874. }
  875. delete [] VFList;
  876. for (unsigned I = 0; I != NumPatterns; I++)
  877. regfree(&Patterns[I]);
  878. if (ferror(stdout))
  879. return _error->Error("Write to stdout failed");
  880. return true;
  881. }
  882. /*}}}*/
  883. // ShowPackage - Dump the package record to the screen /*{{{*/
  884. // ---------------------------------------------------------------------
  885. /* */
  886. bool ShowPackage(CommandLine &CmdL)
  887. {
  888. pkgCache &Cache = *GCache;
  889. pkgDepCache::Policy Plcy;
  890. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  891. {
  892. pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
  893. if (Pkg.end() == true)
  894. {
  895. _error->Warning(_("Unable to locate package %s"),*I);
  896. continue;
  897. }
  898. // Find the proper version to use.
  899. if (_config->FindB("APT::Cache::AllVersions","true") == true)
  900. {
  901. pkgCache::VerIterator V;
  902. for (V = Pkg.VersionList(); V.end() == false; V++)
  903. {
  904. if (DisplayRecord(V) == false)
  905. return false;
  906. }
  907. }
  908. else
  909. {
  910. pkgCache::VerIterator V = Plcy.GetCandidateVer(Pkg);
  911. if (V.end() == true || V.FileList().end() == true)
  912. continue;
  913. if (DisplayRecord(V) == false)
  914. return false;
  915. }
  916. }
  917. return true;
  918. }
  919. /*}}}*/
  920. // ShowPkgNames - Show package names /*{{{*/
  921. // ---------------------------------------------------------------------
  922. /* This does a prefix match on the first argument */
  923. bool ShowPkgNames(CommandLine &CmdL)
  924. {
  925. pkgCache &Cache = *GCache;
  926. pkgCache::PkgIterator I = Cache.PkgBegin();
  927. bool All = _config->FindB("APT::Cache::AllNames","false");
  928. if (CmdL.FileList[1] != 0)
  929. {
  930. for (;I.end() != true; I++)
  931. {
  932. if (All == false && I->VersionList == 0)
  933. continue;
  934. if (strncmp(I.Name(),CmdL.FileList[1],strlen(CmdL.FileList[1])) == 0)
  935. cout << I.Name() << endl;
  936. }
  937. return true;
  938. }
  939. // Show all pkgs
  940. for (;I.end() != true; I++)
  941. {
  942. if (All == false && I->VersionList == 0)
  943. continue;
  944. cout << I.Name() << endl;
  945. }
  946. return true;
  947. }
  948. /*}}}*/
  949. // ShowSrcPackage - Show source package records /*{{{*/
  950. // ---------------------------------------------------------------------
  951. /* */
  952. bool ShowSrcPackage(CommandLine &CmdL)
  953. {
  954. pkgSourceList List;
  955. List.ReadMainList();
  956. // Create the text record parsers
  957. pkgSrcRecords SrcRecs(List);
  958. if (_error->PendingError() == true)
  959. return false;
  960. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  961. {
  962. SrcRecs.Restart();
  963. pkgSrcRecords::Parser *Parse;
  964. while ((Parse = SrcRecs.Find(*I,false)) != 0)
  965. cout << Parse->AsStr() << endl;;
  966. }
  967. return true;
  968. }
  969. /*}}}*/
  970. // GenCaches - Call the main cache generator /*{{{*/
  971. // ---------------------------------------------------------------------
  972. /* */
  973. bool GenCaches(CommandLine &Cmd)
  974. {
  975. OpTextProgress Progress(*_config);
  976. pkgSourceList List;
  977. if (List.ReadMainList() == false)
  978. return false;
  979. return pkgMakeStatusCache(List,Progress);
  980. }
  981. /*}}}*/
  982. // ShowHelp - Show a help screen /*{{{*/
  983. // ---------------------------------------------------------------------
  984. /* */
  985. bool ShowHelp(CommandLine &Cmd)
  986. {
  987. ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION,
  988. COMMON_OS,COMMON_CPU,__DATE__,__TIME__);
  989. cout <<
  990. _("Usage: apt-cache [options] command\n"
  991. " apt-cache [options] add file1 [file1 ...]\n"
  992. " apt-cache [options] showpkg pkg1 [pkg2 ...]\n"
  993. "\n"
  994. "apt-cache is a low-level tool used to manipulate APT's binary\n"
  995. "cache files, and query information from them\n"
  996. "\n"
  997. "Commands:\n"
  998. " add - Add an package file to the source cache\n"
  999. " gencaches - Build both the package and source cache\n"
  1000. " showpkg - Show some general information for a single package\n"
  1001. " stats - Show some basic statistics\n"
  1002. " dump - Show the entire file in a terse form\n"
  1003. " dumpavail - Print an available file to stdout\n"
  1004. " unmet - Show unmet dependencies\n"
  1005. " check - Check the cache a bit\n"
  1006. " search - Search the package list for a regex pattern\n"
  1007. " show - Show a readable record for the package\n"
  1008. " depends - Show raw dependency information for a package\n"
  1009. " pkgnames - List the names of all packages\n"
  1010. " dotty - Generate package graphs for GraphVis\n"
  1011. "\n"
  1012. "Options:\n"
  1013. " -h This help text.\n"
  1014. " -p=? The package cache.\n"
  1015. " -s=? The source cache.\n"
  1016. " -q Disable progress indicator.\n"
  1017. " -i Show only important deps for the unmet command.\n"
  1018. " -c=? Read this configuration file\n"
  1019. " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"
  1020. "See the apt-cache(8) and apt.conf(5) manual pages for more information.\n");
  1021. return true;
  1022. }
  1023. /*}}}*/
  1024. // CacheInitialize - Initialize things for apt-cache /*{{{*/
  1025. // ---------------------------------------------------------------------
  1026. /* */
  1027. void CacheInitialize()
  1028. {
  1029. _config->Set("quiet",0);
  1030. _config->Set("help",false);
  1031. }
  1032. /*}}}*/
  1033. int main(int argc,const char *argv[])
  1034. {
  1035. CommandLine::Args Args[] = {
  1036. {'h',"help","help",0},
  1037. {'v',"version","version",0},
  1038. {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg},
  1039. {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg},
  1040. {'q',"quiet","quiet",CommandLine::IntLevel},
  1041. {'i',"important","APT::Cache::Important",0},
  1042. {'f',"full","APT::Cache::ShowFull",0},
  1043. {'g',"generate","APT::Cache::Generate",0},
  1044. {'a',"all-versions","APT::Cache::AllVersions",0},
  1045. {0,"names-only","APT::Cache::NamesOnly",0},
  1046. {0,"all-names","APT::Cache::AllNames",0},
  1047. {0,"recurse","APT::Cache::RecurseDepends",0},
  1048. {'c',"config-file",0,CommandLine::ConfigFile},
  1049. {'o',"option",0,CommandLine::ArbItem},
  1050. {0,0,0,0}};
  1051. CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp},
  1052. {"add",&DoAdd},
  1053. {"gencaches",&GenCaches},
  1054. {"showsrc",&ShowSrcPackage},
  1055. {0,0}};
  1056. CommandLine::Dispatch CmdsB[] = {{"showpkg",&DumpPackage},
  1057. {"stats",&Stats},
  1058. {"dump",&Dump},
  1059. {"dumpavail",&DumpAvail},
  1060. {"unmet",&UnMet},
  1061. {"search",&Search},
  1062. {"depends",&Depends},
  1063. {"dotty",&Dotty},
  1064. {"show",&ShowPackage},
  1065. {"pkgnames",&ShowPkgNames},
  1066. {0,0}};
  1067. CacheInitialize();
  1068. // Parse the command line and initialize the package library
  1069. CommandLine CmdL(Args,_config);
  1070. if (pkgInitConfig(*_config) == false ||
  1071. CmdL.Parse(argc,argv) == false ||
  1072. pkgInitSystem(*_config,_system) == false)
  1073. {
  1074. _error->DumpErrors();
  1075. return 100;
  1076. }
  1077. // See if the help should be shown
  1078. if (_config->FindB("help") == true ||
  1079. CmdL.FileSize() == 0)
  1080. {
  1081. ShowHelp(CmdL);
  1082. return 0;
  1083. }
  1084. // Deal with stdout not being a tty
  1085. if (ttyname(STDOUT_FILENO) == 0 && _config->FindI("quiet",0) < 1)
  1086. _config->Set("quiet","1");
  1087. if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false)
  1088. {
  1089. MMap *Map;
  1090. if (_config->FindB("APT::Cache::Generate",true) == false)
  1091. {
  1092. Map = new MMap(*new FileFd(_config->FindFile("Dir::Cache::pkgcache"),
  1093. FileFd::ReadOnly),MMap::Public|MMap::ReadOnly);
  1094. }
  1095. else
  1096. {
  1097. // Open the cache file
  1098. pkgSourceList List;
  1099. List.ReadMainList();
  1100. // Generate it and map it
  1101. OpProgress Prog;
  1102. pkgMakeStatusCache(List,Prog,&Map,true);
  1103. }
  1104. if (_error->PendingError() == false)
  1105. {
  1106. pkgCache Cache(Map);
  1107. GCache = &Cache;
  1108. if (_error->PendingError() == false)
  1109. CmdL.DispatchArg(CmdsB);
  1110. }
  1111. delete Map;
  1112. }
  1113. // Print any errors or warnings found during parsing
  1114. if (_error->empty() == false)
  1115. {
  1116. bool Errors = _error->PendingError();
  1117. _error->DumpErrors();
  1118. return Errors == true?100:0;
  1119. }
  1120. return 0;
  1121. }