apt-get.cc 57 KB

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