apt  2.2.4
About: Apt (Advanced Package Tool) is a management system for software packages (Debian/Ubuntu). Release series 2.2.
  Fossies Dox: apt-2.2.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

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