apt-get.cc 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: apt-get.cc,v 1.138 2003/08/09 03:07:03 mdz Exp $
  4. /* ######################################################################
  5. apt-get - Cover for dpkg
  6. This is an allout cover for dpkg implementing a safer front end. It is
  7. based largely on libapt-pkg.
  8. The syntax is different,
  9. apt-get [opt] command [things]
  10. Where command is:
  11. update - Resyncronize the package files from their sources
  12. upgrade - Smart-Download the newest versions of all packages
  13. dselect-upgrade - Follows dselect's changes to the Status: field
  14. and installes new and removes old packages
  15. dist-upgrade - Powerfull upgrader designed to handle the issues with
  16. a new distribution.
  17. install - Download and install a given package (by name, not by .deb)
  18. check - Update the package cache and check for broken packages
  19. clean - Erase the .debs downloaded to /var/cache/apt/archives and
  20. the partial dir too
  21. ##################################################################### */
  22. /*}}}*/
  23. // Include Files /*{{{*/
  24. #include <apt-pkg/error.h>
  25. #include <apt-pkg/cmndline.h>
  26. #include <apt-pkg/init.h>
  27. #include <apt-pkg/depcache.h>
  28. #include <apt-pkg/sourcelist.h>
  29. #include <apt-pkg/algorithms.h>
  30. #include <apt-pkg/acquire-item.h>
  31. #include <apt-pkg/strutl.h>
  32. #include <apt-pkg/clean.h>
  33. #include <apt-pkg/srcrecords.h>
  34. #include <apt-pkg/version.h>
  35. #include <apt-pkg/cachefile.h>
  36. #include <apt-pkg/sptr.h>
  37. #include <apt-pkg/versionmatch.h>
  38. #include <config.h>
  39. #include <apti18n.h>
  40. #include "acqprogress.h"
  41. #include <locale.h>
  42. #include <fstream>
  43. #include <termios.h>
  44. #include <sys/ioctl.h>
  45. #include <sys/stat.h>
  46. #include <sys/statvfs.h>
  47. #include <signal.h>
  48. #include <unistd.h>
  49. #include <stdio.h>
  50. #include <errno.h>
  51. #include <regex.h>
  52. #include <sys/wait.h>
  53. /*}}}*/
  54. using namespace std;
  55. ostream c0out(0);
  56. ostream c1out(0);
  57. ostream c2out(0);
  58. ofstream devnull("/dev/null");
  59. unsigned int ScreenWidth = 80;
  60. // class CacheFile - Cover class for some dependency cache functions /*{{{*/
  61. // ---------------------------------------------------------------------
  62. /* */
  63. class CacheFile : public pkgCacheFile
  64. {
  65. static pkgCache *SortCache;
  66. static int NameComp(const void *a,const void *b);
  67. public:
  68. pkgCache::Package **List;
  69. void Sort();
  70. bool CheckDeps(bool AllowBroken = false);
  71. bool BuildCaches(bool WithLock = true)
  72. {
  73. OpTextProgress Prog(*_config);
  74. if (pkgCacheFile::BuildCaches(Prog,WithLock) == false)
  75. return false;
  76. return true;
  77. }
  78. bool Open(bool WithLock = true)
  79. {
  80. OpTextProgress Prog(*_config);
  81. if (pkgCacheFile::Open(Prog,WithLock) == false)
  82. return false;
  83. Sort();
  84. return true;
  85. };
  86. bool OpenForInstall()
  87. {
  88. if (_config->FindB("APT::Get::Print-URIs") == true)
  89. return Open(false);
  90. else
  91. return Open(true);
  92. }
  93. CacheFile() : List(0) {};
  94. };
  95. /*}}}*/
  96. // YnPrompt - Yes No Prompt. /*{{{*/
  97. // ---------------------------------------------------------------------
  98. /* Returns true on a Yes.*/
  99. bool YnPrompt()
  100. {
  101. if (_config->FindB("APT::Get::Assume-Yes",false) == true)
  102. {
  103. c1out << _("Y") << endl;
  104. return true;
  105. }
  106. char response[1024] = "";
  107. cin.getline(response, sizeof(response));
  108. if (!cin)
  109. return false;
  110. if (strlen(response) == 0)
  111. return true;
  112. regex_t Pattern;
  113. int Res;
  114. Res = regcomp(&Pattern, nl_langinfo(YESEXPR),
  115. REG_EXTENDED|REG_ICASE|REG_NOSUB);
  116. if (Res != 0) {
  117. char Error[300];
  118. regerror(Res,&Pattern,Error,sizeof(Error));
  119. return _error->Error(_("Regex compilation error - %s"),Error);
  120. }
  121. Res = regexec(&Pattern, response, 0, NULL, 0);
  122. if (Res == 0)
  123. return true;
  124. return false;
  125. }
  126. /*}}}*/
  127. // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
  128. // ---------------------------------------------------------------------
  129. /* Returns true on a Yes.*/
  130. bool AnalPrompt(const char *Text)
  131. {
  132. char Buf[1024];
  133. cin.getline(Buf,sizeof(Buf));
  134. if (strcmp(Buf,Text) == 0)
  135. return true;
  136. return false;
  137. }
  138. /*}}}*/
  139. // ShowList - Show a list /*{{{*/
  140. // ---------------------------------------------------------------------
  141. /* This prints out a string of space separated words with a title and
  142. a two space indent line wraped to the current screen width. */
  143. bool ShowList(ostream &out,string Title,string List,string VersionsList)
  144. {
  145. if (List.empty() == true)
  146. return true;
  147. // trim trailing space
  148. int NonSpace = List.find_last_not_of(' ');
  149. if (NonSpace != -1)
  150. {
  151. List = List.erase(NonSpace + 1);
  152. if (List.empty() == true)
  153. return true;
  154. }
  155. // Acount for the leading space
  156. int ScreenWidth = ::ScreenWidth - 3;
  157. out << Title << endl;
  158. string::size_type Start = 0;
  159. string::size_type VersionsStart = 0;
  160. while (Start < List.size())
  161. {
  162. if(_config->FindB("APT::Get::Show-Versions",false) == true &&
  163. VersionsList.size() > 0) {
  164. string::size_type End;
  165. string::size_type VersionsEnd;
  166. End = List.find(' ',Start);
  167. VersionsEnd = VersionsList.find('\n', VersionsStart);
  168. out << " " << string(List,Start,End - Start) << " (" <<
  169. string(VersionsList,VersionsStart,VersionsEnd - VersionsStart) <<
  170. ")" << endl;
  171. if (End == string::npos || End < Start)
  172. End = Start + ScreenWidth;
  173. Start = End + 1;
  174. VersionsStart = VersionsEnd + 1;
  175. } else {
  176. string::size_type End;
  177. if (Start + ScreenWidth >= List.size())
  178. End = List.size();
  179. else
  180. End = List.rfind(' ',Start+ScreenWidth);
  181. if (End == string::npos || End < Start)
  182. End = Start + ScreenWidth;
  183. out << " " << string(List,Start,End - Start) << endl;
  184. Start = End + 1;
  185. }
  186. }
  187. return false;
  188. }
  189. /*}}}*/
  190. // ShowBroken - Debugging aide /*{{{*/
  191. // ---------------------------------------------------------------------
  192. /* This prints out the names of all the packages that are broken along
  193. with the name of each each broken dependency and a quite version
  194. description.
  195. The output looks like:
  196. The following packages have unmet dependencies:
  197. exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
  198. Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
  199. Depends: libsasl7 but it is not going to be installed
  200. */
  201. void ShowBroken(ostream &out,CacheFile &Cache,bool Now)
  202. {
  203. out << _("The following packages have unmet dependencies:") << endl;
  204. for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
  205. {
  206. pkgCache::PkgIterator I(Cache,Cache.List[J]);
  207. if (Now == true)
  208. {
  209. if (Cache[I].NowBroken() == false)
  210. continue;
  211. }
  212. else
  213. {
  214. if (Cache[I].InstBroken() == false)
  215. continue;
  216. }
  217. // Print out each package and the failed dependencies
  218. out <<" " << I.Name() << ":";
  219. unsigned Indent = strlen(I.Name()) + 3;
  220. bool First = true;
  221. pkgCache::VerIterator Ver;
  222. if (Now == true)
  223. Ver = I.CurrentVer();
  224. else
  225. Ver = Cache[I].InstVerIter(Cache);
  226. if (Ver.end() == true)
  227. {
  228. out << endl;
  229. continue;
  230. }
  231. for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;)
  232. {
  233. // Compute a single dependency element (glob or)
  234. pkgCache::DepIterator Start;
  235. pkgCache::DepIterator End;
  236. D.GlobOr(Start,End);
  237. if (Cache->IsImportantDep(End) == false)
  238. continue;
  239. if (Now == true)
  240. {
  241. if ((Cache[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow)
  242. continue;
  243. }
  244. else
  245. {
  246. if ((Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
  247. continue;
  248. }
  249. bool FirstOr = true;
  250. while (1)
  251. {
  252. if (First == false)
  253. for (unsigned J = 0; J != Indent; J++)
  254. out << ' ';
  255. First = false;
  256. if (FirstOr == false)
  257. {
  258. for (unsigned J = 0; J != strlen(End.DepType()) + 3; J++)
  259. out << ' ';
  260. }
  261. else
  262. out << ' ' << End.DepType() << ": ";
  263. FirstOr = false;
  264. out << Start.TargetPkg().Name();
  265. // Show a quick summary of the version requirements
  266. if (Start.TargetVer() != 0)
  267. out << " (" << Start.CompType() << " " << Start.TargetVer() << ")";
  268. /* Show a summary of the target package if possible. In the case
  269. of virtual packages we show nothing */
  270. pkgCache::PkgIterator Targ = Start.TargetPkg();
  271. if (Targ->ProvidesList == 0)
  272. {
  273. out << ' ';
  274. pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache);
  275. if (Now == true)
  276. Ver = Targ.CurrentVer();
  277. if (Ver.end() == false)
  278. {
  279. if (Now == true)
  280. ioprintf(out,_("but %s is installed"),Ver.VerStr());
  281. else
  282. ioprintf(out,_("but %s is to be installed"),Ver.VerStr());
  283. }
  284. else
  285. {
  286. if (Cache[Targ].CandidateVerIter(Cache).end() == true)
  287. {
  288. if (Targ->ProvidesList == 0)
  289. out << _("but it is not installable");
  290. else
  291. out << _("but it is a virtual package");
  292. }
  293. else
  294. out << (Now?_("but it is not installed"):_("but it is not going to be installed"));
  295. }
  296. }
  297. if (Start != End)
  298. out << _(" or");
  299. out << endl;
  300. if (Start == End)
  301. break;
  302. Start++;
  303. }
  304. }
  305. }
  306. }
  307. /*}}}*/
  308. // ShowNew - Show packages to newly install /*{{{*/
  309. // ---------------------------------------------------------------------
  310. /* */
  311. void ShowNew(ostream &out,CacheFile &Cache)
  312. {
  313. /* Print out a list of packages that are going to be removed extra
  314. to what the user asked */
  315. string List;
  316. string VersionsList;
  317. for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
  318. {
  319. pkgCache::PkgIterator I(Cache,Cache.List[J]);
  320. if (Cache[I].NewInstall() == true) {
  321. List += string(I.Name()) + " ";
  322. VersionsList += string(Cache[I].CandVersion) + "\n";
  323. }
  324. }
  325. ShowList(out,_("The following NEW packages will be installed:"),List,VersionsList);
  326. }
  327. /*}}}*/
  328. // ShowDel - Show packages to delete /*{{{*/
  329. // ---------------------------------------------------------------------
  330. /* */
  331. void ShowDel(ostream &out,CacheFile &Cache)
  332. {
  333. /* Print out a list of packages that are going to be removed extra
  334. to what the user asked */
  335. string List;
  336. string VersionsList;
  337. for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
  338. {
  339. pkgCache::PkgIterator I(Cache,Cache.List[J]);
  340. if (Cache[I].Delete() == true)
  341. {
  342. if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge)
  343. List += string(I.Name()) + "* ";
  344. else
  345. List += string(I.Name()) + " ";
  346. VersionsList += string(Cache[I].CandVersion)+ "\n";
  347. }
  348. }
  349. ShowList(out,_("The following packages will be REMOVED:"),List,VersionsList);
  350. }
  351. /*}}}*/
  352. // ShowKept - Show kept packages /*{{{*/
  353. // ---------------------------------------------------------------------
  354. /* */
  355. void ShowKept(ostream &out,CacheFile &Cache)
  356. {
  357. string List;
  358. string VersionsList;
  359. for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
  360. {
  361. pkgCache::PkgIterator I(Cache,Cache.List[J]);
  362. // Not interesting
  363. if (Cache[I].Upgrade() == true || Cache[I].Upgradable() == false ||
  364. I->CurrentVer == 0 || Cache[I].Delete() == true)
  365. continue;
  366. List += string(I.Name()) + " ";
  367. VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n";
  368. }
  369. ShowList(out,_("The following packages have been kept back"),List,VersionsList);
  370. }
  371. /*}}}*/
  372. // ShowUpgraded - Show upgraded packages /*{{{*/
  373. // ---------------------------------------------------------------------
  374. /* */
  375. void ShowUpgraded(ostream &out,CacheFile &Cache)
  376. {
  377. string List;
  378. string VersionsList;
  379. for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
  380. {
  381. pkgCache::PkgIterator I(Cache,Cache.List[J]);
  382. // Not interesting
  383. if (Cache[I].Upgrade() == false || Cache[I].NewInstall() == true)
  384. continue;
  385. List += string(I.Name()) + " ";
  386. VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n";
  387. }
  388. ShowList(out,_("The following packages will be upgraded"),List,VersionsList);
  389. }
  390. /*}}}*/
  391. // ShowDowngraded - Show downgraded packages /*{{{*/
  392. // ---------------------------------------------------------------------
  393. /* */
  394. bool ShowDowngraded(ostream &out,CacheFile &Cache)
  395. {
  396. string List;
  397. string VersionsList;
  398. for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
  399. {
  400. pkgCache::PkgIterator I(Cache,Cache.List[J]);
  401. // Not interesting
  402. if (Cache[I].Downgrade() == false || Cache[I].NewInstall() == true)
  403. continue;
  404. List += string(I.Name()) + " ";
  405. VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n";
  406. }
  407. return ShowList(out,_("The following packages will be DOWNGRADED"),List,VersionsList);
  408. }
  409. /*}}}*/
  410. // ShowHold - Show held but changed packages /*{{{*/
  411. // ---------------------------------------------------------------------
  412. /* */
  413. bool ShowHold(ostream &out,CacheFile &Cache)
  414. {
  415. string List;
  416. string VersionsList;
  417. for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
  418. {
  419. pkgCache::PkgIterator I(Cache,Cache.List[J]);
  420. if (Cache[I].InstallVer != (pkgCache::Version *)I.CurrentVer() &&
  421. I->SelectedState == pkgCache::State::Hold) {
  422. List += string(I.Name()) + " ";
  423. VersionsList += string(Cache[I].CurVersion) + " => " + Cache[I].CandVersion + "\n";
  424. }
  425. }
  426. return ShowList(out,_("The following held packages will be changed:"),List,VersionsList);
  427. }
  428. /*}}}*/
  429. // ShowEssential - Show an essential package warning /*{{{*/
  430. // ---------------------------------------------------------------------
  431. /* This prints out a warning message that is not to be ignored. It shows
  432. all essential packages and their dependents that are to be removed.
  433. It is insanely risky to remove the dependents of an essential package! */
  434. bool ShowEssential(ostream &out,CacheFile &Cache)
  435. {
  436. string List;
  437. string VersionsList;
  438. bool *Added = new bool[Cache->Head().PackageCount];
  439. for (unsigned int I = 0; I != Cache->Head().PackageCount; I++)
  440. Added[I] = false;
  441. for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
  442. {
  443. pkgCache::PkgIterator I(Cache,Cache.List[J]);
  444. if ((I->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential &&
  445. (I->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important)
  446. continue;
  447. // The essential package is being removed
  448. if (Cache[I].Delete() == true)
  449. {
  450. if (Added[I->ID] == false)
  451. {
  452. Added[I->ID] = true;
  453. List += string(I.Name()) + " ";
  454. //VersionsList += string(Cache[I].CurVersion) + "\n"; ???
  455. }
  456. }
  457. if (I->CurrentVer == 0)
  458. continue;
  459. // Print out any essential package depenendents that are to be removed
  460. for (pkgCache::DepIterator D = I.CurrentVer().DependsList(); D.end() == false; D++)
  461. {
  462. // Skip everything but depends
  463. if (D->Type != pkgCache::Dep::PreDepends &&
  464. D->Type != pkgCache::Dep::Depends)
  465. continue;
  466. pkgCache::PkgIterator P = D.SmartTargetPkg();
  467. if (Cache[P].Delete() == true)
  468. {
  469. if (Added[P->ID] == true)
  470. continue;
  471. Added[P->ID] = true;
  472. char S[300];
  473. snprintf(S,sizeof(S),_("%s (due to %s) "),P.Name(),I.Name());
  474. List += S;
  475. //VersionsList += "\n"; ???
  476. }
  477. }
  478. }
  479. delete [] Added;
  480. return ShowList(out,_("WARNING: The following essential packages will be removed\n"
  481. "This should NOT be done unless you know exactly what you are doing!"),List,VersionsList);
  482. }
  483. /*}}}*/
  484. // Stats - Show some statistics /*{{{*/
  485. // ---------------------------------------------------------------------
  486. /* */
  487. void Stats(ostream &out,pkgDepCache &Dep)
  488. {
  489. unsigned long Upgrade = 0;
  490. unsigned long Downgrade = 0;
  491. unsigned long Install = 0;
  492. unsigned long ReInstall = 0;
  493. for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; I++)
  494. {
  495. if (Dep[I].NewInstall() == true)
  496. Install++;
  497. else
  498. {
  499. if (Dep[I].Upgrade() == true)
  500. Upgrade++;
  501. else
  502. if (Dep[I].Downgrade() == true)
  503. Downgrade++;
  504. }
  505. if (Dep[I].Delete() == false && (Dep[I].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)
  506. ReInstall++;
  507. }
  508. ioprintf(out,_("%lu packages upgraded, %lu newly installed, "),
  509. Upgrade,Install);
  510. if (ReInstall != 0)
  511. ioprintf(out,_("%lu reinstalled, "),ReInstall);
  512. if (Downgrade != 0)
  513. ioprintf(out,_("%lu downgraded, "),Downgrade);
  514. ioprintf(out,_("%lu to remove and %lu not upgraded.\n"),
  515. Dep.DelCount(),Dep.KeepCount());
  516. if (Dep.BadCount() != 0)
  517. ioprintf(out,_("%lu packages not fully installed or removed.\n"),
  518. Dep.BadCount());
  519. }
  520. /*}}}*/
  521. // CacheFile::NameComp - QSort compare by name /*{{{*/
  522. // ---------------------------------------------------------------------
  523. /* */
  524. pkgCache *CacheFile::SortCache = 0;
  525. int CacheFile::NameComp(const void *a,const void *b)
  526. {
  527. if (*(pkgCache::Package **)a == 0 || *(pkgCache::Package **)b == 0)
  528. return *(pkgCache::Package **)a - *(pkgCache::Package **)b;
  529. const pkgCache::Package &A = **(pkgCache::Package **)a;
  530. const pkgCache::Package &B = **(pkgCache::Package **)b;
  531. return strcmp(SortCache->StrP + A.Name,SortCache->StrP + B.Name);
  532. }
  533. /*}}}*/
  534. // CacheFile::Sort - Sort by name /*{{{*/
  535. // ---------------------------------------------------------------------
  536. /* */
  537. void CacheFile::Sort()
  538. {
  539. delete [] List;
  540. List = new pkgCache::Package *[Cache->Head().PackageCount];
  541. memset(List,0,sizeof(*List)*Cache->Head().PackageCount);
  542. pkgCache::PkgIterator I = Cache->PkgBegin();
  543. for (;I.end() != true; I++)
  544. List[I->ID] = I;
  545. SortCache = *this;
  546. qsort(List,Cache->Head().PackageCount,sizeof(*List),NameComp);
  547. }
  548. /*}}}*/
  549. // CacheFile::CheckDeps - Open the cache file /*{{{*/
  550. // ---------------------------------------------------------------------
  551. /* This routine generates the caches and then opens the dependency cache
  552. and verifies that the system is OK. */
  553. bool CacheFile::CheckDeps(bool AllowBroken)
  554. {
  555. if (_error->PendingError() == true)
  556. return false;
  557. // Check that the system is OK
  558. if (DCache->DelCount() != 0 || DCache->InstCount() != 0)
  559. return _error->Error("Internal Error, non-zero counts");
  560. // Apply corrections for half-installed packages
  561. if (pkgApplyStatus(*DCache) == false)
  562. return false;
  563. // Nothing is broken
  564. if (DCache->BrokenCount() == 0 || AllowBroken == true)
  565. return true;
  566. // Attempt to fix broken things
  567. if (_config->FindB("APT::Get::Fix-Broken",false) == true)
  568. {
  569. c1out << _("Correcting dependencies...") << flush;
  570. if (pkgFixBroken(*DCache) == false || DCache->BrokenCount() != 0)
  571. {
  572. c1out << _(" failed.") << endl;
  573. ShowBroken(c1out,*this,true);
  574. return _error->Error(_("Unable to correct dependencies"));
  575. }
  576. if (pkgMinimizeUpgrade(*DCache) == false)
  577. return _error->Error(_("Unable to minimize the upgrade set"));
  578. c1out << _(" Done") << endl;
  579. }
  580. else
  581. {
  582. c1out << _("You might want to run `apt-get -f install' to correct these.") << endl;
  583. ShowBroken(c1out,*this,true);
  584. return _error->Error(_("Unmet dependencies. Try using -f."));
  585. }
  586. return true;
  587. }
  588. /*}}}*/
  589. // InstallPackages - Actually download and install the packages /*{{{*/
  590. // ---------------------------------------------------------------------
  591. /* This displays the informative messages describing what is going to
  592. happen and then calls the download routines */
  593. bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
  594. bool Saftey = true)
  595. {
  596. if (_config->FindB("APT::Get::Purge",false) == true)
  597. {
  598. pkgCache::PkgIterator I = Cache->PkgBegin();
  599. for (; I.end() == false; I++)
  600. {
  601. if (I.Purge() == false && Cache[I].Mode == pkgDepCache::ModeDelete)
  602. Cache->MarkDelete(I,true);
  603. }
  604. }
  605. bool Fail = false;
  606. bool Essential = false;
  607. // Show all the various warning indicators
  608. ShowDel(c1out,Cache);
  609. ShowNew(c1out,Cache);
  610. if (ShwKept == true)
  611. ShowKept(c1out,Cache);
  612. Fail |= !ShowHold(c1out,Cache);
  613. if (_config->FindB("APT::Get::Show-Upgraded",false) == true)
  614. ShowUpgraded(c1out,Cache);
  615. Fail |= !ShowDowngraded(c1out,Cache);
  616. if (_config->FindB("APT::Get::Download-Only",false) == false)
  617. Essential = !ShowEssential(c1out,Cache);
  618. Fail |= Essential;
  619. Stats(c1out,Cache);
  620. // Sanity check
  621. if (Cache->BrokenCount() != 0)
  622. {
  623. ShowBroken(c1out,Cache,false);
  624. return _error->Error("Internal Error, InstallPackages was called with broken packages!");
  625. }
  626. if (Cache->DelCount() == 0 && Cache->InstCount() == 0 &&
  627. Cache->BadCount() == 0)
  628. return true;
  629. // No remove flag
  630. if (Cache->DelCount() != 0 && _config->FindB("APT::Get::Remove",true) == false)
  631. return _error->Error(_("Packages need to be removed but Remove is disabled."));
  632. // Run the simulator ..
  633. if (_config->FindB("APT::Get::Simulate") == true)
  634. {
  635. pkgSimulate PM(Cache);
  636. pkgPackageManager::OrderResult Res = PM.DoInstall();
  637. if (Res == pkgPackageManager::Failed)
  638. return false;
  639. if (Res != pkgPackageManager::Completed)
  640. return _error->Error("Internal Error, Ordering didn't finish");
  641. return true;
  642. }
  643. // Create the text record parser
  644. pkgRecords Recs(Cache);
  645. if (_error->PendingError() == true)
  646. return false;
  647. // Lock the archive directory
  648. FileFd Lock;
  649. if (_config->FindB("Debug::NoLocking",false) == false &&
  650. _config->FindB("APT::Get::Print-URIs") == false)
  651. {
  652. Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock"));
  653. if (_error->PendingError() == true)
  654. return _error->Error(_("Unable to lock the download directory"));
  655. }
  656. // Create the download object
  657. AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
  658. pkgAcquire Fetcher(&Stat);
  659. // Read the source list
  660. pkgSourceList List;
  661. if (List.ReadMainList() == false)
  662. return _error->Error(_("The list of sources could not be read."));
  663. // Create the package manager and prepare to download
  664. SPtr<pkgPackageManager> PM= _system->CreatePM(Cache);
  665. if (PM->GetArchives(&Fetcher,&List,&Recs) == false ||
  666. _error->PendingError() == true)
  667. return false;
  668. // Display statistics
  669. double FetchBytes = Fetcher.FetchNeeded();
  670. double FetchPBytes = Fetcher.PartialPresent();
  671. double DebBytes = Fetcher.TotalNeeded();
  672. if (DebBytes != Cache->DebSize())
  673. {
  674. c0out << DebBytes << ',' << Cache->DebSize() << endl;
  675. c0out << "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl;
  676. }
  677. // Number of bytes
  678. if (DebBytes != FetchBytes)
  679. ioprintf(c1out,_("Need to get %sB/%sB of archives.\n"),
  680. SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str());
  681. else
  682. ioprintf(c1out,_("Need to get %sB of archives.\n"),
  683. SizeToStr(DebBytes).c_str());
  684. // Size delta
  685. if (Cache->UsrSize() >= 0)
  686. ioprintf(c1out,_("After unpacking %sB of additional disk space will be used.\n"),
  687. SizeToStr(Cache->UsrSize()).c_str());
  688. else
  689. ioprintf(c1out,_("After unpacking %sB disk space will be freed.\n"),
  690. SizeToStr(-1*Cache->UsrSize()).c_str());
  691. if (_error->PendingError() == true)
  692. return false;
  693. /* Check for enough free space, but only if we are actually going to
  694. download */
  695. if (_config->FindB("APT::Get::Print-URIs") == false &&
  696. _config->FindB("APT::Get::Download",true) == true)
  697. {
  698. struct statvfs Buf;
  699. string OutputDir = _config->FindDir("Dir::Cache::Archives");
  700. if (statvfs(OutputDir.c_str(),&Buf) != 0)
  701. return _error->Errno("statvfs","Couldn't determine free space in %s",
  702. OutputDir.c_str());
  703. if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
  704. return _error->Error(_("You don't have enough free space in %s."),
  705. OutputDir.c_str());
  706. }
  707. // Fail safe check
  708. if (_config->FindI("quiet",0) >= 2 ||
  709. _config->FindB("APT::Get::Assume-Yes",false) == true)
  710. {
  711. if (Fail == true && _config->FindB("APT::Get::Force-Yes",false) == false)
  712. return _error->Error(_("There are problems and -y was used without --force-yes"));
  713. }
  714. if (Essential == true && Saftey == true)
  715. {
  716. if (_config->FindB("APT::Get::Trivial-Only",false) == true)
  717. return _error->Error(_("Trivial Only specified but this is not a trivial operation."));
  718. const char *Prompt = _("Yes, do as I say!");
  719. ioprintf(c2out,
  720. _("You are about to do something potentially harmful\n"
  721. "To continue type in the phrase '%s'\n"
  722. " ?] "),Prompt);
  723. c2out << flush;
  724. if (AnalPrompt(Prompt) == false)
  725. {
  726. c2out << _("Abort.") << endl;
  727. exit(1);
  728. }
  729. }
  730. else
  731. {
  732. // Prompt to continue
  733. if (Ask == true || Fail == true)
  734. {
  735. if (_config->FindB("APT::Get::Trivial-Only",false) == true)
  736. return _error->Error(_("Trivial Only specified but this is not a trivial operation."));
  737. if (_config->FindI("quiet",0) < 2 &&
  738. _config->FindB("APT::Get::Assume-Yes",false) == false)
  739. {
  740. c2out << _("Do you want to continue? [Y/n] ") << flush;
  741. if (YnPrompt() == false)
  742. {
  743. c2out << _("Abort.") << endl;
  744. exit(1);
  745. }
  746. }
  747. }
  748. }
  749. // Just print out the uris an exit if the --print-uris flag was used
  750. if (_config->FindB("APT::Get::Print-URIs") == true)
  751. {
  752. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  753. for (; I != Fetcher.UriEnd(); I++)
  754. cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
  755. I->Owner->FileSize << ' ' << I->Owner->MD5Sum() << endl;
  756. return true;
  757. }
  758. /* Unlock the dpkg lock if we are not going to be doing an install
  759. after. */
  760. if (_config->FindB("APT::Get::Download-Only",false) == true)
  761. _system->UnLock();
  762. // Run it
  763. while (1)
  764. {
  765. bool Transient = false;
  766. if (_config->FindB("APT::Get::Download",true) == false)
  767. {
  768. for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd();)
  769. {
  770. if ((*I)->Local == true)
  771. {
  772. I++;
  773. continue;
  774. }
  775. // Close the item and check if it was found in cache
  776. (*I)->Finished();
  777. if ((*I)->Complete == false)
  778. Transient = true;
  779. // Clear it out of the fetch list
  780. delete *I;
  781. I = Fetcher.ItemsBegin();
  782. }
  783. }
  784. if (Fetcher.Run() == pkgAcquire::Failed)
  785. return false;
  786. // Print out errors
  787. bool Failed = false;
  788. for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
  789. {
  790. if ((*I)->Status == pkgAcquire::Item::StatDone &&
  791. (*I)->Complete == true)
  792. continue;
  793. if ((*I)->Status == pkgAcquire::Item::StatIdle)
  794. {
  795. Transient = true;
  796. // Failed = true;
  797. continue;
  798. }
  799. fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(),
  800. (*I)->ErrorText.c_str());
  801. Failed = true;
  802. }
  803. /* If we are in no download mode and missing files and there were
  804. 'failures' then the user must specify -m. Furthermore, there
  805. is no such thing as a transient error in no-download mode! */
  806. if (Transient == true &&
  807. _config->FindB("APT::Get::Download",true) == false)
  808. {
  809. Transient = false;
  810. Failed = true;
  811. }
  812. if (_config->FindB("APT::Get::Download-Only",false) == true)
  813. {
  814. if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false)
  815. return _error->Error(_("Some files failed to download"));
  816. c1out << _("Download complete and in download only mode") << endl;
  817. return true;
  818. }
  819. if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false)
  820. {
  821. return _error->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
  822. }
  823. if (Transient == true && Failed == true)
  824. return _error->Error(_("--fix-missing and media swapping is not currently supported"));
  825. // Try to deal with missing package files
  826. if (Failed == true && PM->FixMissing() == false)
  827. {
  828. cerr << _("Unable to correct missing packages.") << endl;
  829. return _error->Error(_("Aborting Install."));
  830. }
  831. _system->UnLock();
  832. pkgPackageManager::OrderResult Res = PM->DoInstall();
  833. if (Res == pkgPackageManager::Failed || _error->PendingError() == true)
  834. return false;
  835. if (Res == pkgPackageManager::Completed)
  836. return true;
  837. // Reload the fetcher object and loop again for media swapping
  838. Fetcher.Shutdown();
  839. if (PM->GetArchives(&Fetcher,&List,&Recs) == false)
  840. return false;
  841. _system->Lock();
  842. }
  843. }
  844. /*}}}*/
  845. // TryToInstall - Try to install a single package /*{{{*/
  846. // ---------------------------------------------------------------------
  847. /* This used to be inlined in DoInstall, but with the advent of regex package
  848. name matching it was split out.. */
  849. bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache,
  850. pkgProblemResolver &Fix,bool Remove,bool BrokenFix,
  851. unsigned int &ExpectedInst,bool AllowFail = true)
  852. {
  853. /* This is a pure virtual package and there is a single available
  854. provides */
  855. if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0 &&
  856. Pkg.ProvidesList()->NextProvides == 0)
  857. {
  858. pkgCache::PkgIterator Tmp = Pkg.ProvidesList().OwnerPkg();
  859. ioprintf(c1out,_("Note, selecting %s instead of %s\n"),
  860. Tmp.Name(),Pkg.Name());
  861. Pkg = Tmp;
  862. }
  863. // Handle the no-upgrade case
  864. if (_config->FindB("APT::Get::upgrade",true) == false &&
  865. Pkg->CurrentVer != 0)
  866. {
  867. if (AllowFail == true)
  868. ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"),
  869. Pkg.Name());
  870. return true;
  871. }
  872. // Check if there is something at all to install
  873. pkgDepCache::StateCache &State = Cache[Pkg];
  874. if (Remove == true && Pkg->CurrentVer == 0)
  875. {
  876. Fix.Clear(Pkg);
  877. Fix.Protect(Pkg);
  878. Fix.Remove(Pkg);
  879. /* We want to continue searching for regex hits, so we return false here
  880. otherwise this is not really an error. */
  881. if (AllowFail == false)
  882. return false;
  883. ioprintf(c1out,_("Package %s is not installed, so not removed\n"),Pkg.Name());
  884. return true;
  885. }
  886. if (State.CandidateVer == 0 && Remove == false)
  887. {
  888. if (AllowFail == false)
  889. return false;
  890. if (Pkg->ProvidesList != 0)
  891. {
  892. ioprintf(c1out,_("Package %s is a virtual package provided by:\n"),
  893. Pkg.Name());
  894. pkgCache::PrvIterator I = Pkg.ProvidesList();
  895. for (; I.end() == false; I++)
  896. {
  897. pkgCache::PkgIterator Pkg = I.OwnerPkg();
  898. if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer())
  899. {
  900. if (Cache[Pkg].Install() == true && Cache[Pkg].NewInstall() == false)
  901. c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() <<
  902. _(" [Installed]") << endl;
  903. else
  904. c1out << " " << Pkg.Name() << " " << I.OwnerVer().VerStr() << endl;
  905. }
  906. }
  907. c1out << _("You should explicitly select one to install.") << endl;
  908. }
  909. else
  910. {
  911. ioprintf(c1out,
  912. _("Package %s has no available version, but exists in the database.\n"
  913. "This typically means that the package was mentioned in a dependency and\n"
  914. "never uploaded, has been obsoleted or is not available with the contents\n"
  915. "of sources.list\n"),Pkg.Name());
  916. string List;
  917. string VersionsList;
  918. SPtrArray<bool> Seen = new bool[Cache.Head().PackageCount];
  919. memset(Seen,0,Cache.Head().PackageCount*sizeof(*Seen));
  920. pkgCache::DepIterator Dep = Pkg.RevDependsList();
  921. for (; Dep.end() == false; Dep++)
  922. {
  923. if (Dep->Type != pkgCache::Dep::Replaces)
  924. continue;
  925. if (Seen[Dep.ParentPkg()->ID] == true)
  926. continue;
  927. Seen[Dep.ParentPkg()->ID] = true;
  928. List += string(Dep.ParentPkg().Name()) + " ";
  929. //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ???
  930. }
  931. ShowList(c1out,_("However the following packages replace it:"),List,VersionsList);
  932. }
  933. _error->Error(_("Package %s has no installation candidate"),Pkg.Name());
  934. return false;
  935. }
  936. Fix.Clear(Pkg);
  937. Fix.Protect(Pkg);
  938. if (Remove == true)
  939. {
  940. Fix.Remove(Pkg);
  941. Cache.MarkDelete(Pkg,_config->FindB("APT::Get::Purge",false));
  942. return true;
  943. }
  944. // Install it
  945. Cache.MarkInstall(Pkg,false);
  946. if (State.Install() == false)
  947. {
  948. if (_config->FindB("APT::Get::ReInstall",false) == true)
  949. {
  950. if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false)
  951. ioprintf(c1out,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
  952. Pkg.Name());
  953. else
  954. Cache.SetReInstall(Pkg,true);
  955. }
  956. else
  957. {
  958. if (AllowFail == true)
  959. ioprintf(c1out,_("%s is already the newest version.\n"),
  960. Pkg.Name());
  961. }
  962. }
  963. else
  964. ExpectedInst++;
  965. // Install it with autoinstalling enabled.
  966. if (State.InstBroken() == true && BrokenFix == false)
  967. Cache.MarkInstall(Pkg,true);
  968. return true;
  969. }
  970. /*}}}*/
  971. // TryToChangeVer - Try to change a candidate version /*{{{*/
  972. // ---------------------------------------------------------------------
  973. /* */
  974. bool TryToChangeVer(pkgCache::PkgIterator Pkg,pkgDepCache &Cache,
  975. const char *VerTag,bool IsRel)
  976. {
  977. pkgVersionMatch Match(VerTag,(IsRel == true?pkgVersionMatch::Release :
  978. pkgVersionMatch::Version));
  979. pkgCache::VerIterator Ver = Match.Find(Pkg);
  980. if (Ver.end() == true)
  981. {
  982. if (IsRel == true)
  983. return _error->Error(_("Release '%s' for '%s' was not found"),
  984. VerTag,Pkg.Name());
  985. return _error->Error(_("Version '%s' for '%s' was not found"),
  986. VerTag,Pkg.Name());
  987. }
  988. if (strcmp(VerTag,Ver.VerStr()) != 0)
  989. {
  990. ioprintf(c1out,_("Selected version %s (%s) for %s\n"),
  991. Ver.VerStr(),Ver.RelStr().c_str(),Pkg.Name());
  992. }
  993. Cache.SetCandidateVersion(Ver);
  994. return true;
  995. }
  996. /*}}}*/
  997. // FindSrc - Find a source record /*{{{*/
  998. // ---------------------------------------------------------------------
  999. /* */
  1000. pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
  1001. pkgSrcRecords &SrcRecs,string &Src,
  1002. pkgDepCache &Cache)
  1003. {
  1004. // We want to pull the version off the package specification..
  1005. string VerTag;
  1006. string TmpSrc = Name;
  1007. string::size_type Slash = TmpSrc.rfind('=');
  1008. if (Slash != string::npos)
  1009. {
  1010. VerTag = string(TmpSrc.begin() + Slash + 1,TmpSrc.end());
  1011. TmpSrc = string(TmpSrc.begin(),TmpSrc.begin() + Slash);
  1012. }
  1013. /* Lookup the version of the package we would install if we were to
  1014. install a version and determine the source package name, then look
  1015. in the archive for a source package of the same name. In theory
  1016. we could stash the version string as well and match that too but
  1017. today there aren't multi source versions in the archive. */
  1018. if (_config->FindB("APT::Get::Only-Source") == false &&
  1019. VerTag.empty() == true)
  1020. {
  1021. pkgCache::PkgIterator Pkg = Cache.FindPkg(TmpSrc);
  1022. if (Pkg.end() == false)
  1023. {
  1024. pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg);
  1025. if (Ver.end() == false)
  1026. {
  1027. pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
  1028. Src = Parse.SourcePkg();
  1029. }
  1030. }
  1031. }
  1032. // No source package name..
  1033. if (Src.empty() == true)
  1034. Src = TmpSrc;
  1035. // The best hit
  1036. pkgSrcRecords::Parser *Last = 0;
  1037. unsigned long Offset = 0;
  1038. string Version;
  1039. bool IsMatch = false;
  1040. // If we are matching by version then we need exact matches to be happy
  1041. if (VerTag.empty() == false)
  1042. IsMatch = true;
  1043. /* Iterate over all of the hits, which includes the resulting
  1044. binary packages in the search */
  1045. pkgSrcRecords::Parser *Parse;
  1046. SrcRecs.Restart();
  1047. while ((Parse = SrcRecs.Find(Src.c_str(),false)) != 0)
  1048. {
  1049. string Ver = Parse->Version();
  1050. // Skip name mismatches
  1051. if (IsMatch == true && Parse->Package() != Src)
  1052. continue;
  1053. if (VerTag.empty() == false)
  1054. {
  1055. /* Don't want to fall through because we are doing exact version
  1056. matching. */
  1057. if (Cache.VS().CmpVersion(VerTag,Ver) != 0)
  1058. continue;
  1059. Last = Parse;
  1060. Offset = Parse->Offset();
  1061. break;
  1062. }
  1063. // Newer version or an exact match
  1064. if (Last == 0 || Cache.VS().CmpVersion(Version,Ver) < 0 ||
  1065. (Parse->Package() == Src && IsMatch == false))
  1066. {
  1067. IsMatch = Parse->Package() == Src;
  1068. Last = Parse;
  1069. Offset = Parse->Offset();
  1070. Version = Ver;
  1071. }
  1072. }
  1073. if (Last == 0)
  1074. return 0;
  1075. if (Last->Jump(Offset) == false)
  1076. return 0;
  1077. return Last;
  1078. }
  1079. /*}}}*/
  1080. // DoUpdate - Update the package lists /*{{{*/
  1081. // ---------------------------------------------------------------------
  1082. /* */
  1083. bool DoUpdate(CommandLine &CmdL)
  1084. {
  1085. if (CmdL.FileSize() != 1)
  1086. return _error->Error(_("The update command takes no arguments"));
  1087. // Get the source list
  1088. pkgSourceList List;
  1089. if (List.ReadMainList() == false)
  1090. return false;
  1091. // Lock the list directory
  1092. FileFd Lock;
  1093. if (_config->FindB("Debug::NoLocking",false) == false)
  1094. {
  1095. Lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
  1096. if (_error->PendingError() == true)
  1097. return _error->Error(_("Unable to lock the list directory"));
  1098. }
  1099. // Create the download object
  1100. AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
  1101. pkgAcquire Fetcher(&Stat);
  1102. // Populate it with the source selection
  1103. if (List.GetIndexes(&Fetcher) == false)
  1104. return false;
  1105. // Just print out the uris an exit if the --print-uris flag was used
  1106. if (_config->FindB("APT::Get::Print-URIs") == true)
  1107. {
  1108. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  1109. for (; I != Fetcher.UriEnd(); I++)
  1110. cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
  1111. I->Owner->FileSize << ' ' << I->Owner->MD5Sum() << endl;
  1112. return true;
  1113. }
  1114. // Run it
  1115. if (Fetcher.Run() == pkgAcquire::Failed)
  1116. return false;
  1117. bool Failed = false;
  1118. for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
  1119. {
  1120. if ((*I)->Status == pkgAcquire::Item::StatDone)
  1121. continue;
  1122. (*I)->Finished();
  1123. fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(),
  1124. (*I)->ErrorText.c_str());
  1125. Failed = true;
  1126. }
  1127. // Clean out any old list files
  1128. if (_config->FindB("APT::Get::List-Cleanup",true) == true)
  1129. {
  1130. if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false ||
  1131. Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
  1132. return false;
  1133. }
  1134. // Prepare the cache.
  1135. CacheFile Cache;
  1136. if (Cache.BuildCaches() == false)
  1137. return false;
  1138. if (Failed == true)
  1139. return _error->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
  1140. return true;
  1141. }
  1142. /*}}}*/
  1143. // DoUpgrade - Upgrade all packages /*{{{*/
  1144. // ---------------------------------------------------------------------
  1145. /* Upgrade all packages without installing new packages or erasing old
  1146. packages */
  1147. bool DoUpgrade(CommandLine &CmdL)
  1148. {
  1149. CacheFile Cache;
  1150. if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
  1151. return false;
  1152. // Do the upgrade
  1153. if (pkgAllUpgrade(Cache) == false)
  1154. {
  1155. ShowBroken(c1out,Cache,false);
  1156. return _error->Error(_("Internal Error, AllUpgrade broke stuff"));
  1157. }
  1158. return InstallPackages(Cache,true);
  1159. }
  1160. /*}}}*/
  1161. // DoInstall - Install packages from the command line /*{{{*/
  1162. // ---------------------------------------------------------------------
  1163. /* Install named packages */
  1164. bool DoInstall(CommandLine &CmdL)
  1165. {
  1166. CacheFile Cache;
  1167. if (Cache.OpenForInstall() == false ||
  1168. Cache.CheckDeps(CmdL.FileSize() != 1) == false)
  1169. return false;
  1170. // Enter the special broken fixing mode if the user specified arguments
  1171. bool BrokenFix = false;
  1172. if (Cache->BrokenCount() != 0)
  1173. BrokenFix = true;
  1174. unsigned int ExpectedInst = 0;
  1175. unsigned int Packages = 0;
  1176. pkgProblemResolver Fix(Cache);
  1177. bool DefRemove = false;
  1178. if (strcasecmp(CmdL.FileList[0],"remove") == 0)
  1179. DefRemove = true;
  1180. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  1181. {
  1182. // Duplicate the string
  1183. unsigned int Length = strlen(*I);
  1184. char S[300];
  1185. if (Length >= sizeof(S))
  1186. continue;
  1187. strcpy(S,*I);
  1188. // See if we are removing and special indicators..
  1189. bool Remove = DefRemove;
  1190. char *VerTag = 0;
  1191. bool VerIsRel = false;
  1192. while (Cache->FindPkg(S).end() == true)
  1193. {
  1194. // Handle an optional end tag indicating what to do
  1195. if (Length >= 1 && S[Length - 1] == '-')
  1196. {
  1197. Remove = true;
  1198. S[--Length] = 0;
  1199. continue;
  1200. }
  1201. if (Length >= 1 && S[Length - 1] == '+')
  1202. {
  1203. Remove = false;
  1204. S[--Length] = 0;
  1205. continue;
  1206. }
  1207. char *Slash = strchr(S,'=');
  1208. if (Slash != 0)
  1209. {
  1210. VerIsRel = false;
  1211. *Slash = 0;
  1212. VerTag = Slash + 1;
  1213. }
  1214. Slash = strchr(S,'/');
  1215. if (Slash != 0)
  1216. {
  1217. VerIsRel = true;
  1218. *Slash = 0;
  1219. VerTag = Slash + 1;
  1220. }
  1221. break;
  1222. }
  1223. // Locate the package
  1224. pkgCache::PkgIterator Pkg = Cache->FindPkg(S);
  1225. Packages++;
  1226. if (Pkg.end() == true)
  1227. {
  1228. // Check if the name is a regex
  1229. const char *I;
  1230. for (I = S; *I != 0; I++)
  1231. if (*I == '?' || *I == '*' || *I == '|' ||
  1232. *I == '[' || *I == '^' || *I == '$')
  1233. break;
  1234. if (*I == 0)
  1235. return _error->Error(_("Couldn't find package %s"),S);
  1236. // Regexs must always be confirmed
  1237. ExpectedInst += 1000;
  1238. // Compile the regex pattern
  1239. regex_t Pattern;
  1240. int Res;
  1241. if ((Res = regcomp(&Pattern,S,REG_EXTENDED | REG_ICASE |
  1242. REG_NOSUB)) != 0)
  1243. {
  1244. char Error[300];
  1245. regerror(Res,&Pattern,Error,sizeof(Error));
  1246. return _error->Error(_("Regex compilation error - %s"),Error);
  1247. }
  1248. // Run over the matches
  1249. bool Hit = false;
  1250. for (Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++)
  1251. {
  1252. if (regexec(&Pattern,Pkg.Name(),0,0,0) != 0)
  1253. continue;
  1254. ioprintf(c1out,_("Note, selecting %s for regex '%s'\n"),
  1255. Pkg.Name(),S);
  1256. if (VerTag != 0)
  1257. if (TryToChangeVer(Pkg,Cache,VerTag,VerIsRel) == false)
  1258. return false;
  1259. Hit |= TryToInstall(Pkg,Cache,Fix,Remove,BrokenFix,
  1260. ExpectedInst,false);
  1261. }
  1262. regfree(&Pattern);
  1263. if (Hit == false)
  1264. return _error->Error(_("Couldn't find package %s"),S);
  1265. }
  1266. else
  1267. {
  1268. if (VerTag != 0)
  1269. if (TryToChangeVer(Pkg,Cache,VerTag,VerIsRel) == false)
  1270. return false;
  1271. if (TryToInstall(Pkg,Cache,Fix,Remove,BrokenFix,ExpectedInst) == false)
  1272. return false;
  1273. }
  1274. }
  1275. /* If we are in the Broken fixing mode we do not attempt to fix the
  1276. problems. This is if the user invoked install without -f and gave
  1277. packages */
  1278. if (BrokenFix == true && Cache->BrokenCount() != 0)
  1279. {
  1280. c1out << _("You might want to run `apt-get -f install' to correct these:") << endl;
  1281. ShowBroken(c1out,Cache,false);
  1282. return _error->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
  1283. }
  1284. // Call the scored problem resolver
  1285. Fix.InstallProtect();
  1286. if (Fix.Resolve(true) == false)
  1287. _error->Discard();
  1288. // Now we check the state of the packages,
  1289. if (Cache->BrokenCount() != 0)
  1290. {
  1291. c1out <<
  1292. _("Some packages could not be installed. This may mean that you have\n"
  1293. "requested an impossible situation or if you are using the unstable\n"
  1294. "distribution that some required packages have not yet been created\n"
  1295. "or been moved out of Incoming.") << endl;
  1296. if (Packages == 1)
  1297. {
  1298. c1out << endl;
  1299. c1out <<
  1300. _("Since you only requested a single operation it is extremely likely that\n"
  1301. "the package is simply not installable and a bug report against\n"
  1302. "that package should be filed.") << endl;
  1303. }
  1304. c1out << _("The following information may help to resolve the situation:") << endl;
  1305. c1out << endl;
  1306. ShowBroken(c1out,Cache,false);
  1307. return _error->Error(_("Broken packages"));
  1308. }
  1309. /* Print out a list of packages that are going to be installed extra
  1310. to what the user asked */
  1311. if (Cache->InstCount() != ExpectedInst)
  1312. {
  1313. string List;
  1314. string VersionsList;
  1315. for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
  1316. {
  1317. pkgCache::PkgIterator I(Cache,Cache.List[J]);
  1318. if ((*Cache)[I].Install() == false)
  1319. continue;
  1320. const char **J;
  1321. for (J = CmdL.FileList + 1; *J != 0; J++)
  1322. if (strcmp(*J,I.Name()) == 0)
  1323. break;
  1324. if (*J == 0) {
  1325. List += string(I.Name()) + " ";
  1326. VersionsList += string(Cache[I].CandVersion) + "\n";
  1327. }
  1328. }
  1329. ShowList(c1out,_("The following extra packages will be installed:"),List,VersionsList);
  1330. }
  1331. /* Print out a list of suggested and recommended packages */
  1332. {
  1333. string SuggestsList, RecommendsList, List;
  1334. string SuggestsVersions, RecommendsVersions;
  1335. for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
  1336. {
  1337. pkgCache::PkgIterator I(Cache,Cache.List[J]);
  1338. /* Just look at the ones we want to install */
  1339. if ((*Cache)[I].Install() == false)
  1340. continue;
  1341. for (pkgCache::VerIterator V = I.VersionList(); V.end() == false; V++)
  1342. {
  1343. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++)
  1344. {
  1345. pkgCache::DepIterator Start;
  1346. pkgCache::DepIterator End;
  1347. D.GlobOr(Start,End);
  1348. /*
  1349. * If this is a virtual package, we need to check the list of
  1350. * packages that provide it and see if any of those are
  1351. * installed
  1352. */
  1353. pkgCache::PrvIterator Prv = Start.TargetPkg().ProvidesList();
  1354. bool providedBySomething = false;
  1355. for (; Prv.end() != true; Prv++)
  1356. if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false) {
  1357. providedBySomething = true;
  1358. break;
  1359. }
  1360. if (providedBySomething) continue;
  1361. do
  1362. {
  1363. if (Start->Type == pkgCache::Dep::Suggests) {
  1364. /* A suggests relations, let's see if we have it
  1365. installed already */
  1366. string target = string(Start.TargetPkg().Name()) + " ";
  1367. if ((*Start.TargetPkg()).SelectedState == pkgCache::State::Install || Cache[Start.TargetPkg()].Install())
  1368. break;
  1369. /* Does another package suggest it as well? If so,
  1370. don't print it twice */
  1371. if (int(SuggestsList.find(target)) > -1)
  1372. break;
  1373. SuggestsList += target;
  1374. SuggestsVersions += string(Cache[Start.TargetPkg()].CandVersion) + "\n";
  1375. }
  1376. if (Start->Type == pkgCache::Dep::Recommends) {
  1377. /* A recommends relation, let's see if we have it
  1378. installed already */
  1379. string target = string(Start.TargetPkg().Name()) + " ";
  1380. if ((*Start.TargetPkg()).SelectedState == pkgCache::State::Install || Cache[Start.TargetPkg()].Install())
  1381. break;
  1382. /* Does another package recommend it as well? If so,
  1383. don't print it twice */
  1384. if (int(RecommendsList.find(target)) > -1)
  1385. break;
  1386. RecommendsList += target;
  1387. SuggestsVersions += string(Cache[Start.TargetPkg()].CandVersion) + "\n";
  1388. }
  1389. if (Start == End)
  1390. break;
  1391. Start++;
  1392. } while (1);
  1393. }
  1394. }
  1395. }
  1396. ShowList(c1out,_("Suggested packages:"),SuggestsList,SuggestsVersions);
  1397. ShowList(c1out,_("Recommended packages:"),RecommendsList,RecommendsVersions);
  1398. }
  1399. // See if we need to prompt
  1400. if (Cache->InstCount() == ExpectedInst && Cache->DelCount() == 0)
  1401. return InstallPackages(Cache,false,false);
  1402. return InstallPackages(Cache,false);
  1403. }
  1404. /*}}}*/
  1405. // DoDistUpgrade - Automatic smart upgrader /*{{{*/
  1406. // ---------------------------------------------------------------------
  1407. /* Intelligent upgrader that will install and remove packages at will */
  1408. bool DoDistUpgrade(CommandLine &CmdL)
  1409. {
  1410. CacheFile Cache;
  1411. if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
  1412. return false;
  1413. c0out << _("Calculating Upgrade... ") << flush;
  1414. if (pkgDistUpgrade(*Cache) == false)
  1415. {
  1416. c0out << _("Failed") << endl;
  1417. ShowBroken(c1out,Cache,false);
  1418. return false;
  1419. }
  1420. c0out << _("Done") << endl;
  1421. return InstallPackages(Cache,true);
  1422. }
  1423. /*}}}*/
  1424. // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
  1425. // ---------------------------------------------------------------------
  1426. /* Follows dselect's selections */
  1427. bool DoDSelectUpgrade(CommandLine &CmdL)
  1428. {
  1429. CacheFile Cache;
  1430. if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
  1431. return false;
  1432. // Install everything with the install flag set
  1433. pkgCache::PkgIterator I = Cache->PkgBegin();
  1434. for (;I.end() != true; I++)
  1435. {
  1436. /* Install the package only if it is a new install, the autoupgrader
  1437. will deal with the rest */
  1438. if (I->SelectedState == pkgCache::State::Install)
  1439. Cache->MarkInstall(I,false);
  1440. }
  1441. /* Now install their deps too, if we do this above then order of
  1442. the status file is significant for | groups */
  1443. for (I = Cache->PkgBegin();I.end() != true; I++)
  1444. {
  1445. /* Install the package only if it is a new install, the autoupgrader
  1446. will deal with the rest */
  1447. if (I->SelectedState == pkgCache::State::Install)
  1448. Cache->MarkInstall(I,true);
  1449. }
  1450. // Apply erasures now, they override everything else.
  1451. for (I = Cache->PkgBegin();I.end() != true; I++)
  1452. {
  1453. // Remove packages
  1454. if (I->SelectedState == pkgCache::State::DeInstall ||
  1455. I->SelectedState == pkgCache::State::Purge)
  1456. Cache->MarkDelete(I,I->SelectedState == pkgCache::State::Purge);
  1457. }
  1458. /* Resolve any problems that dselect created, allupgrade cannot handle
  1459. such things. We do so quite agressively too.. */
  1460. if (Cache->BrokenCount() != 0)
  1461. {
  1462. pkgProblemResolver Fix(Cache);
  1463. // Hold back held packages.
  1464. if (_config->FindB("APT::Ignore-Hold",false) == false)
  1465. {
  1466. for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; I++)
  1467. {
  1468. if (I->SelectedState == pkgCache::State::Hold)
  1469. {
  1470. Fix.Protect(I);
  1471. Cache->MarkKeep(I);
  1472. }
  1473. }
  1474. }
  1475. if (Fix.Resolve() == false)
  1476. {
  1477. ShowBroken(c1out,Cache,false);
  1478. return _error->Error("Internal Error, problem resolver broke stuff");
  1479. }
  1480. }
  1481. // Now upgrade everything
  1482. if (pkgAllUpgrade(Cache) == false)
  1483. {
  1484. ShowBroken(c1out,Cache,false);
  1485. return _error->Error("Internal Error, problem resolver broke stuff");
  1486. }
  1487. return InstallPackages(Cache,false);
  1488. }
  1489. /*}}}*/
  1490. // DoClean - Remove download archives /*{{{*/
  1491. // ---------------------------------------------------------------------
  1492. /* */
  1493. bool DoClean(CommandLine &CmdL)
  1494. {
  1495. if (_config->FindB("APT::Get::Simulate") == true)
  1496. {
  1497. cout << "Del " << _config->FindDir("Dir::Cache::archives") << "* " <<
  1498. _config->FindDir("Dir::Cache::archives") << "partial/*" << endl;
  1499. return true;
  1500. }
  1501. // Lock the archive directory
  1502. FileFd Lock;
  1503. if (_config->FindB("Debug::NoLocking",false) == false)
  1504. {
  1505. Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock"));
  1506. if (_error->PendingError() == true)
  1507. return _error->Error(_("Unable to lock the download directory"));
  1508. }
  1509. pkgAcquire Fetcher;
  1510. Fetcher.Clean(_config->FindDir("Dir::Cache::archives"));
  1511. Fetcher.Clean(_config->FindDir("Dir::Cache::archives") + "partial/");
  1512. return true;
  1513. }
  1514. /*}}}*/
  1515. // DoAutoClean - Smartly remove downloaded archives /*{{{*/
  1516. // ---------------------------------------------------------------------
  1517. /* This is similar to clean but it only purges things that cannot be
  1518. downloaded, that is old versions of cached packages. */
  1519. class LogCleaner : public pkgArchiveCleaner
  1520. {
  1521. protected:
  1522. virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St)
  1523. {
  1524. c1out << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "B]" << endl;
  1525. if (_config->FindB("APT::Get::Simulate") == false)
  1526. unlink(File);
  1527. };
  1528. };
  1529. bool DoAutoClean(CommandLine &CmdL)
  1530. {
  1531. // Lock the archive directory
  1532. FileFd Lock;
  1533. if (_config->FindB("Debug::NoLocking",false) == false)
  1534. {
  1535. Lock.Fd(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock"));
  1536. if (_error->PendingError() == true)
  1537. return _error->Error(_("Unable to lock the download directory"));
  1538. }
  1539. CacheFile Cache;
  1540. if (Cache.Open() == false)
  1541. return false;
  1542. LogCleaner Cleaner;
  1543. return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) &&
  1544. Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache);
  1545. }
  1546. /*}}}*/
  1547. // DoCheck - Perform the check operation /*{{{*/
  1548. // ---------------------------------------------------------------------
  1549. /* Opening automatically checks the system, this command is mostly used
  1550. for debugging */
  1551. bool DoCheck(CommandLine &CmdL)
  1552. {
  1553. CacheFile Cache;
  1554. Cache.Open();
  1555. Cache.CheckDeps();
  1556. return true;
  1557. }
  1558. /*}}}*/
  1559. // DoSource - Fetch a source archive /*{{{*/
  1560. // ---------------------------------------------------------------------
  1561. /* Fetch souce packages */
  1562. struct DscFile
  1563. {
  1564. string Package;
  1565. string Version;
  1566. string Dsc;
  1567. };
  1568. bool DoSource(CommandLine &CmdL)
  1569. {
  1570. CacheFile Cache;
  1571. if (Cache.Open(false) == false)
  1572. return false;
  1573. if (CmdL.FileSize() <= 1)
  1574. return _error->Error(_("Must specify at least one package to fetch source for"));
  1575. // Read the source list
  1576. pkgSourceList List;
  1577. if (List.ReadMainList() == false)
  1578. return _error->Error(_("The list of sources could not be read."));
  1579. // Create the text record parsers
  1580. pkgRecords Recs(Cache);
  1581. pkgSrcRecords SrcRecs(List);
  1582. if (_error->PendingError() == true)
  1583. return false;
  1584. // Create the download object
  1585. AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
  1586. pkgAcquire Fetcher(&Stat);
  1587. DscFile *Dsc = new DscFile[CmdL.FileSize()];
  1588. // Load the requestd sources into the fetcher
  1589. unsigned J = 0;
  1590. for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
  1591. {
  1592. string Src;
  1593. pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,*Cache);
  1594. if (Last == 0)
  1595. return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
  1596. // Back track
  1597. vector<pkgSrcRecords::File> Lst;
  1598. if (Last->Files(Lst) == false)
  1599. return false;
  1600. // Load them into the fetcher
  1601. for (vector<pkgSrcRecords::File>::const_iterator I = Lst.begin();
  1602. I != Lst.end(); I++)
  1603. {
  1604. // Try to guess what sort of file it is we are getting.
  1605. if (I->Type == "dsc")
  1606. {
  1607. Dsc[J].Package = Last->Package();
  1608. Dsc[J].Version = Last->Version();
  1609. Dsc[J].Dsc = flNotDir(I->Path);
  1610. }
  1611. // Diff only mode only fetches .diff files
  1612. if (_config->FindB("APT::Get::Diff-Only",false) == true &&
  1613. I->Type != "diff")
  1614. continue;
  1615. // Tar only mode only fetches .tar files
  1616. if (_config->FindB("APT::Get::Tar-Only",false) == true &&
  1617. I->Type != "tar")
  1618. continue;
  1619. new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path),
  1620. I->MD5Hash,I->Size,
  1621. Last->Index().SourceInfo(*Last,*I),Src);
  1622. }
  1623. }
  1624. // Display statistics
  1625. double FetchBytes = Fetcher.FetchNeeded();
  1626. double FetchPBytes = Fetcher.PartialPresent();
  1627. double DebBytes = Fetcher.TotalNeeded();
  1628. // Check for enough free space
  1629. struct statvfs Buf;
  1630. string OutputDir = ".";
  1631. if (statvfs(OutputDir.c_str(),&Buf) != 0)
  1632. return _error->Errno("statvfs","Couldn't determine free space in %s",
  1633. OutputDir.c_str());
  1634. if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
  1635. return _error->Error(_("You don't have enough free space in %s"),
  1636. OutputDir.c_str());
  1637. // Number of bytes
  1638. if (DebBytes != FetchBytes)
  1639. ioprintf(c1out,_("Need to get %sB/%sB of source archives.\n"),
  1640. SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str());
  1641. else
  1642. ioprintf(c1out,_("Need to get %sB of source archives.\n"),
  1643. SizeToStr(DebBytes).c_str());
  1644. if (_config->FindB("APT::Get::Simulate",false) == true)
  1645. {
  1646. for (unsigned I = 0; I != J; I++)
  1647. ioprintf(cout,_("Fetch Source %s\n"),Dsc[I].Package.c_str());
  1648. return true;
  1649. }
  1650. // Just print out the uris an exit if the --print-uris flag was used
  1651. if (_config->FindB("APT::Get::Print-URIs") == true)
  1652. {
  1653. pkgAcquire::UriIterator I = Fetcher.UriBegin();
  1654. for (; I != Fetcher.UriEnd(); I++)
  1655. cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
  1656. I->Owner->FileSize << ' ' << I->Owner->MD5Sum() << endl;
  1657. return true;
  1658. }
  1659. // Run it
  1660. if (Fetcher.Run() == pkgAcquire::Failed)
  1661. return false;
  1662. // Print error messages
  1663. bool Failed = false;
  1664. for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
  1665. {
  1666. if ((*I)->Status == pkgAcquire::Item::StatDone &&
  1667. (*I)->Complete == true)
  1668. continue;
  1669. fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(),
  1670. (*I)->ErrorText.c_str());
  1671. Failed = true;
  1672. }
  1673. if (Failed == true)
  1674. return _error->Error(_("Failed to fetch some archives."));
  1675. if (_config->FindB("APT::Get::Download-only",false) == true)
  1676. {
  1677. c1out << _("Download complete and in download only mode") << endl;
  1678. return true;
  1679. }
  1680. // Unpack the sources
  1681. pid_t Process = ExecFork();
  1682. if (Process == 0)
  1683. {
  1684. for (unsigned I = 0; I != J; I++)
  1685. {
  1686. string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str());
  1687. // Diff only mode only fetches .diff files
  1688. if (_config->FindB("APT::Get::Diff-Only",false) == true ||
  1689. _config->FindB("APT::Get::Tar-Only",false) == true ||
  1690. Dsc[I].Dsc.empty() == true)
  1691. continue;
  1692. // See if the package is already unpacked
  1693. struct stat Stat;
  1694. if (stat(Dir.c_str(),&Stat) == 0 &&
  1695. S_ISDIR(Stat.st_mode) != 0)
  1696. {
  1697. ioprintf(c0out ,_("Skipping unpack of already unpacked source in %s\n"),
  1698. Dir.c_str());
  1699. }
  1700. else
  1701. {
  1702. // Call dpkg-source
  1703. char S[500];
  1704. snprintf(S,sizeof(S),"%s -x %s",
  1705. _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
  1706. Dsc[I].Dsc.c_str());
  1707. if (system(S) != 0)
  1708. {
  1709. fprintf(stderr,_("Unpack command '%s' failed.\n"),S);
  1710. _exit(1);
  1711. }
  1712. }
  1713. // Try to compile it with dpkg-buildpackage
  1714. if (_config->FindB("APT::Get::Compile",false) == true)
  1715. {
  1716. // Call dpkg-buildpackage
  1717. char S[500];
  1718. snprintf(S,sizeof(S),"cd %s && %s %s",
  1719. Dir.c_str(),
  1720. _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
  1721. _config->Find("DPkg::Build-Options","-b -uc").c_str());
  1722. if (system(S) != 0)
  1723. {
  1724. fprintf(stderr,_("Build command '%s' failed.\n"),S);
  1725. _exit(1);
  1726. }
  1727. }
  1728. }
  1729. _exit(0);
  1730. }
  1731. // Wait for the subprocess
  1732. int Status = 0;
  1733. while (waitpid(Process,&Status,0) != Process)
  1734. {
  1735. if (errno == EINTR)
  1736. continue;
  1737. return _error->Errno("waitpid","Couldn't wait for subprocess");
  1738. }
  1739. if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
  1740. return _error->Error(_("Child process failed"));
  1741. return true;
  1742. }
  1743. /*}}}*/
  1744. // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
  1745. // ---------------------------------------------------------------------
  1746. /* This function will look at the build depends list of the given source
  1747. package and install the necessary packages to make it true, or fail. */
  1748. bool DoBuildDep(CommandLine &CmdL)
  1749. {
  1750. CacheFile Cache;
  1751. if (Cache.Open(true) == false)
  1752. return false;
  1753. if (CmdL.FileSize() <= 1)
  1754. return _error->Error(_("Must specify at least one package to check builddeps for"));
  1755. // Read the source list
  1756. pkgSourceList List;
  1757. if (List.ReadMainList() == false)
  1758. return _error->Error(_("The list of sources could not be read."));
  1759. // Create the text record parsers
  1760. pkgRecords Recs(Cache);
  1761. pkgSrcRecords SrcRecs(List);
  1762. if (_error->PendingError() == true)
  1763. return false;
  1764. // Create the download object
  1765. AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
  1766. pkgAcquire Fetcher(&Stat);
  1767. unsigned J = 0;
  1768. for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
  1769. {
  1770. string Src;
  1771. pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,*Cache);
  1772. if (Last == 0)
  1773. return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
  1774. // Process the build-dependencies
  1775. vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps;
  1776. if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only",false)) == false)
  1777. return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
  1778. // Also ensure that build-essential packages are present
  1779. Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
  1780. if (Opts)
  1781. Opts = Opts->Child;
  1782. for (; Opts; Opts = Opts->Next)
  1783. {
  1784. if (Opts->Value.empty() == true)
  1785. continue;
  1786. pkgSrcRecords::Parser::BuildDepRec rec;
  1787. rec.Package = Opts->Value;
  1788. rec.Type = pkgSrcRecords::Parser::BuildDependIndep;
  1789. rec.Op = 0;
  1790. BuildDeps.insert(BuildDeps.begin(), rec);
  1791. }
  1792. if (BuildDeps.size() == 0)
  1793. {
  1794. ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str());
  1795. continue;
  1796. }
  1797. // Install the requested packages
  1798. unsigned int ExpectedInst = 0;
  1799. vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D;
  1800. pkgProblemResolver Fix(Cache);
  1801. for (D = BuildDeps.begin(); D != BuildDeps.end(); D++)
  1802. {
  1803. if ((*D).Type == pkgSrcRecords::Parser::BuildConflict ||
  1804. (*D).Type == pkgSrcRecords::Parser::BuildConflictIndep)
  1805. {
  1806. pkgCache::PkgIterator Pkg = Cache->FindPkg((*D).Package);
  1807. // Build-conflicts on unknown packages are silently ignored
  1808. if (Pkg.end() == true)
  1809. continue;
  1810. pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
  1811. /*
  1812. * Remove if we have an installed version that satisfies the
  1813. * version criteria
  1814. */
  1815. if (IV.end() == false &&
  1816. Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
  1817. TryToInstall(Pkg,Cache,Fix,true,false,ExpectedInst);
  1818. }
  1819. else // BuildDep || BuildDepIndep
  1820. {
  1821. pkgCache::PkgIterator Pkg = Cache->FindPkg((*D).Package);
  1822. if (Pkg.end() == true)
  1823. {
  1824. // Check if there are any alternatives
  1825. if (((*D).Op & pkgCache::Dep::Or) != pkgCache::Dep::Or)
  1826. return _error->Error(_("%s dependency for %s cannot be satisfied "
  1827. "because the package %s cannot be found"),
  1828. Last->BuildDepType((*D).Type),Src.c_str(),
  1829. (*D).Package.c_str());
  1830. // Try the next alternative
  1831. continue;
  1832. }
  1833. /*
  1834. * if there are alternatives, we've already picked one, so skip
  1835. * the rest
  1836. *
  1837. * TODO: this means that if there's a build-dep on A|B and B is
  1838. * installed, we'll still try to install A; more importantly,
  1839. * if A is currently broken, we cannot go back and try B. To fix
  1840. * this would require we do a Resolve cycle for each package we
  1841. * add to the install list. Ugh
  1842. */
  1843. while (D != BuildDeps.end() &&
  1844. (((*D).Op & pkgCache::Dep::Or) == pkgCache::Dep::Or))
  1845. D++;
  1846. /*
  1847. * If this is a virtual package, we need to check the list of
  1848. * packages that provide it and see if any of those are
  1849. * installed
  1850. */
  1851. pkgCache::PrvIterator Prv = Pkg.ProvidesList();
  1852. bool providedBySomething = !Prv.end();
  1853. for (; Prv.end() != true; Prv++)
  1854. {
  1855. if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false)
  1856. break;
  1857. }
  1858. // Get installed version and version we are going to install
  1859. pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache);
  1860. if (!providedBySomething || (*D).Version[0] != '\0') {
  1861. /* We either have a versioned dependency (so a provides won't do)
  1862. or nothing is providing this package */
  1863. pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache);
  1864. for (; CV.end() != true; CV++)
  1865. {
  1866. if (Cache->VS().CheckDep(CV.VerStr(),(*D).Op,(*D).Version.c_str()) == true)
  1867. break;
  1868. }
  1869. if (CV.end() == true)
  1870. return _error->Error(_("%s dependency for %s cannot be satisfied "
  1871. "because no available versions of package %s "
  1872. "can satisfy version requirements"),
  1873. Last->BuildDepType((*D).Type),Src.c_str(),
  1874. (*D).Package.c_str());
  1875. }
  1876. /*
  1877. * TODO: if we depend on a version lower than what we already have
  1878. * installed it is not clear what should be done; in practice
  1879. * this case should be rare, and right now nothing is
  1880. * done about it :-(
  1881. */
  1882. if (Prv.end() == true && // Nothing provides it; and
  1883. (IV.end() == true || // It is not installed, or
  1884. Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == false))
  1885. // the version installed doesn't
  1886. // satisfy constraints
  1887. TryToInstall(Pkg,Cache,Fix,false,false,ExpectedInst);
  1888. }
  1889. }
  1890. Fix.InstallProtect();
  1891. if (Fix.Resolve(true) == false)
  1892. _error->Discard();
  1893. // Now we check the state of the packages,
  1894. if (Cache->BrokenCount() != 0)
  1895. return _error->Error(_("Some broken packages were found while trying to process build-dependencies.\n"
  1896. "You might want to run `apt-get -f install' to correct these."));
  1897. }
  1898. if (InstallPackages(Cache, false, true) == false)
  1899. return _error->Error(_("Failed to process build dependencies"));
  1900. return true;
  1901. }
  1902. /*}}}*/
  1903. // DoMoo - Never Ask, Never Tell /*{{{*/
  1904. // ---------------------------------------------------------------------
  1905. /* */
  1906. bool DoMoo(CommandLine &CmdL)
  1907. {
  1908. cout <<
  1909. " (__) \n"
  1910. " (oo) \n"
  1911. " /------\\/ \n"
  1912. " / | || \n"
  1913. " * /\\---/\\ \n"
  1914. " ~~ ~~ \n"
  1915. "....\"Have you mooed today?\"...\n";
  1916. return true;
  1917. }
  1918. /*}}}*/
  1919. // ShowHelp - Show a help screen /*{{{*/
  1920. // ---------------------------------------------------------------------
  1921. /* */
  1922. bool ShowHelp(CommandLine &CmdL)
  1923. {
  1924. ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION,
  1925. COMMON_OS,COMMON_CPU,__DATE__,__TIME__);
  1926. if (_config->FindB("version") == true)
  1927. {
  1928. cout << _("Supported Modules:") << endl;
  1929. for (unsigned I = 0; I != pkgVersioningSystem::GlobalListLen; I++)
  1930. {
  1931. pkgVersioningSystem *VS = pkgVersioningSystem::GlobalList[I];
  1932. if (_system != 0 && _system->VS == VS)
  1933. cout << '*';
  1934. else
  1935. cout << ' ';
  1936. cout << "Ver: " << VS->Label << endl;
  1937. /* Print out all the packaging systems that will work with
  1938. this VS */
  1939. for (unsigned J = 0; J != pkgSystem::GlobalListLen; J++)
  1940. {
  1941. pkgSystem *Sys = pkgSystem::GlobalList[J];
  1942. if (_system == Sys)
  1943. cout << '*';
  1944. else
  1945. cout << ' ';
  1946. if (Sys->VS->TestCompatibility(*VS) == true)
  1947. cout << "Pkg: " << Sys->Label << " (Priority " << Sys->Score(*_config) << ")" << endl;
  1948. }
  1949. }
  1950. for (unsigned I = 0; I != pkgSourceList::Type::GlobalListLen; I++)
  1951. {
  1952. pkgSourceList::Type *Type = pkgSourceList::Type::GlobalList[I];
  1953. cout << " S.L: '" << Type->Name << "' " << Type->Label << endl;
  1954. }
  1955. for (unsigned I = 0; I != pkgIndexFile::Type::GlobalListLen; I++)
  1956. {
  1957. pkgIndexFile::Type *Type = pkgIndexFile::Type::GlobalList[I];
  1958. cout << " Idx: " << Type->Label << endl;
  1959. }
  1960. return true;
  1961. }
  1962. cout <<
  1963. _("Usage: apt-get [options] command\n"
  1964. " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
  1965. " apt-get [options] source pkg1 [pkg2 ...]\n"
  1966. "\n"
  1967. "apt-get is a simple command line interface for downloading and\n"
  1968. "installing packages. The most frequently used commands are update\n"
  1969. "and install.\n"
  1970. "\n"
  1971. "Commands:\n"
  1972. " update - Retrieve new lists of packages\n"
  1973. " upgrade - Perform an upgrade\n"
  1974. " install - Install new packages (pkg is libc6 not libc6.deb)\n"
  1975. " remove - Remove packages\n"
  1976. " source - Download source archives\n"
  1977. " build-dep - Configure build-dependencies for source packages\n"
  1978. " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
  1979. " dselect-upgrade - Follow dselect selections\n"
  1980. " clean - Erase downloaded archive files\n"
  1981. " autoclean - Erase old downloaded archive files\n"
  1982. " check - Verify that there are no broken dependencies\n"
  1983. "\n"
  1984. "Options:\n"
  1985. " -h This help text.\n"
  1986. " -q Loggable output - no progress indicator\n"
  1987. " -qq No output except for errors\n"
  1988. " -d Download only - do NOT install or unpack archives\n"
  1989. " -s No-act. Perform ordering simulation\n"
  1990. " -y Assume Yes to all queries and do not prompt\n"
  1991. " -f Attempt to continue if the integrity check fails\n"
  1992. " -m Attempt to continue if archives are unlocatable\n"
  1993. " -u Show a list of upgraded packages as well\n"
  1994. " -b Build the source package after fetching it\n"
  1995. " -V Show verbose version numbers\n"
  1996. " -c=? Read this configuration file\n"
  1997. " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"
  1998. "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
  1999. "pages for more information and options.\n"
  2000. " This APT has Super Cow Powers.\n");
  2001. return true;
  2002. }
  2003. /*}}}*/
  2004. // GetInitialize - Initialize things for apt-get /*{{{*/
  2005. // ---------------------------------------------------------------------
  2006. /* */
  2007. void GetInitialize()
  2008. {
  2009. _config->Set("quiet",0);
  2010. _config->Set("help",false);
  2011. _config->Set("APT::Get::Download-Only",false);
  2012. _config->Set("APT::Get::Simulate",false);
  2013. _config->Set("APT::Get::Assume-Yes",false);
  2014. _config->Set("APT::Get::Fix-Broken",false);
  2015. _config->Set("APT::Get::Force-Yes",false);
  2016. _config->Set("APT::Get::APT::Get::No-List-Cleanup",true);
  2017. }
  2018. /*}}}*/
  2019. // SigWinch - Window size change signal handler /*{{{*/
  2020. // ---------------------------------------------------------------------
  2021. /* */
  2022. void SigWinch(int)
  2023. {
  2024. // Riped from GNU ls
  2025. #ifdef TIOCGWINSZ
  2026. struct winsize ws;
  2027. if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col >= 5)
  2028. ScreenWidth = ws.ws_col - 1;
  2029. #endif
  2030. }
  2031. /*}}}*/
  2032. int main(int argc,const char *argv[])
  2033. {
  2034. CommandLine::Args Args[] = {
  2035. {'h',"help","help",0},
  2036. {'v',"version","version",0},
  2037. {'V',"verbose-versions","APT::Get::Show-Versions",0},
  2038. {'q',"quiet","quiet",CommandLine::IntLevel},
  2039. {'q',"silent","quiet",CommandLine::IntLevel},
  2040. {'d',"download-only","APT::Get::Download-Only",0},
  2041. {'b',"compile","APT::Get::Compile",0},
  2042. {'b',"build","APT::Get::Compile",0},
  2043. {'s',"simulate","APT::Get::Simulate",0},
  2044. {'s',"just-print","APT::Get::Simulate",0},
  2045. {'s',"recon","APT::Get::Simulate",0},
  2046. {'s',"dry-run","APT::Get::Simulate",0},
  2047. {'s',"no-act","APT::Get::Simulate",0},
  2048. {'y',"yes","APT::Get::Assume-Yes",0},
  2049. {'y',"assume-yes","APT::Get::Assume-Yes",0},
  2050. {'f',"fix-broken","APT::Get::Fix-Broken",0},
  2051. {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
  2052. {'m',"ignore-missing","APT::Get::Fix-Missing",0},
  2053. {'t',"target-release","APT::Default-Release",CommandLine::HasArg},
  2054. {'t',"default-release","APT::Default-Release",CommandLine::HasArg},
  2055. {0,"download","APT::Get::Download",0},
  2056. {0,"fix-missing","APT::Get::Fix-Missing",0},
  2057. {0,"ignore-hold","APT::Ignore-Hold",0},
  2058. {0,"upgrade","APT::Get::upgrade",0},
  2059. {0,"force-yes","APT::Get::force-yes",0},
  2060. {0,"print-uris","APT::Get::Print-URIs",0},
  2061. {0,"diff-only","APT::Get::Diff-Only",0},
  2062. {0,"tar-only","APT::Get::tar-Only",0},
  2063. {0,"purge","APT::Get::Purge",0},
  2064. {0,"list-cleanup","APT::Get::List-Cleanup",0},
  2065. {0,"reinstall","APT::Get::ReInstall",0},
  2066. {0,"trivial-only","APT::Get::Trivial-Only",0},
  2067. {0,"remove","APT::Get::Remove",0},
  2068. {0,"only-source","APT::Get::Only-Source",0},
  2069. {0,"arch-only","APT::Get::Arch-Only",0},
  2070. {'c',"config-file",0,CommandLine::ConfigFile},
  2071. {'o',"option",0,CommandLine::ArbItem},
  2072. {0,0,0,0}};
  2073. CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate},
  2074. {"upgrade",&DoUpgrade},
  2075. {"install",&DoInstall},
  2076. {"remove",&DoInstall},
  2077. {"dist-upgrade",&DoDistUpgrade},
  2078. {"dselect-upgrade",&DoDSelectUpgrade},
  2079. {"build-dep",&DoBuildDep},
  2080. {"clean",&DoClean},
  2081. {"autoclean",&DoAutoClean},
  2082. {"check",&DoCheck},
  2083. {"source",&DoSource},
  2084. {"moo",&DoMoo},
  2085. {"help",&ShowHelp},
  2086. {0,0}};
  2087. // Set up gettext support
  2088. setlocale(LC_ALL,"");
  2089. textdomain(PACKAGE);
  2090. // Parse the command line and initialize the package library
  2091. CommandLine CmdL(Args,_config);
  2092. if (pkgInitConfig(*_config) == false ||
  2093. CmdL.Parse(argc,argv) == false ||
  2094. pkgInitSystem(*_config,_system) == false)
  2095. {
  2096. if (_config->FindB("version") == true)
  2097. ShowHelp(CmdL);
  2098. _error->DumpErrors();
  2099. return 100;
  2100. }
  2101. // See if the help should be shown
  2102. if (_config->FindB("help") == true ||
  2103. _config->FindB("version") == true ||
  2104. CmdL.FileSize() == 0)
  2105. {
  2106. ShowHelp(CmdL);
  2107. return 0;
  2108. }
  2109. // Deal with stdout not being a tty
  2110. if (ttyname(STDOUT_FILENO) == 0 && _config->FindI("quiet",0) < 1)
  2111. _config->Set("quiet","1");
  2112. // Setup the output streams
  2113. c0out.rdbuf(cout.rdbuf());
  2114. c1out.rdbuf(cout.rdbuf());
  2115. c2out.rdbuf(cout.rdbuf());
  2116. if (_config->FindI("quiet",0) > 0)
  2117. c0out.rdbuf(devnull.rdbuf());
  2118. if (_config->FindI("quiet",0) > 1)
  2119. c1out.rdbuf(devnull.rdbuf());
  2120. // Setup the signals
  2121. signal(SIGPIPE,SIG_IGN);
  2122. signal(SIGWINCH,SigWinch);
  2123. SigWinch(0);
  2124. // Match the operation
  2125. CmdL.DispatchArg(Cmds);
  2126. // Print any errors or warnings found during parsing
  2127. if (_error->empty() == false)
  2128. {
  2129. bool Errors = _error->PendingError();
  2130. _error->DumpErrors();
  2131. return Errors == true?100:0;
  2132. }
  2133. return 0;
  2134. }