apt-get.cc 58 KB

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