apt-get.cc 57 KB

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