apt-get.cc 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  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. std::string localFile = flNotDir(I->Path);
  738. if (FileExists(localFile) == true)
  739. if(I->Hashes.VerifyFile(localFile) == true)
  740. {
  741. ioprintf(c1out,_("Skipping already downloaded file '%s'\n"),
  742. localFile.c_str());
  743. continue;
  744. }
  745. // see if we have a hash (Acquire::ForceHash is the only way to have none)
  746. if (I->Hashes.usable() == false && _config->FindB("APT::Get::AllowUnauthenticated",false) == false)
  747. {
  748. ioprintf(c1out, "Skipping download of file '%s' as requested hashsum is not available for authentication\n",
  749. localFile.c_str());
  750. continue;
  751. }
  752. new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path),
  753. I->Hashes, I->Size, Last->Index().SourceInfo(*Last,*I), Src);
  754. }
  755. }
  756. // Display statistics
  757. unsigned long long FetchBytes = Fetcher.FetchNeeded();
  758. unsigned long long FetchPBytes = Fetcher.PartialPresent();
  759. unsigned long long DebBytes = Fetcher.TotalNeeded();
  760. // Check for enough free space
  761. struct statvfs Buf;
  762. string OutputDir = ".";
  763. if (statvfs(OutputDir.c_str(),&Buf) != 0) {
  764. if (errno == EOVERFLOW)
  765. return _error->WarningE("statvfs",_("Couldn't determine free space in %s"),
  766. OutputDir.c_str());
  767. else
  768. return _error->Errno("statvfs",_("Couldn't determine free space in %s"),
  769. OutputDir.c_str());
  770. } else if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
  771. {
  772. struct statfs Stat;
  773. if (statfs(OutputDir.c_str(),&Stat) != 0
  774. #if HAVE_STRUCT_STATFS_F_TYPE
  775. || unsigned(Stat.f_type) != RAMFS_MAGIC
  776. #endif
  777. ) {
  778. return _error->Error(_("You don't have enough free space in %s"),
  779. OutputDir.c_str());
  780. }
  781. }
  782. // Number of bytes
  783. if (DebBytes != FetchBytes)
  784. //TRANSLATOR: The required space between number and unit is already included
  785. // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
  786. ioprintf(c1out,_("Need to get %sB/%sB of source archives.\n"),
  787. SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str());
  788. else
  789. //TRANSLATOR: The required space between number and unit is already included
  790. // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
  791. ioprintf(c1out,_("Need to get %sB of source archives.\n"),
  792. SizeToStr(DebBytes).c_str());
  793. if (_config->FindB("APT::Get::Simulate",false) == true)
  794. {
  795. for (unsigned I = 0; I != J; I++)
  796. ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str());
  797. return true;
  798. }
  799. // Just print out the uris an exit if the --print-uris flag was used
  800. if (_config->FindB("APT::Get::Print-URIs") == true)
  801. {
  802. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  803. for (; I != Fetcher.UriEnd(); ++I)
  804. cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
  805. I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl;
  806. return true;
  807. }
  808. // Run it
  809. bool Failed = false;
  810. if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
  811. {
  812. return _error->Error(_("Failed to fetch some archives."));
  813. }
  814. if (_config->FindB("APT::Get::Download-only",false) == true)
  815. {
  816. c1out << _("Download complete and in download only mode") << endl;
  817. return true;
  818. }
  819. // Unpack the sources
  820. pid_t Process = ExecFork();
  821. if (Process == 0)
  822. {
  823. bool const fixBroken = _config->FindB("APT::Get::Fix-Broken", false);
  824. for (unsigned I = 0; I != J; ++I)
  825. {
  826. string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str());
  827. // Diff only mode only fetches .diff files
  828. if (_config->FindB("APT::Get::Diff-Only",false) == true ||
  829. _config->FindB("APT::Get::Tar-Only",false) == true ||
  830. Dsc[I].Dsc.empty() == true)
  831. continue;
  832. // See if the package is already unpacked
  833. struct stat Stat;
  834. if (fixBroken == false && stat(Dir.c_str(),&Stat) == 0 &&
  835. S_ISDIR(Stat.st_mode) != 0)
  836. {
  837. ioprintf(c0out ,_("Skipping unpack of already unpacked source in %s\n"),
  838. Dir.c_str());
  839. }
  840. else
  841. {
  842. // Call dpkg-source
  843. char S[500];
  844. snprintf(S,sizeof(S),"%s -x %s",
  845. _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
  846. Dsc[I].Dsc.c_str());
  847. if (system(S) != 0)
  848. {
  849. fprintf(stderr,_("Unpack command '%s' failed.\n"),S);
  850. fprintf(stderr,_("Check if the 'dpkg-dev' package is installed.\n"));
  851. _exit(1);
  852. }
  853. }
  854. // Try to compile it with dpkg-buildpackage
  855. if (_config->FindB("APT::Get::Compile",false) == true)
  856. {
  857. string buildopts = _config->Find("APT::Get::Host-Architecture");
  858. if (buildopts.empty() == false)
  859. buildopts = "-a" + buildopts + " ";
  860. // get all active build profiles
  861. std::string const profiles = APT::Configuration::getBuildProfilesString();
  862. if (profiles.empty() == false)
  863. buildopts.append(" -P").append(profiles).append(" ");
  864. buildopts.append(_config->Find("DPkg::Build-Options","-b -uc"));
  865. // Call dpkg-buildpackage
  866. char S[500];
  867. snprintf(S,sizeof(S),"cd %s && %s %s",
  868. Dir.c_str(),
  869. _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
  870. buildopts.c_str());
  871. if (system(S) != 0)
  872. {
  873. fprintf(stderr,_("Build command '%s' failed.\n"),S);
  874. _exit(1);
  875. }
  876. }
  877. }
  878. _exit(0);
  879. }
  880. // Wait for the subprocess
  881. int Status = 0;
  882. while (waitpid(Process,&Status,0) != Process)
  883. {
  884. if (errno == EINTR)
  885. continue;
  886. return _error->Errno("waitpid","Couldn't wait for subprocess");
  887. }
  888. if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
  889. return _error->Error(_("Child process failed"));
  890. return true;
  891. }
  892. /*}}}*/
  893. // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
  894. // ---------------------------------------------------------------------
  895. /* This function will look at the build depends list of the given source
  896. package and install the necessary packages to make it true, or fail. */
  897. static bool DoBuildDep(CommandLine &CmdL)
  898. {
  899. CacheFile Cache;
  900. _config->Set("APT::Install-Recommends", false);
  901. if (Cache.Open(true) == false)
  902. return false;
  903. if (CmdL.FileSize() <= 1)
  904. return _error->Error(_("Must specify at least one package to check builddeps for"));
  905. // Read the source list
  906. if (Cache.BuildSourceList() == false)
  907. return false;
  908. pkgSourceList *List = Cache.GetSourceList();
  909. // Create the text record parsers
  910. pkgRecords Recs(Cache);
  911. pkgSrcRecords SrcRecs(*List);
  912. if (_error->PendingError() == true)
  913. return false;
  914. // Create the download object
  915. AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
  916. pkgAcquire Fetcher;
  917. if (Fetcher.Setup(&Stat) == false)
  918. return false;
  919. bool StripMultiArch;
  920. string hostArch = _config->Find("APT::Get::Host-Architecture");
  921. if (hostArch.empty() == false)
  922. {
  923. std::vector<std::string> archs = APT::Configuration::getArchitectures();
  924. if (std::find(archs.begin(), archs.end(), hostArch) == archs.end())
  925. return _error->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch.c_str());
  926. StripMultiArch = false;
  927. }
  928. else
  929. StripMultiArch = true;
  930. unsigned J = 0;
  931. for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
  932. {
  933. string Src;
  934. pkgSrcRecords::Parser *Last = 0;
  935. // a unpacked debian source tree
  936. if (DirectoryExists(*I))
  937. {
  938. // FIXME: how can we make this more elegant?
  939. std::string TypeName = "debian/control File Source Index";
  940. pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
  941. if(Type != NULL)
  942. Last = Type->CreateSrcPkgParser(*I);
  943. }
  944. // if its a local file (e.g. .dsc) use this
  945. else if (FileExists(*I))
  946. {
  947. // see if we can get a parser for this pkgIndexFile type
  948. string TypeName = flExtension(*I) + " File Source Index";
  949. pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
  950. if(Type != NULL)
  951. Last = Type->CreateSrcPkgParser(*I);
  952. } else {
  953. // normal case, search the cache for the source file
  954. Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
  955. }
  956. if (Last == 0)
  957. return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
  958. // Process the build-dependencies
  959. vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps;
  960. // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
  961. if (hostArch.empty() == false)
  962. {
  963. std::string nativeArch = _config->Find("APT::Architecture");
  964. _config->Set("APT::Architecture", hostArch);
  965. bool Success = Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch);
  966. _config->Set("APT::Architecture", nativeArch);
  967. if (Success == false)
  968. return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
  969. }
  970. else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
  971. return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
  972. // Also ensure that build-essential packages are present
  973. Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
  974. if (Opts)
  975. Opts = Opts->Child;
  976. for (; Opts; Opts = Opts->Next)
  977. {
  978. if (Opts->Value.empty() == true)
  979. continue;
  980. pkgSrcRecords::Parser::BuildDepRec rec;
  981. rec.Package = Opts->Value;
  982. rec.Type = pkgSrcRecords::Parser::BuildDependIndep;
  983. rec.Op = 0;
  984. BuildDeps.push_back(rec);
  985. }
  986. if (BuildDeps.empty() == true)
  987. {
  988. ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str());
  989. continue;
  990. }
  991. // Install the requested packages
  992. vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D;
  993. pkgProblemResolver Fix(Cache);
  994. bool skipAlternatives = false; // skip remaining alternatives in an or group
  995. for (D = BuildDeps.begin(); D != BuildDeps.end(); ++D)
  996. {
  997. bool hasAlternatives = (((*D).Op & pkgCache::Dep::Or) == pkgCache::Dep::Or);
  998. if (skipAlternatives == true)
  999. {
  1000. /*
  1001. * if there are alternatives, we've already picked one, so skip
  1002. * the rest
  1003. *
  1004. * TODO: this means that if there's a build-dep on A|B and B is
  1005. * installed, we'll still try to install A; more importantly,
  1006. * if A is currently broken, we cannot go back and try B. To fix
  1007. * this would require we do a Resolve cycle for each package we
  1008. * add to the install list. Ugh
  1009. */
  1010. if (!hasAlternatives)
  1011. skipAlternatives = false; // end of or group
  1012. continue;
  1013. }
  1014. if ((*D).Type == pkgSrcRecords::Parser::BuildConflict ||
  1015. (*D).Type == pkgSrcRecords::Parser::BuildConflictIndep)
  1016. {
  1017. pkgCache::GrpIterator Grp = Cache->FindGrp((*D).Package);
  1018. // Build-conflicts on unknown packages are silently ignored
  1019. if (Grp.end() == true)
  1020. continue;
  1021. for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
  1022. {
  1023. pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
  1024. /*
  1025. * Remove if we have an installed version that satisfies the
  1026. * version criteria
  1027. */
  1028. if (IV.end() == false &&
  1029. Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
  1030. TryToInstallBuildDep(Pkg,Cache,Fix,true,false);
  1031. }
  1032. }
  1033. else // BuildDep || BuildDepIndep
  1034. {
  1035. if (_config->FindB("Debug::BuildDeps",false) == true)
  1036. cout << "Looking for " << (*D).Package << "...\n";
  1037. pkgCache::PkgIterator Pkg;
  1038. // Cross-Building?
  1039. if (StripMultiArch == false && D->Type != pkgSrcRecords::Parser::BuildDependIndep)
  1040. {
  1041. size_t const colon = D->Package.find(":");
  1042. if (colon != string::npos)
  1043. {
  1044. if (strcmp(D->Package.c_str() + colon, ":any") == 0 || strcmp(D->Package.c_str() + colon, ":native") == 0)
  1045. Pkg = Cache->FindPkg(D->Package.substr(0,colon));
  1046. else
  1047. Pkg = Cache->FindPkg(D->Package);
  1048. }
  1049. else
  1050. Pkg = Cache->FindPkg(D->Package, hostArch);
  1051. // a bad version either is invalid or doesn't satify dependency
  1052. #define BADVER(Ver) (Ver.end() == true || \
  1053. (D->Version.empty() == false && \
  1054. Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false))
  1055. APT::VersionList verlist;
  1056. if (Pkg.end() == false)
  1057. {
  1058. pkgCache::VerIterator Ver = (*Cache)[Pkg].InstVerIter(*Cache);
  1059. if (BADVER(Ver) == false)
  1060. verlist.insert(Ver);
  1061. Ver = (*Cache)[Pkg].CandidateVerIter(*Cache);
  1062. if (BADVER(Ver) == false)
  1063. verlist.insert(Ver);
  1064. }
  1065. if (verlist.empty() == true)
  1066. {
  1067. pkgCache::PkgIterator BuildPkg = Cache->FindPkg(D->Package, "native");
  1068. if (BuildPkg.end() == false && Pkg != BuildPkg)
  1069. {
  1070. pkgCache::VerIterator Ver = (*Cache)[BuildPkg].InstVerIter(*Cache);
  1071. if (BADVER(Ver) == false)
  1072. verlist.insert(Ver);
  1073. Ver = (*Cache)[BuildPkg].CandidateVerIter(*Cache);
  1074. if (BADVER(Ver) == false)
  1075. verlist.insert(Ver);
  1076. }
  1077. }
  1078. #undef BADVER
  1079. string forbidden;
  1080. // We need to decide if host or build arch, so find a version we can look at
  1081. APT::VersionList::const_iterator Ver = verlist.begin();
  1082. for (; Ver != verlist.end(); ++Ver)
  1083. {
  1084. forbidden.clear();
  1085. if (Ver->MultiArch == pkgCache::Version::None || Ver->MultiArch == pkgCache::Version::All)
  1086. {
  1087. if (colon == string::npos)
  1088. Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
  1089. else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
  1090. forbidden = "Multi-Arch: none";
  1091. else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
  1092. Pkg = Ver.ParentPkg().Group().FindPkg("native");
  1093. }
  1094. else if (Ver->MultiArch == pkgCache::Version::Same)
  1095. {
  1096. if (colon == string::npos)
  1097. Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
  1098. else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
  1099. forbidden = "Multi-Arch: same";
  1100. else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
  1101. Pkg = Ver.ParentPkg().Group().FindPkg("native");
  1102. }
  1103. else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
  1104. {
  1105. if (colon == string::npos)
  1106. Pkg = Ver.ParentPkg().Group().FindPkg("native");
  1107. else if (strcmp(D->Package.c_str() + colon, ":any") == 0 ||
  1108. strcmp(D->Package.c_str() + colon, ":native") == 0)
  1109. forbidden = "Multi-Arch: foreign";
  1110. }
  1111. else if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
  1112. {
  1113. if (colon == string::npos)
  1114. Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
  1115. else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
  1116. {
  1117. // prefer any installed over preferred non-installed architectures
  1118. pkgCache::GrpIterator Grp = Ver.ParentPkg().Group();
  1119. // we don't check for version here as we are better of with upgrading than remove and install
  1120. for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg))
  1121. if (Pkg.CurrentVer().end() == false)
  1122. break;
  1123. if (Pkg.end() == true)
  1124. Pkg = Grp.FindPreferredPkg(true);
  1125. }
  1126. else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
  1127. Pkg = Ver.ParentPkg().Group().FindPkg("native");
  1128. }
  1129. if (forbidden.empty() == false)
  1130. {
  1131. if (_config->FindB("Debug::BuildDeps",false) == true)
  1132. cout << D->Package.substr(colon, string::npos) << " is not allowed from " << forbidden << " package " << (*D).Package << " (" << Ver.VerStr() << ")" << endl;
  1133. continue;
  1134. }
  1135. //we found a good version
  1136. break;
  1137. }
  1138. if (Ver == verlist.end())
  1139. {
  1140. if (_config->FindB("Debug::BuildDeps",false) == true)
  1141. cout << " No multiarch info as we have no satisfying installed nor candidate for " << D->Package << " on build or host arch" << endl;
  1142. if (forbidden.empty() == false)
  1143. {
  1144. if (hasAlternatives)
  1145. continue;
  1146. return _error->Error(_("%s dependency for %s can't be satisfied "
  1147. "because %s is not allowed on '%s' packages"),
  1148. Last->BuildDepType(D->Type), Src.c_str(),
  1149. D->Package.c_str(), forbidden.c_str());
  1150. }
  1151. }
  1152. }
  1153. else
  1154. Pkg = Cache->FindPkg(D->Package);
  1155. if (Pkg.end() == true || (Pkg->VersionList == 0 && Pkg->ProvidesList == 0))
  1156. {
  1157. if (_config->FindB("Debug::BuildDeps",false) == true)
  1158. cout << " (not found)" << (*D).Package << endl;
  1159. if (hasAlternatives)
  1160. continue;
  1161. return _error->Error(_("%s dependency for %s cannot be satisfied "
  1162. "because the package %s cannot be found"),
  1163. Last->BuildDepType((*D).Type),Src.c_str(),
  1164. (*D).Package.c_str());
  1165. }
  1166. pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
  1167. if (IV.end() == false)
  1168. {
  1169. if (_config->FindB("Debug::BuildDeps",false) == true)
  1170. cout << " Is installed\n";
  1171. if (D->Version.empty() == true ||
  1172. Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
  1173. {
  1174. skipAlternatives = hasAlternatives;
  1175. continue;
  1176. }
  1177. if (_config->FindB("Debug::BuildDeps",false) == true)
  1178. cout << " ...but the installed version doesn't meet the version requirement\n";
  1179. if (((*D).Op & pkgCache::Dep::LessEq) == pkgCache::Dep::LessEq)
  1180. return _error->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
  1181. Last->BuildDepType((*D).Type), Src.c_str(), Pkg.FullName(true).c_str());
  1182. }
  1183. // Only consider virtual packages if there is no versioned dependency
  1184. if ((*D).Version.empty() == true)
  1185. {
  1186. /*
  1187. * If this is a virtual package, we need to check the list of
  1188. * packages that provide it and see if any of those are
  1189. * installed
  1190. */
  1191. pkgCache::PrvIterator Prv = Pkg.ProvidesList();
  1192. for (; Prv.end() != true; ++Prv)
  1193. {
  1194. if (_config->FindB("Debug::BuildDeps",false) == true)
  1195. cout << " Checking provider " << Prv.OwnerPkg().FullName() << endl;
  1196. if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false)
  1197. break;
  1198. }
  1199. if (Prv.end() == false)
  1200. {
  1201. if (_config->FindB("Debug::BuildDeps",false) == true)
  1202. cout << " Is provided by installed package " << Prv.OwnerPkg().FullName() << endl;
  1203. skipAlternatives = hasAlternatives;
  1204. continue;
  1205. }
  1206. }
  1207. else // versioned dependency
  1208. {
  1209. pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache);
  1210. if (CV.end() == true ||
  1211. Cache->VS().CheckDep(CV.VerStr(),(*D).Op,(*D).Version.c_str()) == false)
  1212. {
  1213. if (hasAlternatives)
  1214. continue;
  1215. else if (CV.end() == false)
  1216. return _error->Error(_("%s dependency for %s cannot be satisfied "
  1217. "because candidate version of package %s "
  1218. "can't satisfy version requirements"),
  1219. Last->BuildDepType(D->Type), Src.c_str(),
  1220. D->Package.c_str());
  1221. else
  1222. return _error->Error(_("%s dependency for %s cannot be satisfied "
  1223. "because package %s has no candidate version"),
  1224. Last->BuildDepType(D->Type), Src.c_str(),
  1225. D->Package.c_str());
  1226. }
  1227. }
  1228. if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false,false) == true)
  1229. {
  1230. // We successfully installed something; skip remaining alternatives
  1231. skipAlternatives = hasAlternatives;
  1232. if(_config->FindB("APT::Get::Build-Dep-Automatic", false) == true)
  1233. Cache->MarkAuto(Pkg, true);
  1234. continue;
  1235. }
  1236. else if (hasAlternatives)
  1237. {
  1238. if (_config->FindB("Debug::BuildDeps",false) == true)
  1239. cout << " Unsatisfiable, trying alternatives\n";
  1240. continue;
  1241. }
  1242. else
  1243. {
  1244. return _error->Error(_("Failed to satisfy %s dependency for %s: %s"),
  1245. Last->BuildDepType((*D).Type),
  1246. Src.c_str(),
  1247. (*D).Package.c_str());
  1248. }
  1249. }
  1250. }
  1251. if (Fix.Resolve(true) == false)
  1252. _error->Discard();
  1253. // Now we check the state of the packages,
  1254. if (Cache->BrokenCount() != 0)
  1255. {
  1256. ShowBroken(cout, Cache, false);
  1257. return _error->Error(_("Build-dependencies for %s could not be satisfied."),*I);
  1258. }
  1259. }
  1260. if (InstallPackages(Cache, false, true) == false)
  1261. return _error->Error(_("Failed to process build dependencies"));
  1262. return true;
  1263. }
  1264. /*}}}*/
  1265. // GetChangelogPath - return a path pointing to a changelog file or dir /*{{{*/
  1266. // ---------------------------------------------------------------------
  1267. /* This returns a "path" string for the changelog url construction.
  1268. * Please note that its not complete, it either needs a "/changelog"
  1269. * appended (for the packages.debian.org/changelogs site) or a
  1270. * ".changelog" (for third party sites that store the changelog in the
  1271. * pool/ next to the deb itself)
  1272. * Example return: "pool/main/a/apt/apt_0.8.8ubuntu3"
  1273. */
  1274. static string GetChangelogPath(CacheFile &Cache,
  1275. pkgCache::PkgIterator Pkg,
  1276. pkgCache::VerIterator Ver)
  1277. {
  1278. string path;
  1279. pkgRecords Recs(Cache);
  1280. pkgRecords::Parser &rec=Recs.Lookup(Ver.FileList());
  1281. string srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg();
  1282. string ver = Ver.VerStr();
  1283. // if there is a source version it always wins
  1284. if (rec.SourceVer() != "")
  1285. ver = rec.SourceVer();
  1286. path = flNotFile(rec.FileName());
  1287. path += srcpkg + "_" + StripEpoch(ver);
  1288. return path;
  1289. }
  1290. /*}}}*/
  1291. // GuessThirdPartyChangelogUri - return url /*{{{*/
  1292. // ---------------------------------------------------------------------
  1293. /* Contruct a changelog file path for third party sites that do not use
  1294. * packages.debian.org/changelogs
  1295. * This simply uses the ArchiveURI() of the source pkg and looks for
  1296. * a .changelog file there, Example for "mediabuntu":
  1297. * apt-get changelog mplayer-doc:
  1298. * http://packages.medibuntu.org/pool/non-free/m/mplayer/mplayer_1.0~rc4~try1.dsfg1-1ubuntu1+medibuntu1.changelog
  1299. */
  1300. static bool GuessThirdPartyChangelogUri(CacheFile &Cache,
  1301. pkgCache::PkgIterator Pkg,
  1302. pkgCache::VerIterator Ver,
  1303. string &out_uri)
  1304. {
  1305. // get the binary deb server path
  1306. pkgCache::VerFileIterator Vf = Ver.FileList();
  1307. if (Vf.end() == true)
  1308. return false;
  1309. pkgCache::PkgFileIterator F = Vf.File();
  1310. pkgIndexFile *index;
  1311. pkgSourceList *SrcList = Cache.GetSourceList();
  1312. if(SrcList->FindIndex(F, index) == false)
  1313. return false;
  1314. // get archive uri for the binary deb
  1315. string path_without_dot_changelog = GetChangelogPath(Cache, Pkg, Ver);
  1316. out_uri = index->ArchiveURI(path_without_dot_changelog + ".changelog");
  1317. // now strip away the filename and add srcpkg_srcver.changelog
  1318. return true;
  1319. }
  1320. /*}}}*/
  1321. // DownloadChangelog - Download the changelog /*{{{*/
  1322. // ---------------------------------------------------------------------
  1323. static bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher,
  1324. pkgCache::VerIterator Ver, string targetfile)
  1325. /* Download a changelog file for the given package version to
  1326. * targetfile. This will first try the server from Apt::Changelogs::Server
  1327. * (http://packages.debian.org/changelogs by default) and if that gives
  1328. * a 404 tries to get it from the archive directly (see
  1329. * GuessThirdPartyChangelogUri for details how)
  1330. */
  1331. {
  1332. string path;
  1333. string descr;
  1334. string server;
  1335. string changelog_uri;
  1336. // data structures we need
  1337. pkgCache::PkgIterator Pkg = Ver.ParentPkg();
  1338. // make the server root configurable
  1339. server = _config->Find("Apt::Changelogs::Server",
  1340. "http://packages.debian.org/changelogs");
  1341. path = GetChangelogPath(CacheFile, Pkg, Ver);
  1342. strprintf(changelog_uri, "%s/%s/changelog", server.c_str(), path.c_str());
  1343. if (_config->FindB("APT::Get::Print-URIs", false) == true)
  1344. {
  1345. std::cout << '\'' << changelog_uri << '\'' << std::endl;
  1346. return true;
  1347. }
  1348. strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), changelog_uri.c_str());
  1349. // queue it
  1350. new pkgAcqFile(&Fetcher, changelog_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile);
  1351. // try downloading it, if that fails, try third-party-changelogs location
  1352. // FIXME: Fetcher.Run() is "Continue" even if I get a 404?!?
  1353. Fetcher.Run();
  1354. if (!FileExists(targetfile))
  1355. {
  1356. string third_party_uri;
  1357. if (GuessThirdPartyChangelogUri(CacheFile, Pkg, Ver, third_party_uri))
  1358. {
  1359. strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), third_party_uri.c_str());
  1360. new pkgAcqFile(&Fetcher, third_party_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile);
  1361. Fetcher.Run();
  1362. }
  1363. }
  1364. if (FileExists(targetfile))
  1365. return true;
  1366. // error
  1367. return _error->Error("changelog download failed");
  1368. }
  1369. /*}}}*/
  1370. // DoChangelog - Get changelog from the command line /*{{{*/
  1371. // ---------------------------------------------------------------------
  1372. static bool DoChangelog(CommandLine &CmdL)
  1373. {
  1374. CacheFile Cache;
  1375. if (Cache.ReadOnlyOpen() == false)
  1376. return false;
  1377. APT::CacheSetHelper helper(c0out);
  1378. APT::VersionList verset = APT::VersionList::FromCommandLine(Cache,
  1379. CmdL.FileList + 1, APT::VersionList::CANDIDATE, helper);
  1380. if (verset.empty() == true)
  1381. return false;
  1382. pkgAcquire Fetcher;
  1383. if (_config->FindB("APT::Get::Print-URIs", false) == true)
  1384. {
  1385. bool Success = true;
  1386. for (APT::VersionList::const_iterator Ver = verset.begin();
  1387. Ver != verset.end(); ++Ver)
  1388. Success &= DownloadChangelog(Cache, Fetcher, Ver, "");
  1389. return Success;
  1390. }
  1391. AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0));
  1392. Fetcher.Setup(&Stat);
  1393. bool const downOnly = _config->FindB("APT::Get::Download-Only", false);
  1394. char tmpname[100];
  1395. const char* tmpdir = NULL;
  1396. if (downOnly == false)
  1397. {
  1398. std::string systemTemp = GetTempDir();
  1399. snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX",
  1400. systemTemp.c_str());
  1401. tmpdir = mkdtemp(tmpname);
  1402. if (tmpdir == NULL)
  1403. return _error->Errno("mkdtemp", "mkdtemp failed");
  1404. }
  1405. for (APT::VersionList::const_iterator Ver = verset.begin();
  1406. Ver != verset.end();
  1407. ++Ver)
  1408. {
  1409. string changelogfile;
  1410. if (downOnly == false)
  1411. changelogfile.append(tmpname).append("changelog");
  1412. else
  1413. changelogfile.append(Ver.ParentPkg().Name()).append(".changelog");
  1414. if (DownloadChangelog(Cache, Fetcher, Ver, changelogfile) && downOnly == false)
  1415. {
  1416. DisplayFileInPager(changelogfile);
  1417. // cleanup temp file
  1418. unlink(changelogfile.c_str());
  1419. }
  1420. }
  1421. // clenaup tmp dir
  1422. if (tmpdir != NULL)
  1423. rmdir(tmpdir);
  1424. return true;
  1425. }
  1426. /*}}}*/
  1427. // ShowHelp - Show a help screen /*{{{*/
  1428. // ---------------------------------------------------------------------
  1429. /* */
  1430. static bool ShowHelp(CommandLine &)
  1431. {
  1432. ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
  1433. COMMON_ARCH,__DATE__,__TIME__);
  1434. if (_config->FindB("version") == true)
  1435. {
  1436. cout << _("Supported modules:") << endl;
  1437. for (unsigned I = 0; I != pkgVersioningSystem::GlobalListLen; I++)
  1438. {
  1439. pkgVersioningSystem *VS = pkgVersioningSystem::GlobalList[I];
  1440. if (_system != 0 && _system->VS == VS)
  1441. cout << '*';
  1442. else
  1443. cout << ' ';
  1444. cout << "Ver: " << VS->Label << endl;
  1445. /* Print out all the packaging systems that will work with
  1446. this VS */
  1447. for (unsigned J = 0; J != pkgSystem::GlobalListLen; J++)
  1448. {
  1449. pkgSystem *Sys = pkgSystem::GlobalList[J];
  1450. if (_system == Sys)
  1451. cout << '*';
  1452. else
  1453. cout << ' ';
  1454. if (Sys->VS->TestCompatibility(*VS) == true)
  1455. cout << "Pkg: " << Sys->Label << " (Priority " << Sys->Score(*_config) << ")" << endl;
  1456. }
  1457. }
  1458. for (unsigned I = 0; I != pkgSourceList::Type::GlobalListLen; I++)
  1459. {
  1460. pkgSourceList::Type *Type = pkgSourceList::Type::GlobalList[I];
  1461. cout << " S.L: '" << Type->Name << "' " << Type->Label << endl;
  1462. }
  1463. for (unsigned I = 0; I != pkgIndexFile::Type::GlobalListLen; I++)
  1464. {
  1465. pkgIndexFile::Type *Type = pkgIndexFile::Type::GlobalList[I];
  1466. cout << " Idx: " << Type->Label << endl;
  1467. }
  1468. return true;
  1469. }
  1470. cout <<
  1471. _("Usage: apt-get [options] command\n"
  1472. " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
  1473. " apt-get [options] source pkg1 [pkg2 ...]\n"
  1474. "\n"
  1475. "apt-get is a simple command line interface for downloading and\n"
  1476. "installing packages. The most frequently used commands are update\n"
  1477. "and install.\n"
  1478. "\n"
  1479. "Commands:\n"
  1480. " update - Retrieve new lists of packages\n"
  1481. " upgrade - Perform an upgrade\n"
  1482. " install - Install new packages (pkg is libc6 not libc6.deb)\n"
  1483. " remove - Remove packages\n"
  1484. " autoremove - Remove automatically all unused packages\n"
  1485. " purge - Remove packages and config files\n"
  1486. " source - Download source archives\n"
  1487. " build-dep - Configure build-dependencies for source packages\n"
  1488. " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
  1489. " dselect-upgrade - Follow dselect selections\n"
  1490. " clean - Erase downloaded archive files\n"
  1491. " autoclean - Erase old downloaded archive files\n"
  1492. " check - Verify that there are no broken dependencies\n"
  1493. " changelog - Download and display the changelog for the given package\n"
  1494. " download - Download the binary package into the current directory\n"
  1495. "\n"
  1496. "Options:\n"
  1497. " -h This help text.\n"
  1498. " -q Loggable output - no progress indicator\n"
  1499. " -qq No output except for errors\n"
  1500. " -d Download only - do NOT install or unpack archives\n"
  1501. " -s No-act. Perform ordering simulation\n"
  1502. " -y Assume Yes to all queries and do not prompt\n"
  1503. " -f Attempt to correct a system with broken dependencies in place\n"
  1504. " -m Attempt to continue if archives are unlocatable\n"
  1505. " -u Show a list of upgraded packages as well\n"
  1506. " -b Build the source package after fetching it\n"
  1507. " -V Show verbose version numbers\n"
  1508. " -c=? Read this configuration file\n"
  1509. " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
  1510. "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
  1511. "pages for more information and options.\n"
  1512. " This APT has Super Cow Powers.\n");
  1513. return true;
  1514. }
  1515. /*}}}*/
  1516. int main(int argc,const char *argv[]) /*{{{*/
  1517. {
  1518. CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate},
  1519. {"upgrade",&DoUpgrade},
  1520. {"install",&DoInstall},
  1521. {"remove",&DoInstall},
  1522. {"purge",&DoInstall},
  1523. {"autoremove",&DoInstall},
  1524. {"markauto",&DoMarkAuto},
  1525. {"unmarkauto",&DoMarkAuto},
  1526. {"dist-upgrade",&DoDistUpgrade},
  1527. {"dselect-upgrade",&DoDSelectUpgrade},
  1528. {"build-dep",&DoBuildDep},
  1529. {"clean",&DoClean},
  1530. {"autoclean",&DoAutoClean},
  1531. {"check",&DoCheck},
  1532. {"source",&DoSource},
  1533. {"download",&DoDownload},
  1534. {"changelog",&DoChangelog},
  1535. {"moo",&DoMoo},
  1536. {"help",&ShowHelp},
  1537. {0,0}};
  1538. std::vector<CommandLine::Args> Args = getCommandArgs("apt-get", CommandLine::GetCommand(Cmds, argc, argv));
  1539. // Set up gettext support
  1540. setlocale(LC_ALL,"");
  1541. textdomain(PACKAGE);
  1542. // Parse the command line and initialize the package library
  1543. CommandLine CmdL(Args.data(),_config);
  1544. if (pkgInitConfig(*_config) == false ||
  1545. CmdL.Parse(argc,argv) == false ||
  1546. pkgInitSystem(*_config,_system) == false)
  1547. {
  1548. if (_config->FindB("version") == true)
  1549. ShowHelp(CmdL);
  1550. _error->DumpErrors();
  1551. return 100;
  1552. }
  1553. // See if the help should be shown
  1554. if (_config->FindB("help") == true ||
  1555. _config->FindB("version") == true ||
  1556. CmdL.FileSize() == 0)
  1557. {
  1558. ShowHelp(CmdL);
  1559. return 0;
  1560. }
  1561. // see if we are in simulate mode
  1562. CheckSimulateMode(CmdL);
  1563. // Init the signals
  1564. InitSignals();
  1565. // Setup the output streams
  1566. InitOutput();
  1567. // Match the operation
  1568. CmdL.DispatchArg(Cmds);
  1569. // Print any errors or warnings found during parsing
  1570. bool const Errors = _error->PendingError();
  1571. if (_config->FindI("quiet",0) > 0)
  1572. _error->DumpErrors();
  1573. else
  1574. _error->DumpErrors(GlobalError::DEBUG);
  1575. return Errors == true ? 100 : 0;
  1576. }
  1577. /*}}}*/