apt-get.cc 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: apt-get.cc,v 1.156 2004/08/28 01:05:16 mdz Exp $
  4. /* ######################################################################
  5. apt-get - Cover for dpkg
  6. This is an allout cover for dpkg implementing a safer front end. It is
  7. based largely on libapt-pkg.
  8. The syntax is different,
  9. apt-get [opt] command [things]
  10. Where command is:
  11. update - Resyncronize the package files from their sources
  12. upgrade - Smart-Download the newest versions of all packages
  13. dselect-upgrade - Follows dselect's changes to the Status: field
  14. and installes new and removes old packages
  15. dist-upgrade - Powerful upgrader designed to handle the issues with
  16. a new distribution.
  17. install - Download and install a given package (by name, not by .deb)
  18. check - Update the package cache and check for broken packages
  19. clean - Erase the .debs downloaded to /var/cache/apt/archives and
  20. the partial dir too
  21. ##################################################################### */
  22. /*}}}*/
  23. // Include Files /*{{{*/
  24. #include <config.h>
  25. #include <apt-pkg/acquire-item.h>
  26. #include <apt-pkg/algorithms.h>
  27. #include <apt-pkg/aptconfiguration.h>
  28. #include <apt-pkg/cachefile.h>
  29. #include <apt-pkg/cacheset.h>
  30. #include <apt-pkg/clean.h>
  31. #include <apt-pkg/cmndline.h>
  32. #include <apt-pkg/debmetaindex.h>
  33. #include <apt-pkg/depcache.h>
  34. #include <apt-pkg/error.h>
  35. #include <apt-pkg/fileutl.h>
  36. #include <apt-pkg/indexfile.h>
  37. #include <apt-pkg/init.h>
  38. #include <apt-pkg/md5.h>
  39. #include <apt-pkg/metaindex.h>
  40. #include <apt-pkg/pkgrecords.h>
  41. #include <apt-pkg/pkgsystem.h>
  42. #include <apt-pkg/progress.h>
  43. #include <apt-pkg/sourcelist.h>
  44. #include <apt-pkg/srcrecords.h>
  45. #include <apt-pkg/strutl.h>
  46. #include <apt-pkg/version.h>
  47. #include <apt-pkg/acquire.h>
  48. #include <apt-pkg/configuration.h>
  49. #include <apt-pkg/macros.h>
  50. #include <apt-pkg/pkgcache.h>
  51. #include <apt-pkg/cacheiterators.h>
  52. #include <apt-pkg/upgrade.h>
  53. #include <apt-pkg/sptr.h>
  54. #include <apt-private/acqprogress.h>
  55. #include <apt-private/private-cacheset.h>
  56. #include <apt-private/private-cachefile.h>
  57. #include <apt-private/private-cmndline.h>
  58. #include <apt-private/private-download.h>
  59. #include <apt-private/private-install.h>
  60. #include <apt-private/private-main.h>
  61. #include <apt-private/private-moo.h>
  62. #include <apt-private/private-output.h>
  63. #include <apt-private/private-update.h>
  64. #include <apt-private/private-upgrade.h>
  65. #include <apt-private/private-utils.h>
  66. #include <errno.h>
  67. #include <signal.h>
  68. #include <stddef.h>
  69. #include <stdio.h>
  70. #include <stdlib.h>
  71. #include <string.h>
  72. #include <sys/ioctl.h>
  73. #include <sys/stat.h>
  74. #include <unistd.h>
  75. #include <pwd.h>
  76. #include <grp.h>
  77. #include <algorithm>
  78. #include <fstream>
  79. #include <iostream>
  80. #include <sstream>
  81. #include <set>
  82. #include <string>
  83. #include <vector>
  84. #include <apti18n.h>
  85. /*}}}*/
  86. using namespace std;
  87. // TryToInstallBuildDep - Try to install a single package /*{{{*/
  88. // ---------------------------------------------------------------------
  89. /* This used to be inlined in DoInstall, but with the advent of regex package
  90. name matching it was split out.. */
  91. static bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache,
  92. pkgProblemResolver &Fix,bool Remove,bool BrokenFix,
  93. bool AllowFail = true)
  94. {
  95. if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0)
  96. {
  97. CacheSetHelperAPTGet helper(c1out);
  98. helper.showErrors(false);
  99. pkgCache::VerIterator Ver = helper.canNotFindNewestVer(Cache, Pkg);
  100. if (Ver.end() == false)
  101. Pkg = Ver.ParentPkg();
  102. else if (helper.showVirtualPackageErrors(Cache) == false)
  103. return AllowFail;
  104. }
  105. if (_config->FindB("Debug::BuildDeps",false) == true)
  106. {
  107. if (Remove == true)
  108. cout << " Trying to remove " << Pkg << endl;
  109. else
  110. cout << " Trying to install " << Pkg << endl;
  111. }
  112. if (Remove == true)
  113. {
  114. TryToRemove RemoveAction(Cache, &Fix);
  115. RemoveAction(Pkg.VersionList());
  116. } else if (Cache[Pkg].CandidateVer != 0) {
  117. TryToInstall InstallAction(Cache, &Fix, BrokenFix);
  118. InstallAction(Cache[Pkg].CandidateVerIter(Cache));
  119. InstallAction.doAutoInstall();
  120. } else
  121. return AllowFail;
  122. return true;
  123. }
  124. /*}}}*/
  125. // GetReleaseFileForSourceRecord - Return Suite for the given srcrecord /*{{{*/
  126. static pkgCache::RlsFileIterator GetReleaseFileForSourceRecord(CacheFile &CacheFile,
  127. pkgSourceList *SrcList, pkgSrcRecords::Parser *Parse)
  128. {
  129. // try to find release
  130. const pkgIndexFile& CurrentIndexFile = Parse->Index();
  131. for (pkgSourceList::const_iterator S = SrcList->begin();
  132. S != SrcList->end(); ++S)
  133. {
  134. vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles();
  135. for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin();
  136. IF != Indexes->end(); ++IF)
  137. {
  138. if (&CurrentIndexFile == (*IF))
  139. return (*S)->FindInCache(CacheFile, false);
  140. }
  141. }
  142. return pkgCache::RlsFileIterator(CacheFile);
  143. }
  144. /*}}}*/
  145. // FindSrc - Find a source record /*{{{*/
  146. // ---------------------------------------------------------------------
  147. /* */
  148. static pkgSrcRecords::Parser *FindSrc(const char *Name,
  149. pkgSrcRecords &SrcRecs,string &Src,
  150. CacheFile &CacheFile)
  151. {
  152. string VerTag, UserRequestedVerTag;
  153. string ArchTag = "";
  154. string RelTag = _config->Find("APT::Default-Release");
  155. string TmpSrc = Name;
  156. pkgDepCache *Cache = CacheFile.GetDepCache();
  157. // extract release
  158. size_t found = TmpSrc.find_last_of("/");
  159. if (found != string::npos)
  160. {
  161. RelTag = TmpSrc.substr(found+1);
  162. TmpSrc = TmpSrc.substr(0,found);
  163. }
  164. // extract the version
  165. found = TmpSrc.find_last_of("=");
  166. if (found != string::npos)
  167. {
  168. VerTag = UserRequestedVerTag = TmpSrc.substr(found+1);
  169. TmpSrc = TmpSrc.substr(0,found);
  170. }
  171. // extract arch
  172. found = TmpSrc.find_last_of(":");
  173. if (found != string::npos)
  174. {
  175. ArchTag = TmpSrc.substr(found+1);
  176. TmpSrc = TmpSrc.substr(0,found);
  177. }
  178. /* Lookup the version of the package we would install if we were to
  179. install a version and determine the source package name, then look
  180. in the archive for a source package of the same name. */
  181. bool MatchSrcOnly = _config->FindB("APT::Get::Only-Source");
  182. pkgCache::PkgIterator Pkg;
  183. if (ArchTag != "")
  184. Pkg = Cache->FindPkg(TmpSrc, ArchTag);
  185. else
  186. Pkg = Cache->FindPkg(TmpSrc);
  187. // if we can't find a package but the user qualified with a arch,
  188. // error out here
  189. if (Pkg.end() && ArchTag != "")
  190. {
  191. Src = Name;
  192. _error->Error(_("Can not find a package for architecture '%s'"),
  193. ArchTag.c_str());
  194. return 0;
  195. }
  196. if (MatchSrcOnly == false && Pkg.end() == false)
  197. {
  198. if(VerTag != "" || RelTag != "" || ArchTag != "")
  199. {
  200. bool fuzzy = false;
  201. // we have a default release, try to locate the pkg. we do it like
  202. // this because GetCandidateVer() will not "downgrade", that means
  203. // "apt-get source -t stable apt" won't work on a unstable system
  204. for (pkgCache::VerIterator Ver = Pkg.VersionList();; ++Ver)
  205. {
  206. // try first only exact matches, later fuzzy matches
  207. if (Ver.end() == true)
  208. {
  209. if (fuzzy == true)
  210. break;
  211. fuzzy = true;
  212. Ver = Pkg.VersionList();
  213. // exit right away from the Pkg.VersionList() loop if we
  214. // don't have any versions
  215. if (Ver.end() == true)
  216. break;
  217. }
  218. // ignore arches that are not for us
  219. if (ArchTag != "" && Ver.Arch() != ArchTag)
  220. continue;
  221. // pick highest version for the arch unless the user wants
  222. // something else
  223. if (ArchTag != "" && VerTag == "" && RelTag == "")
  224. if(Cache->VS().CmpVersion(VerTag, Ver.VerStr()) < 0)
  225. VerTag = Ver.VerStr();
  226. // We match against a concrete version (or a part of this version)
  227. if (VerTag.empty() == false &&
  228. (fuzzy == true || Cache->VS().CmpVersion(VerTag, Ver.VerStr()) != 0) && // exact match
  229. (fuzzy == false || strncmp(VerTag.c_str(), Ver.VerStr(), VerTag.size()) != 0)) // fuzzy match
  230. continue;
  231. for (pkgCache::VerFileIterator VF = Ver.FileList();
  232. VF.end() == false; ++VF)
  233. {
  234. /* If this is the status file, and the current version is not the
  235. version in the status file (ie it is not installed, or somesuch)
  236. then it is not a candidate for installation, ever. This weeds
  237. out bogus entries that may be due to config-file states, or
  238. other. */
  239. if ((VF.File()->Flags & pkgCache::Flag::NotSource) ==
  240. pkgCache::Flag::NotSource && Pkg.CurrentVer() != Ver)
  241. continue;
  242. // or we match against a release
  243. if(VerTag.empty() == false ||
  244. (VF.File().Archive() != 0 && VF.File().Archive() == RelTag) ||
  245. (VF.File().Codename() != 0 && VF.File().Codename() == RelTag))
  246. {
  247. // the Version we have is possibly fuzzy or includes binUploads,
  248. // so we use the Version of the SourcePkg (empty if same as package)
  249. Src = Ver.SourcePkgName();
  250. VerTag = Ver.SourceVerStr();
  251. break;
  252. }
  253. }
  254. if (Src.empty() == false)
  255. break;
  256. }
  257. }
  258. if (Src == "" && ArchTag != "")
  259. {
  260. if (VerTag != "")
  261. _error->Error(_("Can not find a package '%s' with version '%s'"),
  262. Pkg.FullName().c_str(), VerTag.c_str());
  263. if (RelTag != "")
  264. _error->Error(_("Can not find a package '%s' with release '%s'"),
  265. Pkg.FullName().c_str(), RelTag.c_str());
  266. Src = Name;
  267. return 0;
  268. }
  269. if (Src.empty() == true)
  270. {
  271. // if we don't have found a fitting package yet so we will
  272. // choose a good candidate and proceed with that.
  273. // Maybe we will find a source later on with the right VerTag
  274. // or RelTag
  275. pkgCache::VerIterator Ver = Cache->GetCandidateVer(Pkg);
  276. if (Ver.end() == false)
  277. {
  278. if (strcmp(Ver.SourcePkgName(),Ver.ParentPkg().Name()) != 0)
  279. Src = Ver.SourcePkgName();
  280. if (VerTag.empty() == true && strcmp(Ver.SourceVerStr(),Ver.VerStr()) != 0)
  281. VerTag = Ver.SourceVerStr();
  282. }
  283. }
  284. }
  285. if (Src.empty() == true)
  286. {
  287. Src = TmpSrc;
  288. }
  289. else
  290. {
  291. /* if we have a source pkg name, make sure to only search
  292. for srcpkg names, otherwise apt gets confused if there
  293. is a binary package "pkg1" and a source package "pkg1"
  294. with the same name but that comes from different packages */
  295. MatchSrcOnly = true;
  296. if (Src != TmpSrc)
  297. {
  298. ioprintf(c1out, _("Picking '%s' as source package instead of '%s'\n"), Src.c_str(), TmpSrc.c_str());
  299. }
  300. }
  301. // The best hit
  302. pkgSrcRecords::Parser *Last = 0;
  303. unsigned long Offset = 0;
  304. string Version;
  305. pkgSourceList *SrcList = CacheFile.GetSourceList();
  306. /* Iterate over all of the hits, which includes the resulting
  307. binary packages in the search */
  308. pkgSrcRecords::Parser *Parse;
  309. while (true)
  310. {
  311. SrcRecs.Restart();
  312. while ((Parse = SrcRecs.Find(Src.c_str(), MatchSrcOnly)) != 0)
  313. {
  314. const string Ver = Parse->Version();
  315. // See if we need to look for a specific release tag
  316. if (RelTag != "" && UserRequestedVerTag == "")
  317. {
  318. pkgCache::RlsFileIterator const Rls = GetReleaseFileForSourceRecord(CacheFile, SrcList, Parse);
  319. if (Rls.end() == false)
  320. {
  321. if ((Rls->Archive != 0 && RelTag == Rls.Archive()) ||
  322. (Rls->Codename != 0 && RelTag == Rls.Codename()))
  323. {
  324. Last = Parse;
  325. Offset = Parse->Offset();
  326. Version = Ver;
  327. }
  328. }
  329. }
  330. // Ignore all versions which doesn't fit
  331. if (VerTag.empty() == false &&
  332. Cache->VS().CmpVersion(VerTag, Ver) != 0) // exact match
  333. continue;
  334. // Newer version or an exact match? Save the hit
  335. if (Last == 0 || Cache->VS().CmpVersion(Version,Ver) < 0) {
  336. Last = Parse;
  337. Offset = Parse->Offset();
  338. Version = Ver;
  339. }
  340. // was the version check above an exact match?
  341. // If so, we don't need to look further
  342. if (VerTag.empty() == false && (VerTag == Ver))
  343. break;
  344. }
  345. if (UserRequestedVerTag == "" && Version != "" && RelTag != "")
  346. ioprintf(c1out, "Selected version '%s' (%s) for %s\n",
  347. Version.c_str(), RelTag.c_str(), Src.c_str());
  348. if (Last != 0 || VerTag.empty() == true)
  349. break;
  350. _error->Error(_("Can not find version '%s' of package '%s'"), VerTag.c_str(), TmpSrc.c_str());
  351. return 0;
  352. }
  353. if (Last == 0 || Last->Jump(Offset) == false)
  354. return 0;
  355. return Last;
  356. }
  357. /*}}}*/
  358. /* mark packages as automatically/manually installed. {{{*/
  359. static bool DoMarkAuto(CommandLine &CmdL)
  360. {
  361. bool Action = true;
  362. int AutoMarkChanged = 0;
  363. OpTextProgress progress;
  364. CacheFile Cache;
  365. if (Cache.Open() == false)
  366. return false;
  367. if (strcasecmp(CmdL.FileList[0],"markauto") == 0)
  368. Action = true;
  369. else if (strcasecmp(CmdL.FileList[0],"unmarkauto") == 0)
  370. Action = false;
  371. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  372. {
  373. const char *S = *I;
  374. // Locate the package
  375. pkgCache::PkgIterator Pkg = Cache->FindPkg(S);
  376. if (Pkg.end() == true) {
  377. return _error->Error(_("Couldn't find package %s"),S);
  378. }
  379. else
  380. {
  381. if (!Action)
  382. ioprintf(c1out,_("%s set to manually installed.\n"), Pkg.Name());
  383. else
  384. ioprintf(c1out,_("%s set to automatically installed.\n"),
  385. Pkg.Name());
  386. Cache->MarkAuto(Pkg,Action);
  387. AutoMarkChanged++;
  388. }
  389. }
  390. _error->Notice(_("This command is deprecated. Please use 'apt-mark auto' and 'apt-mark manual' instead."));
  391. if (AutoMarkChanged && ! _config->FindB("APT::Get::Simulate",false))
  392. return Cache->writeStateFile(NULL);
  393. return false;
  394. }
  395. /*}}}*/
  396. // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
  397. // ---------------------------------------------------------------------
  398. /* Follows dselect's selections */
  399. static bool DoDSelectUpgrade(CommandLine &)
  400. {
  401. CacheFile Cache;
  402. if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
  403. return false;
  404. pkgDepCache::ActionGroup group(Cache);
  405. // Install everything with the install flag set
  406. pkgCache::PkgIterator I = Cache->PkgBegin();
  407. for (;I.end() != true; ++I)
  408. {
  409. /* Install the package only if it is a new install, the autoupgrader
  410. will deal with the rest */
  411. if (I->SelectedState == pkgCache::State::Install)
  412. Cache->MarkInstall(I,false);
  413. }
  414. /* Now install their deps too, if we do this above then order of
  415. the status file is significant for | groups */
  416. for (I = Cache->PkgBegin();I.end() != true; ++I)
  417. {
  418. /* Install the package only if it is a new install, the autoupgrader
  419. will deal with the rest */
  420. if (I->SelectedState == pkgCache::State::Install)
  421. Cache->MarkInstall(I,true);
  422. }
  423. // Apply erasures now, they override everything else.
  424. for (I = Cache->PkgBegin();I.end() != true; ++I)
  425. {
  426. // Remove packages
  427. if (I->SelectedState == pkgCache::State::DeInstall ||
  428. I->SelectedState == pkgCache::State::Purge)
  429. Cache->MarkDelete(I,I->SelectedState == pkgCache::State::Purge);
  430. }
  431. /* Resolve any problems that dselect created, allupgrade cannot handle
  432. such things. We do so quite aggressively too.. */
  433. if (Cache->BrokenCount() != 0)
  434. {
  435. pkgProblemResolver Fix(Cache);
  436. // Hold back held packages.
  437. if (_config->FindB("APT::Ignore-Hold",false) == false)
  438. {
  439. for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; ++I)
  440. {
  441. if (I->SelectedState == pkgCache::State::Hold)
  442. {
  443. Fix.Protect(I);
  444. Cache->MarkKeep(I);
  445. }
  446. }
  447. }
  448. if (Fix.Resolve() == false)
  449. {
  450. ShowBroken(c1out,Cache,false);
  451. return _error->Error(_("Internal error, problem resolver broke stuff"));
  452. }
  453. }
  454. // Now upgrade everything
  455. if (APT::Upgrade::Upgrade(Cache, APT::Upgrade::FORBID_REMOVE_PACKAGES | APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES) == false)
  456. {
  457. ShowBroken(c1out,Cache,false);
  458. return _error->Error(_("Internal error, problem resolver broke stuff"));
  459. }
  460. return InstallPackages(Cache,false);
  461. }
  462. /*}}}*/
  463. // DoClean - Remove download archives /*{{{*/
  464. // ---------------------------------------------------------------------
  465. /* */
  466. static bool DoClean(CommandLine &)
  467. {
  468. std::string const archivedir = _config->FindDir("Dir::Cache::archives");
  469. std::string const listsdir = _config->FindDir("Dir::state::lists");
  470. if (_config->FindB("APT::Get::Simulate") == true)
  471. {
  472. std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache");
  473. std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache");
  474. cout << "Del " << archivedir << "* " << archivedir << "partial/*"<< endl
  475. << "Del " << listsdir << "partial/*" << endl
  476. << "Del " << pkgcache << " " << srcpkgcache << endl;
  477. return true;
  478. }
  479. pkgAcquire Fetcher;
  480. Fetcher.GetLock(archivedir);
  481. Fetcher.Clean(archivedir);
  482. Fetcher.Clean(archivedir + "partial/");
  483. Fetcher.GetLock(listsdir);
  484. Fetcher.Clean(listsdir + "partial/");
  485. pkgCacheFile::RemoveCaches();
  486. return true;
  487. }
  488. /*}}}*/
  489. // DoAutoClean - Smartly remove downloaded archives /*{{{*/
  490. // ---------------------------------------------------------------------
  491. /* This is similar to clean but it only purges things that cannot be
  492. downloaded, that is old versions of cached packages. */
  493. class LogCleaner : public pkgArchiveCleaner
  494. {
  495. protected:
  496. virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St) APT_OVERRIDE
  497. {
  498. c1out << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "B]" << endl;
  499. if (_config->FindB("APT::Get::Simulate") == false)
  500. unlink(File);
  501. };
  502. };
  503. static bool DoAutoClean(CommandLine &)
  504. {
  505. // Lock the archive directory
  506. FileFd Lock;
  507. if (_config->FindB("Debug::NoLocking",false) == false)
  508. {
  509. int lock_fd = GetLock(_config->FindDir("Dir::Cache::Archives") + "lock");
  510. if (lock_fd < 0)
  511. return _error->Error(_("Unable to lock the download directory"));
  512. Lock.Fd(lock_fd);
  513. }
  514. CacheFile Cache;
  515. if (Cache.Open() == false)
  516. return false;
  517. LogCleaner Cleaner;
  518. return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) &&
  519. Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache);
  520. }
  521. /*}}}*/
  522. // DoDownload - download a binary /*{{{*/
  523. // ---------------------------------------------------------------------
  524. static bool DoDownload(CommandLine &CmdL)
  525. {
  526. CacheFile Cache;
  527. if (Cache.ReadOnlyOpen() == false)
  528. return false;
  529. APT::CacheSetHelper helper;
  530. APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache,
  531. CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
  532. if (verset.empty() == true)
  533. return false;
  534. AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
  535. pkgAcquire Fetcher(&Stat);
  536. pkgRecords Recs(Cache);
  537. pkgSourceList *SrcList = Cache.GetSourceList();
  538. // reuse the usual acquire methods for deb files, but don't drop them into
  539. // the usual directories - keep everything in the current directory
  540. std::vector<std::string> storefile(verset.size());
  541. std::string const cwd = SafeGetCWD();
  542. _config->Set("Dir::Cache::Archives", cwd);
  543. int i = 0;
  544. for (APT::VersionSet::const_iterator Ver = verset.begin();
  545. Ver != verset.end(); ++Ver, ++i)
  546. {
  547. pkgAcquire::Item *I = new pkgAcqArchive(&Fetcher, SrcList, &Recs, *Ver, storefile[i]);
  548. if (storefile[i].empty())
  549. continue;
  550. std::string const filename = cwd + flNotDir(storefile[i]);
  551. storefile[i].assign(filename);
  552. I->DestFile.assign(filename);
  553. }
  554. // Just print out the uris and exit if the --print-uris flag was used
  555. if (_config->FindB("APT::Get::Print-URIs") == true)
  556. {
  557. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  558. for (; I != Fetcher.UriEnd(); ++I)
  559. cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
  560. I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
  561. return true;
  562. }
  563. if (_error->PendingError() == true || CheckAuth(Fetcher, false) == false)
  564. return false;
  565. bool Failed = false;
  566. if (AcquireRun(Fetcher, 0, &Failed, NULL) == false)
  567. return false;
  568. // copy files in local sources to the current directory
  569. for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
  570. {
  571. std::string const filename = cwd + flNotDir((*I)->DestFile);
  572. if ((*I)->Local == true &&
  573. filename != (*I)->DestFile &&
  574. (*I)->Status == pkgAcquire::Item::StatDone)
  575. {
  576. std::ifstream src((*I)->DestFile.c_str(), std::ios::binary);
  577. std::ofstream dst(filename.c_str(), std::ios::binary);
  578. dst << src.rdbuf();
  579. }
  580. }
  581. return Failed == false;
  582. }
  583. /*}}}*/
  584. // DoCheck - Perform the check operation /*{{{*/
  585. // ---------------------------------------------------------------------
  586. /* Opening automatically checks the system, this command is mostly used
  587. for debugging */
  588. static bool DoCheck(CommandLine &)
  589. {
  590. CacheFile Cache;
  591. Cache.Open();
  592. Cache.CheckDeps();
  593. return true;
  594. }
  595. /*}}}*/
  596. // DoSource - Fetch a source archive /*{{{*/
  597. // ---------------------------------------------------------------------
  598. /* Fetch souce packages */
  599. struct DscFile
  600. {
  601. string Package;
  602. string Version;
  603. string Dsc;
  604. };
  605. static bool DoSource(CommandLine &CmdL)
  606. {
  607. CacheFile Cache;
  608. if (Cache.Open(false) == false)
  609. return false;
  610. if (CmdL.FileSize() <= 1)
  611. return _error->Error(_("Must specify at least one package to fetch source for"));
  612. // Read the source list
  613. if (Cache.BuildSourceList() == false)
  614. return false;
  615. pkgSourceList *List = Cache.GetSourceList();
  616. // Create the text record parsers
  617. pkgSrcRecords SrcRecs(*List);
  618. if (_error->PendingError() == true)
  619. return false;
  620. // Create the download object
  621. AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
  622. pkgAcquire Fetcher(&Stat);
  623. std::unique_ptr<DscFile[]> Dsc(new DscFile[CmdL.FileSize()]);
  624. // insert all downloaded uris into this set to avoid downloading them
  625. // twice
  626. set<string> queued;
  627. // Diff only mode only fetches .diff files
  628. bool const diffOnly = _config->FindB("APT::Get::Diff-Only", false);
  629. // Tar only mode only fetches .tar files
  630. bool const tarOnly = _config->FindB("APT::Get::Tar-Only", false);
  631. // Dsc only mode only fetches .dsc files
  632. bool const dscOnly = _config->FindB("APT::Get::Dsc-Only", false);
  633. // Load the requestd sources into the fetcher
  634. unsigned J = 0;
  635. std::vector<std::string> UntrustedList;
  636. for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
  637. {
  638. string Src;
  639. pkgSrcRecords::Parser *Last = FindSrc(*I,SrcRecs,Src,Cache);
  640. if (Last == 0) {
  641. return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
  642. }
  643. if (Last->Index().IsTrusted() == false)
  644. UntrustedList.push_back(Src);
  645. string srec = Last->AsStr();
  646. string::size_type pos = srec.find("\nVcs-");
  647. while (pos != string::npos)
  648. {
  649. pos += strlen("\nVcs-");
  650. string vcs = srec.substr(pos,srec.find(":",pos)-pos);
  651. if(vcs == "Browser")
  652. {
  653. pos = srec.find("\nVcs-", pos);
  654. continue;
  655. }
  656. pos += vcs.length()+2;
  657. string::size_type epos = srec.find("\n", pos);
  658. string const uri = srec.substr(pos,epos-pos);
  659. ioprintf(c1out, _("NOTICE: '%s' packaging is maintained in "
  660. "the '%s' version control system at:\n"
  661. "%s\n"),
  662. Src.c_str(), vcs.c_str(), uri.c_str());
  663. std::string vcscmd;
  664. if (vcs == "Bzr")
  665. vcscmd = "bzr branch " + uri;
  666. else if (vcs == "Git")
  667. vcscmd = "git clone " + uri;
  668. if (vcscmd.empty() == false)
  669. ioprintf(c1out,_("Please use:\n%s\n"
  670. "to retrieve the latest (possibly unreleased) "
  671. "updates to the package.\n"),
  672. vcscmd.c_str());
  673. break;
  674. }
  675. // Back track
  676. vector<pkgSrcRecords::File2> Lst;
  677. if (Last->Files2(Lst) == false) {
  678. return false;
  679. }
  680. // Load them into the fetcher
  681. for (vector<pkgSrcRecords::File2>::const_iterator I = Lst.begin();
  682. I != Lst.end(); ++I)
  683. {
  684. // Try to guess what sort of file it is we are getting.
  685. if (I->Type == "dsc")
  686. {
  687. Dsc[J].Package = Last->Package();
  688. Dsc[J].Version = Last->Version();
  689. Dsc[J].Dsc = flNotDir(I->Path);
  690. }
  691. // Handle the only options so that multiple can be used at once
  692. if (diffOnly == true || tarOnly == true || dscOnly == true)
  693. {
  694. if ((diffOnly == true && I->Type == "diff") ||
  695. (tarOnly == true && I->Type == "tar") ||
  696. (dscOnly == true && I->Type == "dsc"))
  697. ; // Fine, we want this file downloaded
  698. else
  699. continue;
  700. }
  701. // don't download the same uri twice (should this be moved to
  702. // the fetcher interface itself?)
  703. if(queued.find(Last->Index().ArchiveURI(I->Path)) != queued.end())
  704. continue;
  705. queued.insert(Last->Index().ArchiveURI(I->Path));
  706. // check if we have a file with that md5 sum already localy
  707. std::string localFile = flNotDir(I->Path);
  708. if (FileExists(localFile) == true)
  709. if(I->Hashes.VerifyFile(localFile) == true)
  710. {
  711. ioprintf(c1out,_("Skipping already downloaded file '%s'\n"),
  712. localFile.c_str());
  713. continue;
  714. }
  715. // see if we have a hash (Acquire::ForceHash is the only way to have none)
  716. if (I->Hashes.usable() == false && _config->FindB("APT::Get::AllowUnauthenticated",false) == false)
  717. {
  718. ioprintf(c1out, "Skipping download of file '%s' as requested hashsum is not available for authentication\n",
  719. localFile.c_str());
  720. continue;
  721. }
  722. new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path),
  723. I->Hashes, I->FileSize, Last->Index().SourceInfo(*Last,*I), Src);
  724. }
  725. }
  726. // Display statistics
  727. unsigned long long FetchBytes = Fetcher.FetchNeeded();
  728. unsigned long long FetchPBytes = Fetcher.PartialPresent();
  729. unsigned long long DebBytes = Fetcher.TotalNeeded();
  730. if (CheckFreeSpaceBeforeDownload(".", (FetchBytes - FetchPBytes)) == false)
  731. return false;
  732. // Number of bytes
  733. if (DebBytes != FetchBytes)
  734. //TRANSLATOR: The required space between number and unit is already included
  735. // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
  736. ioprintf(c1out,_("Need to get %sB/%sB of source archives.\n"),
  737. SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str());
  738. else
  739. //TRANSLATOR: The required space between number and unit is already included
  740. // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
  741. ioprintf(c1out,_("Need to get %sB of source archives.\n"),
  742. SizeToStr(DebBytes).c_str());
  743. if (_config->FindB("APT::Get::Simulate",false) == true)
  744. {
  745. for (unsigned I = 0; I != J; I++)
  746. ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str());
  747. return true;
  748. }
  749. // Just print out the uris an exit if the --print-uris flag was used
  750. if (_config->FindB("APT::Get::Print-URIs") == true)
  751. {
  752. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  753. for (; I != Fetcher.UriEnd(); ++I)
  754. cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
  755. I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
  756. return true;
  757. }
  758. // check authentication status of the source as well
  759. if (UntrustedList.empty() == false && AuthPrompt(UntrustedList, false) == false)
  760. return false;
  761. // Run it
  762. bool Failed = false;
  763. if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
  764. {
  765. return _error->Error(_("Failed to fetch some archives."));
  766. }
  767. if (_config->FindB("APT::Get::Download-only",false) == true)
  768. {
  769. c1out << _("Download complete and in download only mode") << endl;
  770. return true;
  771. }
  772. // Unpack the sources
  773. pid_t Process = ExecFork();
  774. if (Process == 0)
  775. {
  776. bool const fixBroken = _config->FindB("APT::Get::Fix-Broken", false);
  777. for (unsigned I = 0; I != J; ++I)
  778. {
  779. string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str());
  780. // Diff only mode only fetches .diff files
  781. if (_config->FindB("APT::Get::Diff-Only",false) == true ||
  782. _config->FindB("APT::Get::Tar-Only",false) == true ||
  783. Dsc[I].Dsc.empty() == true)
  784. continue;
  785. // See if the package is already unpacked
  786. struct stat Stat;
  787. if (fixBroken == false && stat(Dir.c_str(),&Stat) == 0 &&
  788. S_ISDIR(Stat.st_mode) != 0)
  789. {
  790. ioprintf(c0out ,_("Skipping unpack of already unpacked source in %s\n"),
  791. Dir.c_str());
  792. }
  793. else
  794. {
  795. // Call dpkg-source
  796. std::string const sourceopts = _config->Find("DPkg::Source-Options", "-x");
  797. std::string S;
  798. strprintf(S, "%s %s %s",
  799. _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
  800. sourceopts.c_str(), Dsc[I].Dsc.c_str());
  801. if (system(S.c_str()) != 0)
  802. {
  803. fprintf(stderr, _("Unpack command '%s' failed.\n"), S.c_str());
  804. fprintf(stderr, _("Check if the 'dpkg-dev' package is installed.\n"));
  805. _exit(1);
  806. }
  807. }
  808. // Try to compile it with dpkg-buildpackage
  809. if (_config->FindB("APT::Get::Compile",false) == true)
  810. {
  811. string buildopts = _config->Find("APT::Get::Host-Architecture");
  812. if (buildopts.empty() == false)
  813. buildopts = "-a" + buildopts + " ";
  814. // get all active build profiles
  815. std::string const profiles = APT::Configuration::getBuildProfilesString();
  816. if (profiles.empty() == false)
  817. buildopts.append(" -P").append(profiles).append(" ");
  818. buildopts.append(_config->Find("DPkg::Build-Options","-b -uc"));
  819. // Call dpkg-buildpackage
  820. std::string S;
  821. strprintf(S, "cd %s && %s %s",
  822. Dir.c_str(),
  823. _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
  824. buildopts.c_str());
  825. if (system(S.c_str()) != 0)
  826. {
  827. fprintf(stderr, _("Build command '%s' failed.\n"), S.c_str());
  828. _exit(1);
  829. }
  830. }
  831. }
  832. _exit(0);
  833. }
  834. return ExecWait(Process, "dpkg-source");
  835. }
  836. /*}}}*/
  837. // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
  838. // ---------------------------------------------------------------------
  839. /* This function will look at the build depends list of the given source
  840. package and install the necessary packages to make it true, or fail. */
  841. static bool DoBuildDep(CommandLine &CmdL)
  842. {
  843. CacheFile Cache;
  844. _config->Set("APT::Install-Recommends", false);
  845. bool WantLock = _config->FindB("APT::Get::Print-URIs", false) == false;
  846. if (Cache.Open(WantLock) == false)
  847. return false;
  848. if (CmdL.FileSize() <= 1)
  849. return _error->Error(_("Must specify at least one package to check builddeps for"));
  850. // Read the source list
  851. if (Cache.BuildSourceList() == false)
  852. return false;
  853. pkgSourceList *List = Cache.GetSourceList();
  854. // Create the text record parsers
  855. pkgSrcRecords SrcRecs(*List);
  856. if (_error->PendingError() == true)
  857. return false;
  858. bool StripMultiArch;
  859. string hostArch = _config->Find("APT::Get::Host-Architecture");
  860. if (hostArch.empty() == false)
  861. {
  862. std::vector<std::string> archs = APT::Configuration::getArchitectures();
  863. if (std::find(archs.begin(), archs.end(), hostArch) == archs.end())
  864. return _error->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch.c_str());
  865. StripMultiArch = false;
  866. }
  867. else
  868. StripMultiArch = true;
  869. unsigned J = 0;
  870. for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
  871. {
  872. string Src;
  873. pkgSrcRecords::Parser *Last = 0;
  874. std::unique_ptr<pkgSrcRecords::Parser> LastOwner;
  875. // an unpacked debian source tree
  876. using APT::String::Startswith;
  877. if ((Startswith(*I, "./") || Startswith(*I, "/")) &&
  878. DirectoryExists(*I))
  879. {
  880. ioprintf(c1out, _("Note, using directory '%s' to get the build dependencies\n"), *I);
  881. // FIXME: how can we make this more elegant?
  882. std::string TypeName = "Debian control file";
  883. pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
  884. if(Type != NULL)
  885. LastOwner.reset(Last = Type->CreateSrcPkgParser(*I));
  886. }
  887. // if its a local file (e.g. .dsc) use this
  888. else if (FileExists(*I))
  889. {
  890. ioprintf(c1out, _("Note, using file '%s' to get the build dependencies\n"), *I);
  891. // see if we can get a parser for this pkgIndexFile type
  892. string TypeName = "Debian " + flExtension(*I) + " file";
  893. pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
  894. if(Type != NULL)
  895. LastOwner.reset(Last = Type->CreateSrcPkgParser(*I));
  896. } else {
  897. // normal case, search the cache for the source file
  898. Last = FindSrc(*I,SrcRecs,Src,Cache);
  899. }
  900. if (Last == 0)
  901. return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
  902. // Process the build-dependencies
  903. vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps;
  904. // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
  905. if (hostArch.empty() == false)
  906. {
  907. std::string nativeArch = _config->Find("APT::Architecture");
  908. _config->Set("APT::Architecture", hostArch);
  909. bool Success = Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch);
  910. _config->Set("APT::Architecture", nativeArch);
  911. if (Success == false)
  912. return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
  913. }
  914. else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
  915. return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
  916. // Also ensure that build-essential packages are present
  917. Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
  918. if (Opts)
  919. Opts = Opts->Child;
  920. for (; Opts; Opts = Opts->Next)
  921. {
  922. if (Opts->Value.empty() == true)
  923. continue;
  924. pkgSrcRecords::Parser::BuildDepRec rec;
  925. rec.Package = Opts->Value;
  926. rec.Type = pkgSrcRecords::Parser::BuildDependIndep;
  927. rec.Op = 0;
  928. BuildDeps.push_back(rec);
  929. }
  930. if (BuildDeps.empty() == true)
  931. {
  932. ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str());
  933. continue;
  934. }
  935. // Install the requested packages
  936. vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D;
  937. pkgProblemResolver Fix(Cache);
  938. bool skipAlternatives = false; // skip remaining alternatives in an or group
  939. for (D = BuildDeps.begin(); D != BuildDeps.end(); ++D)
  940. {
  941. bool hasAlternatives = (((*D).Op & pkgCache::Dep::Or) == pkgCache::Dep::Or);
  942. if (skipAlternatives == true)
  943. {
  944. /*
  945. * if there are alternatives, we've already picked one, so skip
  946. * the rest
  947. *
  948. * TODO: this means that if there's a build-dep on A|B and B is
  949. * installed, we'll still try to install A; more importantly,
  950. * if A is currently broken, we cannot go back and try B. To fix
  951. * this would require we do a Resolve cycle for each package we
  952. * add to the install list. Ugh
  953. */
  954. if (!hasAlternatives)
  955. skipAlternatives = false; // end of or group
  956. continue;
  957. }
  958. if ((*D).Type == pkgSrcRecords::Parser::BuildConflict ||
  959. (*D).Type == pkgSrcRecords::Parser::BuildConflictIndep)
  960. {
  961. pkgCache::GrpIterator Grp = Cache->FindGrp((*D).Package);
  962. // Build-conflicts on unknown packages are silently ignored
  963. if (Grp.end() == true)
  964. continue;
  965. for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
  966. {
  967. pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
  968. /*
  969. * Remove if we have an installed version that satisfies the
  970. * version criteria
  971. */
  972. if (IV.end() == false &&
  973. Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
  974. TryToInstallBuildDep(Pkg,Cache,Fix,true,false);
  975. }
  976. }
  977. else // BuildDep || BuildDepIndep
  978. {
  979. if (_config->FindB("Debug::BuildDeps",false) == true)
  980. cout << "Looking for " << (*D).Package << "...\n";
  981. pkgCache::PkgIterator Pkg;
  982. // Cross-Building?
  983. if (StripMultiArch == false && D->Type != pkgSrcRecords::Parser::BuildDependIndep)
  984. {
  985. size_t const colon = D->Package.find(":");
  986. if (colon != string::npos)
  987. {
  988. if (strcmp(D->Package.c_str() + colon, ":any") == 0 || strcmp(D->Package.c_str() + colon, ":native") == 0)
  989. Pkg = Cache->FindPkg(D->Package.substr(0,colon));
  990. else
  991. Pkg = Cache->FindPkg(D->Package);
  992. }
  993. else
  994. Pkg = Cache->FindPkg(D->Package, hostArch);
  995. // a bad version either is invalid or doesn't satify dependency
  996. #define BADVER(Ver) (Ver.end() == true || \
  997. (D->Version.empty() == false && \
  998. Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false))
  999. APT::VersionList verlist;
  1000. if (Pkg.end() == false)
  1001. {
  1002. pkgCache::VerIterator Ver = (*Cache)[Pkg].InstVerIter(*Cache);
  1003. if (BADVER(Ver) == false)
  1004. verlist.insert(Ver);
  1005. Ver = (*Cache)[Pkg].CandidateVerIter(*Cache);
  1006. if (BADVER(Ver) == false)
  1007. verlist.insert(Ver);
  1008. }
  1009. if (verlist.empty() == true)
  1010. {
  1011. pkgCache::PkgIterator BuildPkg = Cache->FindPkg(D->Package, "native");
  1012. if (BuildPkg.end() == false && Pkg != BuildPkg)
  1013. {
  1014. pkgCache::VerIterator Ver = (*Cache)[BuildPkg].InstVerIter(*Cache);
  1015. if (BADVER(Ver) == false)
  1016. verlist.insert(Ver);
  1017. Ver = (*Cache)[BuildPkg].CandidateVerIter(*Cache);
  1018. if (BADVER(Ver) == false)
  1019. verlist.insert(Ver);
  1020. }
  1021. }
  1022. #undef BADVER
  1023. string forbidden;
  1024. // We need to decide if host or build arch, so find a version we can look at
  1025. APT::VersionList::const_iterator Ver = verlist.begin();
  1026. for (; Ver != verlist.end(); ++Ver)
  1027. {
  1028. forbidden.clear();
  1029. if (Ver->MultiArch == pkgCache::Version::No || Ver->MultiArch == pkgCache::Version::All)
  1030. {
  1031. if (colon == string::npos)
  1032. Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
  1033. else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
  1034. forbidden = "Multi-Arch: no";
  1035. else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
  1036. Pkg = Ver.ParentPkg().Group().FindPkg("native");
  1037. }
  1038. else if (Ver->MultiArch == pkgCache::Version::Same)
  1039. {
  1040. if (colon == string::npos)
  1041. Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
  1042. else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
  1043. forbidden = "Multi-Arch: same";
  1044. else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
  1045. Pkg = Ver.ParentPkg().Group().FindPkg("native");
  1046. }
  1047. else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
  1048. {
  1049. if (colon == string::npos)
  1050. Pkg = Ver.ParentPkg().Group().FindPkg("native");
  1051. else if (strcmp(D->Package.c_str() + colon, ":any") == 0 ||
  1052. strcmp(D->Package.c_str() + colon, ":native") == 0)
  1053. forbidden = "Multi-Arch: foreign";
  1054. }
  1055. else if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
  1056. {
  1057. if (colon == string::npos)
  1058. Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
  1059. else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
  1060. {
  1061. // prefer any installed over preferred non-installed architectures
  1062. pkgCache::GrpIterator Grp = Ver.ParentPkg().Group();
  1063. // we don't check for version here as we are better of with upgrading than remove and install
  1064. for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
  1065. if (Pkg.CurrentVer().end() == false)
  1066. break;
  1067. if (Pkg.end() == true)
  1068. Pkg = Grp.FindPreferredPkg(true);
  1069. }
  1070. else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
  1071. Pkg = Ver.ParentPkg().Group().FindPkg("native");
  1072. }
  1073. if (forbidden.empty() == false)
  1074. {
  1075. if (_config->FindB("Debug::BuildDeps",false) == true)
  1076. cout << D->Package.substr(colon, string::npos) << " is not allowed from " << forbidden << " package " << (*D).Package << " (" << Ver.VerStr() << ")" << endl;
  1077. continue;
  1078. }
  1079. //we found a good version
  1080. break;
  1081. }
  1082. if (Ver == verlist.end())
  1083. {
  1084. if (_config->FindB("Debug::BuildDeps",false) == true)
  1085. cout << " No multiarch info as we have no satisfying installed nor candidate for " << D->Package << " on build or host arch" << endl;
  1086. if (forbidden.empty() == false)
  1087. {
  1088. if (hasAlternatives)
  1089. continue;
  1090. return _error->Error(_("%s dependency for %s can't be satisfied "
  1091. "because %s is not allowed on '%s' packages"),
  1092. Last->BuildDepType(D->Type), Src.c_str(),
  1093. D->Package.c_str(), forbidden.c_str());
  1094. }
  1095. }
  1096. }
  1097. else
  1098. Pkg = Cache->FindPkg(D->Package);
  1099. if (Pkg.end() == true || (Pkg->VersionList == 0 && Pkg->ProvidesList == 0))
  1100. {
  1101. if (_config->FindB("Debug::BuildDeps",false) == true)
  1102. cout << " (not found)" << (*D).Package << endl;
  1103. if (hasAlternatives)
  1104. continue;
  1105. return _error->Error(_("%s dependency for %s cannot be satisfied "
  1106. "because the package %s cannot be found"),
  1107. Last->BuildDepType((*D).Type),Src.c_str(),
  1108. (*D).Package.c_str());
  1109. }
  1110. pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
  1111. if (IV.end() == false)
  1112. {
  1113. if (_config->FindB("Debug::BuildDeps",false) == true)
  1114. cout << " Is installed\n";
  1115. if (D->Version.empty() == true ||
  1116. Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
  1117. {
  1118. skipAlternatives = hasAlternatives;
  1119. continue;
  1120. }
  1121. if (_config->FindB("Debug::BuildDeps",false) == true)
  1122. cout << " ...but the installed version doesn't meet the version requirement\n";
  1123. if (((*D).Op & pkgCache::Dep::LessEq) == pkgCache::Dep::LessEq)
  1124. return _error->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
  1125. Last->BuildDepType((*D).Type), Src.c_str(), Pkg.FullName(true).c_str());
  1126. }
  1127. // Only consider virtual packages if there is no versioned dependency
  1128. if ((*D).Version.empty() == true)
  1129. {
  1130. /*
  1131. * If this is a virtual package, we need to check the list of
  1132. * packages that provide it and see if any of those are
  1133. * installed
  1134. */
  1135. pkgCache::PrvIterator Prv = Pkg.ProvidesList();
  1136. for (; Prv.end() != true; ++Prv)
  1137. {
  1138. if (_config->FindB("Debug::BuildDeps",false) == true)
  1139. cout << " Checking provider " << Prv.OwnerPkg().FullName() << endl;
  1140. if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false)
  1141. break;
  1142. }
  1143. if (Prv.end() == false)
  1144. {
  1145. if (_config->FindB("Debug::BuildDeps",false) == true)
  1146. cout << " Is provided by installed package " << Prv.OwnerPkg().FullName() << endl;
  1147. skipAlternatives = hasAlternatives;
  1148. continue;
  1149. }
  1150. }
  1151. else // versioned dependency
  1152. {
  1153. pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache);
  1154. if (CV.end() == true ||
  1155. Cache->VS().CheckDep(CV.VerStr(),(*D).Op,(*D).Version.c_str()) == false)
  1156. {
  1157. if (hasAlternatives)
  1158. continue;
  1159. else if (CV.end() == false)
  1160. return _error->Error(_("%s dependency for %s cannot be satisfied "
  1161. "because candidate version of package %s "
  1162. "can't satisfy version requirements"),
  1163. Last->BuildDepType(D->Type), Src.c_str(),
  1164. D->Package.c_str());
  1165. else
  1166. return _error->Error(_("%s dependency for %s cannot be satisfied "
  1167. "because package %s has no candidate version"),
  1168. Last->BuildDepType(D->Type), Src.c_str(),
  1169. D->Package.c_str());
  1170. }
  1171. }
  1172. if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false,false) == true)
  1173. {
  1174. // We successfully installed something; skip remaining alternatives
  1175. skipAlternatives = hasAlternatives;
  1176. if(_config->FindB("APT::Get::Build-Dep-Automatic", false) == true)
  1177. Cache->MarkAuto(Pkg, true);
  1178. continue;
  1179. }
  1180. else if (hasAlternatives)
  1181. {
  1182. if (_config->FindB("Debug::BuildDeps",false) == true)
  1183. cout << " Unsatisfiable, trying alternatives\n";
  1184. continue;
  1185. }
  1186. else
  1187. {
  1188. return _error->Error(_("Failed to satisfy %s dependency for %s: %s"),
  1189. Last->BuildDepType((*D).Type),
  1190. Src.c_str(),
  1191. (*D).Package.c_str());
  1192. }
  1193. }
  1194. }
  1195. if (Fix.Resolve(true) == false)
  1196. _error->Discard();
  1197. // Now we check the state of the packages,
  1198. if (Cache->BrokenCount() != 0)
  1199. {
  1200. ShowBroken(cout, Cache, false);
  1201. return _error->Error(_("Build-dependencies for %s could not be satisfied."),*I);
  1202. }
  1203. }
  1204. if (InstallPackages(Cache, false, true) == false)
  1205. return _error->Error(_("Failed to process build dependencies"));
  1206. return true;
  1207. }
  1208. /*}}}*/
  1209. // DoChangelog - Get changelog from the command line /*{{{*/
  1210. static bool DoChangelog(CommandLine &CmdL)
  1211. {
  1212. CacheFile Cache;
  1213. if (Cache.ReadOnlyOpen() == false)
  1214. return false;
  1215. APT::CacheSetHelper helper;
  1216. APT::VersionList verset = APT::VersionList::FromCommandLine(Cache,
  1217. CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
  1218. if (verset.empty() == true)
  1219. return false;
  1220. pkgAcquire Fetcher;
  1221. AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
  1222. Fetcher.SetLog(&Stat);
  1223. bool const downOnly = _config->FindB("APT::Get::Download-Only", false);
  1224. bool const printOnly = _config->FindB("APT::Get::Print-URIs", false);
  1225. for (APT::VersionList::const_iterator Ver = verset.begin();
  1226. Ver != verset.end();
  1227. ++Ver)
  1228. {
  1229. if (printOnly)
  1230. new pkgAcqChangelog(&Fetcher, Ver, "/dev/null");
  1231. else if (downOnly)
  1232. new pkgAcqChangelog(&Fetcher, Ver, ".");
  1233. else
  1234. new pkgAcqChangelog(&Fetcher, Ver);
  1235. }
  1236. if (printOnly == false)
  1237. {
  1238. bool Failed = false;
  1239. if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
  1240. return false;
  1241. }
  1242. if (downOnly == false || printOnly == true)
  1243. {
  1244. bool Failed = false;
  1245. for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
  1246. {
  1247. if (printOnly)
  1248. {
  1249. if ((*I)->ErrorText.empty() == false)
  1250. {
  1251. Failed = true;
  1252. _error->Error("%s", (*I)->ErrorText.c_str());
  1253. }
  1254. else
  1255. cout << '\'' << (*I)->DescURI() << "' " << flNotDir((*I)->DestFile) << std::endl;
  1256. }
  1257. else
  1258. DisplayFileInPager((*I)->DestFile);
  1259. }
  1260. return Failed == false;
  1261. }
  1262. return true;
  1263. }
  1264. /*}}}*/
  1265. // DoIndexTargets - Lists all IndexTargets /*{{{*/
  1266. static std::string format_key(std::string key)
  1267. {
  1268. // deb822 is case-insensitive, but the human eye prefers candy
  1269. std::transform(key.begin(), key.end(), key.begin(), ::tolower);
  1270. key[0] = ::toupper(key[0]);
  1271. size_t found = key.find("_uri");
  1272. if (found != std::string::npos)
  1273. key.replace(found, 4, "-URI");
  1274. while ((found = key.find('_')) != std::string::npos)
  1275. {
  1276. key[found] = '-';
  1277. key[found + 1] = ::toupper(key[found + 1]);
  1278. }
  1279. return key;
  1280. }
  1281. static bool DoIndexTargets(CommandLine &CmdL)
  1282. {
  1283. pkgCacheFile CacheFile;
  1284. pkgSourceList *SrcList = CacheFile.GetSourceList();
  1285. if (SrcList == NULL)
  1286. return false;
  1287. std::string const Format = _config->Find("APT::Get::IndexTargets::Format");
  1288. bool const ReleaseInfo = _config->FindB("APT::Get::IndexTargets::ReleaseInfo", true);
  1289. bool Filtered = CmdL.FileSize() > 1;
  1290. for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); ++S)
  1291. {
  1292. std::vector<IndexTarget> const targets = (*S)->GetIndexTargets();
  1293. std::map<std::string, string> AddOptions;
  1294. if (ReleaseInfo)
  1295. {
  1296. AddOptions.insert(std::make_pair("TRUSTED", ((*S)->IsTrusted() ? "yes" : "no")));
  1297. pkgCache &Cache = *CacheFile.GetPkgCache();
  1298. pkgCache::RlsFileIterator const RlsFile = (*S)->FindInCache(Cache, false);
  1299. if (RlsFile.end())
  1300. continue;
  1301. #define APT_RELEASE(X,Y) if (RlsFile.Y() != NULL) AddOptions.insert(std::make_pair(X, RlsFile.Y()))
  1302. APT_RELEASE("CODENAME", Codename);
  1303. APT_RELEASE("SUITE", Archive);
  1304. APT_RELEASE("VERSION", Version);
  1305. APT_RELEASE("ORIGIN", Origin);
  1306. APT_RELEASE("LABEL", Label);
  1307. #undef APT_RELEASE
  1308. }
  1309. for (std::vector<IndexTarget>::const_iterator T = targets.begin(); T != targets.end(); ++T)
  1310. {
  1311. std::string filename = T->Option(ReleaseInfo ? IndexTarget::EXISTING_FILENAME : IndexTarget::FILENAME);
  1312. if (filename.empty())
  1313. continue;
  1314. std::ostringstream stanza;
  1315. if (Filtered || Format.empty())
  1316. {
  1317. stanza << "MetaKey: " << T->MetaKey << "\n"
  1318. << "ShortDesc: " << T->ShortDesc << "\n"
  1319. << "Description: " << T->Description << "\n"
  1320. << "URI: " << T->URI << "\n"
  1321. << "Filename: " << filename << "\n"
  1322. << "Optional: " << (T->IsOptional ? "yes" : "no") << "\n"
  1323. << "KeepCompressed: " << (T->KeepCompressed ? "yes" : "no") << "\n";
  1324. for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O)
  1325. stanza << format_key(O->first) << ": " << O->second << "\n";
  1326. for (std::map<std::string,std::string>::const_iterator O = T->Options.begin(); O != T->Options.end(); ++O)
  1327. {
  1328. if (O->first == "PDIFFS")
  1329. stanza << "PDiffs: " << O->second << "\n";
  1330. else if (O->first == "COMPRESSIONTYPES")
  1331. stanza << "CompressionTypes: " << O->second << "\n";
  1332. else if (O->first == "DEFAULTENABLED")
  1333. stanza << "DefaultEnabled: " << O->second << "\n";
  1334. else
  1335. stanza << format_key(O->first) << ": " << O->second << "\n";
  1336. }
  1337. stanza << "\n";
  1338. if (Filtered)
  1339. {
  1340. // that is a bit crude, but good enough for now
  1341. bool found = true;
  1342. std::string haystack = std::string("\n") + stanza.str() + "\n";
  1343. std::transform(haystack.begin(), haystack.end(), haystack.begin(), ::tolower);
  1344. size_t const filesize = CmdL.FileSize() - 1;
  1345. for (size_t i = 0; i != filesize; ++i)
  1346. {
  1347. std::string needle = std::string("\n") + CmdL.FileList[i + 1] + "\n";
  1348. std::transform(needle.begin(), needle.end(), needle.begin(), ::tolower);
  1349. if (haystack.find(needle) != std::string::npos)
  1350. continue;
  1351. found = false;
  1352. break;
  1353. }
  1354. if (found == false)
  1355. continue;
  1356. }
  1357. }
  1358. if (Format.empty())
  1359. cout << stanza.str();
  1360. else
  1361. {
  1362. std::string out = SubstVar(Format, "$(FILENAME)", filename);
  1363. out = T->Format(out);
  1364. for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O)
  1365. out = SubstVar(out, std::string("$(") + O->first + ")", O->second);
  1366. cout << out << std::endl;
  1367. }
  1368. }
  1369. }
  1370. return true;
  1371. }
  1372. /*}}}*/
  1373. // ShowHelp - Show a help screen /*{{{*/
  1374. // ---------------------------------------------------------------------
  1375. /* */
  1376. static bool ShowHelp(CommandLine &)
  1377. {
  1378. ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
  1379. if (_config->FindB("version") == true)
  1380. {
  1381. cout << _("Supported modules:") << endl;
  1382. for (unsigned I = 0; I != pkgVersioningSystem::GlobalListLen; I++)
  1383. {
  1384. pkgVersioningSystem *VS = pkgVersioningSystem::GlobalList[I];
  1385. if (_system != 0 && _system->VS == VS)
  1386. cout << '*';
  1387. else
  1388. cout << ' ';
  1389. cout << "Ver: " << VS->Label << endl;
  1390. /* Print out all the packaging systems that will work with
  1391. this VS */
  1392. for (unsigned J = 0; J != pkgSystem::GlobalListLen; J++)
  1393. {
  1394. pkgSystem *Sys = pkgSystem::GlobalList[J];
  1395. if (_system == Sys)
  1396. cout << '*';
  1397. else
  1398. cout << ' ';
  1399. if (Sys->VS->TestCompatibility(*VS) == true)
  1400. cout << "Pkg: " << Sys->Label << " (Priority " << Sys->Score(*_config) << ")" << endl;
  1401. }
  1402. }
  1403. for (unsigned I = 0; I != pkgSourceList::Type::GlobalListLen; I++)
  1404. {
  1405. pkgSourceList::Type *Type = pkgSourceList::Type::GlobalList[I];
  1406. cout << " S.L: '" << Type->Name << "' " << Type->Label << endl;
  1407. }
  1408. for (unsigned I = 0; I != pkgIndexFile::Type::GlobalListLen; I++)
  1409. {
  1410. pkgIndexFile::Type *Type = pkgIndexFile::Type::GlobalList[I];
  1411. cout << " Idx: " << Type->Label << endl;
  1412. }
  1413. return true;
  1414. }
  1415. cout <<
  1416. _("Usage: apt-get [options] command\n"
  1417. " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
  1418. " apt-get [options] source pkg1 [pkg2 ...]\n"
  1419. "\n"
  1420. "apt-get is a simple command line interface for downloading and\n"
  1421. "installing packages. The most frequently used commands are update\n"
  1422. "and install.\n"
  1423. "\n"
  1424. "Commands:\n"
  1425. " update - Retrieve new lists of packages\n"
  1426. " upgrade - Perform an upgrade\n"
  1427. " install - Install new packages (pkg is libc6 not libc6.deb)\n"
  1428. " remove - Remove packages\n"
  1429. " autoremove - Remove automatically all unused packages\n"
  1430. " purge - Remove packages and config files\n"
  1431. " source - Download source archives\n"
  1432. " build-dep - Configure build-dependencies for source packages\n"
  1433. " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
  1434. " dselect-upgrade - Follow dselect selections\n"
  1435. " clean - Erase downloaded archive files\n"
  1436. " autoclean - Erase old downloaded archive files\n"
  1437. " check - Verify that there are no broken dependencies\n"
  1438. " changelog - Download and display the changelog for the given package\n"
  1439. " download - Download the binary package into the current directory\n"
  1440. "\n"
  1441. "Options:\n"
  1442. " -h This help text.\n"
  1443. " -q Loggable output - no progress indicator\n"
  1444. " -qq No output except for errors\n"
  1445. " -d Download only - do NOT install or unpack archives\n"
  1446. " -s No-act. Perform ordering simulation\n"
  1447. " -y Assume Yes to all queries and do not prompt\n"
  1448. " -f Attempt to correct a system with broken dependencies in place\n"
  1449. " -m Attempt to continue if archives are unlocatable\n"
  1450. " -u Show a list of upgraded packages as well\n"
  1451. " -b Build the source package after fetching it\n"
  1452. " -V Show verbose version numbers\n"
  1453. " -c=? Read this configuration file\n"
  1454. " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
  1455. "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
  1456. "pages for more information and options.\n"
  1457. " This APT has Super Cow Powers.\n");
  1458. return true;
  1459. }
  1460. /*}}}*/
  1461. int main(int argc,const char *argv[]) /*{{{*/
  1462. {
  1463. CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate},
  1464. {"upgrade",&DoUpgrade},
  1465. {"install",&DoInstall},
  1466. {"remove",&DoInstall},
  1467. {"purge",&DoInstall},
  1468. {"autoremove",&DoInstall},
  1469. {"auto-remove",&DoInstall},
  1470. {"markauto",&DoMarkAuto},
  1471. {"unmarkauto",&DoMarkAuto},
  1472. {"dist-upgrade",&DoDistUpgrade},
  1473. {"full-upgrade",&DoDistUpgrade},
  1474. {"dselect-upgrade",&DoDSelectUpgrade},
  1475. {"build-dep",&DoBuildDep},
  1476. {"clean",&DoClean},
  1477. {"autoclean",&DoAutoClean},
  1478. {"auto-clean",&DoAutoClean},
  1479. {"check",&DoCheck},
  1480. {"source",&DoSource},
  1481. {"download",&DoDownload},
  1482. {"changelog",&DoChangelog},
  1483. {"indextargets",&DoIndexTargets},
  1484. {"moo",&DoMoo},
  1485. {"help",&ShowHelp},
  1486. {0,0}};
  1487. std::vector<CommandLine::Args> Args = getCommandArgs("apt-get", CommandLine::GetCommand(Cmds, argc, argv));
  1488. // Set up gettext support
  1489. setlocale(LC_ALL,"");
  1490. textdomain(PACKAGE);
  1491. // Parse the command line and initialize the package library
  1492. CommandLine CmdL;
  1493. ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
  1494. // see if we are in simulate mode
  1495. CheckSimulateMode(CmdL);
  1496. // Init the signals
  1497. InitSignals();
  1498. // Setup the output streams
  1499. InitOutput();
  1500. // Match the operation
  1501. CmdL.DispatchArg(Cmds);
  1502. // Print any errors or warnings found during parsing
  1503. bool const Errors = _error->PendingError();
  1504. if (_config->FindI("quiet",0) > 0)
  1505. _error->DumpErrors();
  1506. else
  1507. _error->DumpErrors(GlobalError::DEBUG);
  1508. return Errors == true ? 100 : 0;
  1509. }
  1510. /*}}}*/