apt-get.cc 57 KB

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