apt-get.cc 57 KB

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