You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

763 lines
23 KiB

  1. // Include files /*{{{*/
  2. #include<config.h>
  3. #include <apt-pkg/configuration.h>
  4. #include <apt-pkg/strutl.h>
  5. #include <apt-pkg/error.h>
  6. #include <apt-pkg/cachefile.h>
  7. #include <apt-pkg/pkgrecords.h>
  8. #include <apt-pkg/policy.h>
  9. #include <apt-pkg/depcache.h>
  10. #include <apt-pkg/pkgcache.h>
  11. #include <apt-pkg/cacheiterators.h>
  12. #include <apt-private/private-output.h>
  13. #include <apt-private/private-cachefile.h>
  14. #include <regex.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <iomanip>
  19. #include <iostream>
  20. #include <langinfo.h>
  21. #include <unistd.h>
  22. #include <signal.h>
  23. #include <sys/ioctl.h>
  24. #include <sstream>
  25. #include <apti18n.h>
  26. /*}}}*/
  27. using namespace std;
  28. std::ostream c0out(0);
  29. std::ostream c1out(0);
  30. std::ostream c2out(0);
  31. std::ofstream devnull("/dev/null");
  32. unsigned int ScreenWidth = 80 - 1; /* - 1 for the cursor */
  33. // SigWinch - Window size change signal handler /*{{{*/
  34. // ---------------------------------------------------------------------
  35. /* */
  36. static void SigWinch(int)
  37. {
  38. // Riped from GNU ls
  39. #ifdef TIOCGWINSZ
  40. struct winsize ws;
  41. if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col >= 5)
  42. ScreenWidth = ws.ws_col - 1;
  43. #endif
  44. }
  45. /*}}}*/
  46. bool InitOutput(std::basic_streambuf<char> * const out) /*{{{*/
  47. {
  48. if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1)
  49. _config->Set("quiet","1");
  50. c0out.rdbuf(out);
  51. c1out.rdbuf(out);
  52. c2out.rdbuf(out);
  53. if (_config->FindI("quiet",0) > 0)
  54. c0out.rdbuf(devnull.rdbuf());
  55. if (_config->FindI("quiet",0) > 1)
  56. c1out.rdbuf(devnull.rdbuf());
  57. // deal with window size changes
  58. signal(SIGWINCH,SigWinch);
  59. SigWinch(0);
  60. if(!isatty(1))
  61. {
  62. _config->Set("APT::Color", "false");
  63. _config->Set("APT::Color::Highlight", "");
  64. _config->Set("APT::Color::Neutral", "");
  65. } else {
  66. // Colors
  67. _config->CndSet("APT::Color::Highlight", "\x1B[32m");
  68. _config->CndSet("APT::Color::Neutral", "\x1B[0m");
  69. _config->CndSet("APT::Color::Red", "\x1B[31m");
  70. _config->CndSet("APT::Color::Green", "\x1B[32m");
  71. _config->CndSet("APT::Color::Yellow", "\x1B[33m");
  72. _config->CndSet("APT::Color::Blue", "\x1B[34m");
  73. _config->CndSet("APT::Color::Magenta", "\x1B[35m");
  74. _config->CndSet("APT::Color::Cyan", "\x1B[36m");
  75. _config->CndSet("APT::Color::White", "\x1B[37m");
  76. }
  77. return true;
  78. }
  79. /*}}}*/
  80. static std::string GetArchiveSuite(pkgCacheFile &/*CacheFile*/, pkgCache::VerIterator ver) /*{{{*/
  81. {
  82. std::string suite = "";
  83. if (ver && ver.FileList())
  84. {
  85. pkgCache::VerFileIterator VF = ver.FileList();
  86. for (; VF.end() == false ; ++VF)
  87. {
  88. if(VF.File() == NULL || VF.File().Archive() == NULL)
  89. suite = suite + "," + _("unknown");
  90. else
  91. suite = suite + "," + VF.File().Archive();
  92. //suite = VF.File().Archive();
  93. }
  94. suite = suite.erase(0, 1);
  95. }
  96. return suite;
  97. }
  98. /*}}}*/
  99. static std::string GetFlagsStr(pkgCacheFile &CacheFile, pkgCache::PkgIterator P)/*{{{*/
  100. {
  101. pkgDepCache *DepCache = CacheFile.GetDepCache();
  102. pkgDepCache::StateCache &state = (*DepCache)[P];
  103. std::string flags_str;
  104. if (state.NowBroken())
  105. flags_str = "B";
  106. if (P.CurrentVer() && state.Upgradable() && state.CandidateVer != NULL)
  107. flags_str = "g";
  108. else if (P.CurrentVer() != NULL)
  109. flags_str = "i";
  110. else
  111. flags_str = "-";
  112. return flags_str;
  113. }
  114. /*}}}*/
  115. static std::string GetCandidateVersion(pkgCacheFile &CacheFile, pkgCache::PkgIterator P)/*{{{*/
  116. {
  117. pkgPolicy *policy = CacheFile.GetPolicy();
  118. pkgCache::VerIterator cand = policy->GetCandidateVer(P);
  119. return cand ? cand.VerStr() : "(none)";
  120. }
  121. /*}}}*/
  122. static std::string GetInstalledVersion(pkgCacheFile &/*CacheFile*/, pkgCache::PkgIterator P)/*{{{*/
  123. {
  124. pkgCache::VerIterator inst = P.CurrentVer();
  125. return inst ? inst.VerStr() : "(none)";
  126. }
  127. /*}}}*/
  128. static std::string GetVersion(pkgCacheFile &/*CacheFile*/, pkgCache::VerIterator V)/*{{{*/
  129. {
  130. pkgCache::PkgIterator P = V.ParentPkg();
  131. if (V == P.CurrentVer())
  132. {
  133. std::string inst_str = DeNull(V.VerStr());
  134. #if 0 // FIXME: do we want this or something like this?
  135. pkgDepCache *DepCache = CacheFile.GetDepCache();
  136. pkgDepCache::StateCache &state = (*DepCache)[P];
  137. if (state.Upgradable())
  138. return "**"+inst_str;
  139. #endif
  140. return inst_str;
  141. }
  142. if(V)
  143. return DeNull(V.VerStr());
  144. return "(none)";
  145. }
  146. /*}}}*/
  147. static std::string GetArchitecture(pkgCacheFile &CacheFile, pkgCache::PkgIterator P)/*{{{*/
  148. {
  149. if (P->CurrentVer == 0)
  150. {
  151. pkgDepCache * const DepCache = CacheFile.GetDepCache();
  152. pkgDepCache::StateCache const &state = (*DepCache)[P];
  153. if (state.CandidateVer != NULL)
  154. {
  155. pkgCache::VerIterator const CandV(CacheFile, state.CandidateVer);
  156. return CandV.Arch();
  157. }
  158. else
  159. {
  160. pkgCache::VerIterator const V = P.VersionList();
  161. if (V.end() == false)
  162. return V.Arch();
  163. else
  164. return P.Arch();
  165. }
  166. }
  167. else
  168. return P.CurrentVer().Arch();
  169. }
  170. /*}}}*/
  171. static std::string GetShortDescription(pkgCacheFile &CacheFile, pkgRecords &records, pkgCache::PkgIterator P)/*{{{*/
  172. {
  173. pkgPolicy *policy = CacheFile.GetPolicy();
  174. pkgCache::VerIterator ver;
  175. if (P.CurrentVer())
  176. ver = P.CurrentVer();
  177. else
  178. ver = policy->GetCandidateVer(P);
  179. std::string ShortDescription = "(none)";
  180. if(ver)
  181. {
  182. pkgCache::DescIterator const Desc = ver.TranslatedDescription();
  183. if (Desc.end() == false)
  184. {
  185. pkgRecords::Parser & parser = records.Lookup(Desc.FileList());
  186. ShortDescription = parser.ShortDesc();
  187. }
  188. }
  189. return ShortDescription;
  190. }
  191. /*}}}*/
  192. static std::string GetLongDescription(pkgCacheFile &CacheFile, pkgRecords &records, pkgCache::PkgIterator P)/*{{{*/
  193. {
  194. pkgPolicy *policy = CacheFile.GetPolicy();
  195. pkgCache::VerIterator ver;
  196. if (P->CurrentVer != 0)
  197. ver = P.CurrentVer();
  198. else
  199. ver = policy->GetCandidateVer(P);
  200. std::string const EmptyDescription = "(none)";
  201. if(ver.end() == true)
  202. return EmptyDescription;
  203. pkgCache::DescIterator const Desc = ver.TranslatedDescription();
  204. if (Desc.end() == false)
  205. {
  206. pkgRecords::Parser & parser = records.Lookup(Desc.FileList());
  207. std::string const longdesc = parser.LongDesc();
  208. if (longdesc.empty() == false)
  209. return SubstVar(longdesc, "\n ", "\n ");
  210. }
  211. return EmptyDescription;
  212. }
  213. /*}}}*/
  214. void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/
  215. pkgCache::VerIterator const &V, std::ostream &out,
  216. std::string const &format)
  217. {
  218. pkgCache::PkgIterator const P = V.ParentPkg();
  219. pkgDepCache * const DepCache = CacheFile.GetDepCache();
  220. pkgDepCache::StateCache const &state = (*DepCache)[P];
  221. std::string output;
  222. if (_config->FindB("APT::Cmd::use-format", false))
  223. output = _config->Find("APT::Cmd::format", "${db::Status-Abbrev} ${Package} ${Version} ${Origin} ${Description}");
  224. else
  225. output = format;
  226. // FIXME: some of these names are really icky – and all is nowhere documented
  227. output = SubstVar(output, "${db::Status-Abbrev}", GetFlagsStr(CacheFile, P));
  228. output = SubstVar(output, "${Package}", P.Name());
  229. std::string const ArchStr = GetArchitecture(CacheFile, P);
  230. output = SubstVar(output, "${Architecture}", ArchStr);
  231. std::string const InstalledVerStr = GetInstalledVersion(CacheFile, P);
  232. output = SubstVar(output, "${installed:Version}", InstalledVerStr);
  233. std::string const CandidateVerStr = GetCandidateVersion(CacheFile, P);
  234. output = SubstVar(output, "${candidate:Version}", CandidateVerStr);
  235. std::string const VersionStr = GetVersion(CacheFile, V);
  236. output = SubstVar(output, "${Version}", VersionStr);
  237. output = SubstVar(output, "${Origin}", GetArchiveSuite(CacheFile, V));
  238. std::string StatusStr = "";
  239. if (P->CurrentVer != 0)
  240. {
  241. if (P.CurrentVer() == V)
  242. {
  243. if (state.Upgradable() && state.CandidateVer != NULL)
  244. strprintf(StatusStr, _("[installed,upgradable to: %s]"),
  245. CandidateVerStr.c_str());
  246. else if (V.Downloadable() == false)
  247. StatusStr = _("[installed,local]");
  248. else if(V.Automatic() == true && state.Garbage == true)
  249. StatusStr = _("[installed,auto-removable]");
  250. else if ((state.Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto)
  251. StatusStr = _("[installed,automatic]");
  252. else
  253. StatusStr = _("[installed]");
  254. }
  255. else if (state.CandidateVer == V && state.Upgradable())
  256. strprintf(StatusStr, _("[upgradable from: %s]"),
  257. InstalledVerStr.c_str());
  258. }
  259. else if (V.ParentPkg()->CurrentState == pkgCache::State::ConfigFiles)
  260. StatusStr = _("[residual-config]");
  261. output = SubstVar(output, "${apt:Status}", StatusStr);
  262. output = SubstVar(output, "${color:highlight}", _config->Find("APT::Color::Highlight", ""));
  263. output = SubstVar(output, "${color:neutral}", _config->Find("APT::Color::Neutral", ""));
  264. output = SubstVar(output, "${Description}", GetShortDescription(CacheFile, records, P));
  265. output = SubstVar(output, "${LongDescription}", GetLongDescription(CacheFile, records, P));
  266. output = SubstVar(output, "${ }${ }", "${ }");
  267. output = SubstVar(output, "${ }\n", "\n");
  268. output = SubstVar(output, "${ }", " ");
  269. if (APT::String::Endswith(output, " ") == true)
  270. output.erase(output.length() - 1);
  271. out << output;
  272. }
  273. /*}}}*/
  274. // ShowBroken - Debugging aide /*{{{*/
  275. // ---------------------------------------------------------------------
  276. /* This prints out the names of all the packages that are broken along
  277. with the name of each each broken dependency and a quite version
  278. description.
  279. The output looks like:
  280. The following packages have unmet dependencies:
  281. exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
  282. Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
  283. Depends: libsasl7 but it is not going to be installed
  284. */
  285. static void ShowBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg, bool const Now)
  286. {
  287. if (Now == true)
  288. {
  289. if ((*Cache)[Pkg].NowBroken() == false)
  290. return;
  291. }
  292. else
  293. {
  294. if ((*Cache)[Pkg].InstBroken() == false)
  295. return;
  296. }
  297. // Print out each package and the failed dependencies
  298. out << " " << Pkg.FullName(true) << " :";
  299. unsigned const Indent = Pkg.FullName(true).size() + 3;
  300. bool First = true;
  301. pkgCache::VerIterator Ver;
  302. if (Now == true)
  303. Ver = Pkg.CurrentVer();
  304. else
  305. Ver = (*Cache)[Pkg].InstVerIter(*Cache);
  306. if (Ver.end() == true)
  307. {
  308. out << endl;
  309. return;
  310. }
  311. for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;)
  312. {
  313. // Compute a single dependency element (glob or)
  314. pkgCache::DepIterator Start;
  315. pkgCache::DepIterator End;
  316. D.GlobOr(Start,End); // advances D
  317. if ((*Cache)->IsImportantDep(End) == false)
  318. continue;
  319. if (Now == true)
  320. {
  321. if (((*Cache)[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow)
  322. continue;
  323. }
  324. else
  325. {
  326. if (((*Cache)[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
  327. continue;
  328. }
  329. bool FirstOr = true;
  330. while (1)
  331. {
  332. if (First == false)
  333. for (unsigned J = 0; J != Indent; J++)
  334. out << ' ';
  335. First = false;
  336. if (FirstOr == false)
  337. {
  338. for (unsigned J = 0; J != strlen(End.DepType()) + 3; J++)
  339. out << ' ';
  340. }
  341. else
  342. out << ' ' << End.DepType() << ": ";
  343. FirstOr = false;
  344. out << Start.TargetPkg().FullName(true);
  345. // Show a quick summary of the version requirements
  346. if (Start.TargetVer() != 0)
  347. out << " (" << Start.CompType() << " " << Start.TargetVer() << ")";
  348. /* Show a summary of the target package if possible. In the case
  349. of virtual packages we show nothing */
  350. pkgCache::PkgIterator Targ = Start.TargetPkg();
  351. if (Targ->ProvidesList == 0)
  352. {
  353. out << ' ';
  354. pkgCache::VerIterator Ver = (*Cache)[Targ].InstVerIter(*Cache);
  355. if (Now == true)
  356. Ver = Targ.CurrentVer();
  357. if (Ver.end() == false)
  358. {
  359. if (Now == true)
  360. ioprintf(out,_("but %s is installed"),Ver.VerStr());
  361. else
  362. ioprintf(out,_("but %s is to be installed"),Ver.VerStr());
  363. }
  364. else
  365. {
  366. if ((*Cache)[Targ].CandidateVerIter(*Cache).end() == true)
  367. {
  368. if (Targ->ProvidesList == 0)
  369. out << _("but it is not installable");
  370. else
  371. out << _("but it is a virtual package");
  372. }
  373. else
  374. out << (Now?_("but it is not installed"):_("but it is not going to be installed"));
  375. }
  376. }
  377. if (Start != End)
  378. out << _(" or");
  379. out << endl;
  380. if (Start == End)
  381. break;
  382. ++Start;
  383. }
  384. }
  385. }
  386. void ShowBroken(ostream &out, CacheFile &Cache, bool const Now)
  387. {
  388. if (Cache->BrokenCount() == 0)
  389. return;
  390. out << _("The following packages have unmet dependencies:") << endl;
  391. SortedPackageUniverse Universe(Cache);
  392. for (auto const &Pkg: Universe)
  393. ShowBrokenPackage(out, &Cache, Pkg, Now);
  394. }
  395. void ShowBroken(ostream &out, pkgCacheFile &Cache, bool const Now)
  396. {
  397. if (Cache->BrokenCount() == 0)
  398. return;
  399. out << _("The following packages have unmet dependencies:") << endl;
  400. APT::PackageUniverse Universe(Cache);
  401. for (auto const &Pkg: Universe)
  402. ShowBrokenPackage(out, &Cache, Pkg, Now);
  403. }
  404. /*}}}*/
  405. // ShowNew - Show packages to newly install /*{{{*/
  406. void ShowNew(ostream &out,CacheFile &Cache)
  407. {
  408. SortedPackageUniverse Universe(Cache);
  409. ShowList(out,_("The following NEW packages will be installed:"), Universe,
  410. [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].NewInstall(); },
  411. &PrettyFullName,
  412. CandidateVersion(&Cache));
  413. }
  414. /*}}}*/
  415. // ShowDel - Show packages to delete /*{{{*/
  416. void ShowDel(ostream &out,CacheFile &Cache)
  417. {
  418. SortedPackageUniverse Universe(Cache);
  419. ShowList(out,_("The following packages will be REMOVED:"), Universe,
  420. [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].Delete(); },
  421. [&Cache](pkgCache::PkgIterator const &Pkg)
  422. {
  423. std::string str = PrettyFullName(Pkg);
  424. if (((*Cache)[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge)
  425. str.append("*");
  426. return str;
  427. },
  428. CandidateVersion(&Cache));
  429. }
  430. /*}}}*/
  431. // ShowKept - Show kept packages /*{{{*/
  432. void ShowKept(ostream &out,CacheFile &Cache)
  433. {
  434. SortedPackageUniverse Universe(Cache);
  435. ShowList(out,_("The following packages have been kept back:"), Universe,
  436. [&Cache](pkgCache::PkgIterator const &Pkg)
  437. {
  438. return Cache[Pkg].Upgrade() == false &&
  439. Cache[Pkg].Upgradable() == true &&
  440. Pkg->CurrentVer != 0 &&
  441. Cache[Pkg].Delete() == false;
  442. },
  443. &PrettyFullName,
  444. CurrentToCandidateVersion(&Cache));
  445. }
  446. /*}}}*/
  447. // ShowUpgraded - Show upgraded packages /*{{{*/
  448. void ShowUpgraded(ostream &out,CacheFile &Cache)
  449. {
  450. SortedPackageUniverse Universe(Cache);
  451. ShowList(out,_("The following packages will be upgraded:"), Universe,
  452. [&Cache](pkgCache::PkgIterator const &Pkg)
  453. {
  454. return Cache[Pkg].Upgrade() == true && Cache[Pkg].NewInstall() == false;
  455. },
  456. &PrettyFullName,
  457. CurrentToCandidateVersion(&Cache));
  458. }
  459. /*}}}*/
  460. // ShowDowngraded - Show downgraded packages /*{{{*/
  461. // ---------------------------------------------------------------------
  462. /* */
  463. bool ShowDowngraded(ostream &out,CacheFile &Cache)
  464. {
  465. SortedPackageUniverse Universe(Cache);
  466. return ShowList(out,_("The following packages will be DOWNGRADED:"), Universe,
  467. [&Cache](pkgCache::PkgIterator const &Pkg)
  468. {
  469. return Cache[Pkg].Downgrade() == true && Cache[Pkg].NewInstall() == false;
  470. },
  471. &PrettyFullName,
  472. CurrentToCandidateVersion(&Cache));
  473. }
  474. /*}}}*/
  475. // ShowHold - Show held but changed packages /*{{{*/
  476. bool ShowHold(ostream &out,CacheFile &Cache)
  477. {
  478. SortedPackageUniverse Universe(Cache);
  479. return ShowList(out,_("The following held packages will be changed:"), Universe,
  480. [&Cache](pkgCache::PkgIterator const &Pkg)
  481. {
  482. return Pkg->SelectedState == pkgCache::State::Hold &&
  483. Cache[Pkg].InstallVer != (pkgCache::Version *)Pkg.CurrentVer();
  484. },
  485. &PrettyFullName,
  486. CurrentToCandidateVersion(&Cache));
  487. }
  488. /*}}}*/
  489. // ShowEssential - Show an essential package warning /*{{{*/
  490. // ---------------------------------------------------------------------
  491. /* This prints out a warning message that is not to be ignored. It shows
  492. all essential packages and their dependents that are to be removed.
  493. It is insanely risky to remove the dependents of an essential package! */
  494. struct APT_HIDDEN PrettyFullNameWithDue {
  495. std::map<unsigned long long, pkgCache::PkgIterator> due;
  496. PrettyFullNameWithDue() {}
  497. std::string operator() (pkgCache::PkgIterator const &Pkg)
  498. {
  499. std::string const A = PrettyFullName(Pkg);
  500. std::map<unsigned long long, pkgCache::PkgIterator>::const_iterator d = due.find(Pkg->ID);
  501. if (d == due.end())
  502. return A;
  503. std::string const B = PrettyFullName(d->second);
  504. std::ostringstream outstr;
  505. ioprintf(outstr, _("%s (due to %s)"), A.c_str(), B.c_str());
  506. return outstr.str();
  507. }
  508. };
  509. bool ShowEssential(ostream &out,CacheFile &Cache)
  510. {
  511. std::vector<bool> Added(Cache->Head().PackageCount, false);
  512. APT::PackageDeque pkglist;
  513. PrettyFullNameWithDue withdue;
  514. SortedPackageUniverse Universe(Cache);
  515. for (pkgCache::PkgIterator const &I: Universe)
  516. {
  517. if ((I->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential &&
  518. (I->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important)
  519. continue;
  520. // The essential package is being removed
  521. if (Cache[I].Delete() == false)
  522. continue;
  523. if (Added[I->ID] == false)
  524. {
  525. Added[I->ID] = true;
  526. pkglist.insert(I);
  527. }
  528. if (I->CurrentVer == 0)
  529. continue;
  530. // Print out any essential package depenendents that are to be removed
  531. for (pkgCache::DepIterator D = I.CurrentVer().DependsList(); D.end() == false; ++D)
  532. {
  533. // Skip everything but depends
  534. if (D->Type != pkgCache::Dep::PreDepends &&
  535. D->Type != pkgCache::Dep::Depends)
  536. continue;
  537. pkgCache::PkgIterator P = D.SmartTargetPkg();
  538. if (Cache[P].Delete() == true)
  539. {
  540. if (Added[P->ID] == true)
  541. continue;
  542. Added[P->ID] = true;
  543. pkglist.insert(P);
  544. withdue.due[P->ID] = I;
  545. }
  546. }
  547. }
  548. return ShowList(out,_("WARNING: The following essential packages will be removed.\n"
  549. "This should NOT be done unless you know exactly what you are doing!"),
  550. pkglist, &AlwaysTrue, withdue, &EmptyString);
  551. }
  552. /*}}}*/
  553. // Stats - Show some statistics /*{{{*/
  554. // ---------------------------------------------------------------------
  555. /* */
  556. void Stats(ostream &out,pkgDepCache &Dep)
  557. {
  558. unsigned long Upgrade = 0;
  559. unsigned long Downgrade = 0;
  560. unsigned long Install = 0;
  561. unsigned long ReInstall = 0;
  562. for (pkgCache::PkgIterator I = Dep.PkgBegin(); I.end() == false; ++I)
  563. {
  564. if (Dep[I].NewInstall() == true)
  565. Install++;
  566. else
  567. {
  568. if (Dep[I].Upgrade() == true)
  569. Upgrade++;
  570. else
  571. if (Dep[I].Downgrade() == true)
  572. Downgrade++;
  573. }
  574. if (Dep[I].Delete() == false && (Dep[I].iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)
  575. ReInstall++;
  576. }
  577. ioprintf(out,_("%lu upgraded, %lu newly installed, "),
  578. Upgrade,Install);
  579. if (ReInstall != 0)
  580. ioprintf(out,_("%lu reinstalled, "),ReInstall);
  581. if (Downgrade != 0)
  582. ioprintf(out,_("%lu downgraded, "),Downgrade);
  583. ioprintf(out,_("%lu to remove and %lu not upgraded.\n"),
  584. Dep.DelCount(),Dep.KeepCount());
  585. if (Dep.BadCount() != 0)
  586. ioprintf(out,_("%lu not fully installed or removed.\n"),
  587. Dep.BadCount());
  588. }
  589. /*}}}*/
  590. // YnPrompt - Yes No Prompt. /*{{{*/
  591. // ---------------------------------------------------------------------
  592. /* Returns true on a Yes.*/
  593. bool YnPrompt(bool Default)
  594. {
  595. /* nl_langinfo does not support LANGUAGE setting, so we unset it here
  596. to have the help-message (hopefully) match the expected characters */
  597. char * language = getenv("LANGUAGE");
  598. if (language != NULL)
  599. language = strdup(language);
  600. if (language != NULL)
  601. unsetenv("LANGUAGE");
  602. if (Default == true)
  603. // TRANSLATOR: Yes/No question help-text: defaulting to Y[es]
  604. // e.g. "Do you want to continue? [Y/n] "
  605. // The user has to answer with an input matching the
  606. // YESEXPR/NOEXPR defined in your l10n.
  607. c2out << " " << _("[Y/n]") << " " << std::flush;
  608. else
  609. // TRANSLATOR: Yes/No question help-text: defaulting to N[o]
  610. // e.g. "Should this file be removed? [y/N] "
  611. // The user has to answer with an input matching the
  612. // YESEXPR/NOEXPR defined in your l10n.
  613. c2out << " " << _("[y/N]") << " " << std::flush;
  614. if (language != NULL)
  615. {
  616. setenv("LANGUAGE", language, 0);
  617. free(language);
  618. }
  619. if (_config->FindB("APT::Get::Assume-Yes",false) == true)
  620. {
  621. // TRANSLATOR: "Yes" answer printed for a yes/no question if --assume-yes is set
  622. c1out << _("Y") << std::endl;
  623. return true;
  624. }
  625. else if (_config->FindB("APT::Get::Assume-No",false) == true)
  626. {
  627. // TRANSLATOR: "No" answer printed for a yes/no question if --assume-no is set
  628. c1out << _("N") << std::endl;
  629. return false;
  630. }
  631. char response[1024] = "";
  632. std::cin.getline(response, sizeof(response));
  633. if (!std::cin)
  634. return false;
  635. if (strlen(response) == 0)
  636. return Default;
  637. regex_t Pattern;
  638. int Res;
  639. Res = regcomp(&Pattern, nl_langinfo(YESEXPR),
  640. REG_EXTENDED|REG_ICASE|REG_NOSUB);
  641. if (Res != 0) {
  642. char Error[300];
  643. regerror(Res,&Pattern,Error,sizeof(Error));
  644. return _error->Error(_("Regex compilation error - %s"),Error);
  645. }
  646. Res = regexec(&Pattern, response, 0, NULL, 0);
  647. if (Res == 0)
  648. return true;
  649. return false;
  650. }
  651. /*}}}*/
  652. // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
  653. // ---------------------------------------------------------------------
  654. /* Returns true on a Yes.*/
  655. bool AnalPrompt(const char *Text)
  656. {
  657. char Buf[1024];
  658. std::cin.getline(Buf,sizeof(Buf));
  659. if (strcmp(Buf,Text) == 0)
  660. return true;
  661. return false;
  662. }
  663. /*}}}*/
  664. std::string PrettyFullName(pkgCache::PkgIterator const &Pkg)
  665. {
  666. return Pkg.FullName(true);
  667. }
  668. std::string CandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg)
  669. {
  670. return (*Cache)[Pkg].CandVersion;
  671. }
  672. std::function<std::string(pkgCache::PkgIterator const &)> CandidateVersion(pkgCacheFile * const Cache)
  673. {
  674. return std::bind(static_cast<std::string(*)(pkgCacheFile * const, pkgCache::PkgIterator const&)>(&CandidateVersion), Cache, std::placeholders::_1);
  675. }
  676. std::string CurrentToCandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg)
  677. {
  678. return std::string((*Cache)[Pkg].CurVersion) + " => " + (*Cache)[Pkg].CandVersion;
  679. }
  680. std::function<std::string(pkgCache::PkgIterator const &)> CurrentToCandidateVersion(pkgCacheFile * const Cache)
  681. {
  682. return std::bind(static_cast<std::string(*)(pkgCacheFile * const, pkgCache::PkgIterator const&)>(&CurrentToCandidateVersion), Cache, std::placeholders::_1);
  683. }
  684. bool AlwaysTrue(pkgCache::PkgIterator const &)
  685. {
  686. return true;
  687. }
  688. std::string EmptyString(pkgCache::PkgIterator const &)
  689. {
  690. return std::string();
  691. }