apt-get.cc 58 KB

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