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-install.cc
Go to the documentation of this file.
1 // Include Files /*{{{*/
2 #include <config.h>
3 
4 #include <apt-pkg/acquire-item.h>
5 #include <apt-pkg/acquire.h>
6 #include <apt-pkg/algorithms.h>
7 #include <apt-pkg/cachefile.h>
8 #include <apt-pkg/cacheset.h>
9 #include <apt-pkg/cmndline.h>
10 #include <apt-pkg/configuration.h>
11 #include <apt-pkg/depcache.h>
12 #include <apt-pkg/error.h>
13 #include <apt-pkg/fileutl.h>
15 #include <apt-pkg/macros.h>
16 #include <apt-pkg/packagemanager.h>
17 #include <apt-pkg/pkgcache.h>
18 #include <apt-pkg/pkgrecords.h>
19 #include <apt-pkg/pkgsystem.h>
20 #include <apt-pkg/prettyprinters.h>
21 #include <apt-pkg/strutl.h>
22 #include <apt-pkg/upgrade.h>
23 
24 #include <algorithm>
25 #include <iostream>
26 #include <map>
27 #include <set>
28 #include <vector>
29 #include <stdlib.h>
30 #include <string.h>
31 
39 
40 #include <apti18n.h>
41  /*}}}*/
42 class pkgSourceList;
43 
44 bool CheckNothingBroken(CacheFile &Cache) /*{{{*/
45 {
46  // Now we check the state of the packages,
47  if (Cache->BrokenCount() == 0)
48  return true;
49 
50  // FIXME: if an external solver showed an error, we shouldn't show one here
51  if (_error->PendingError() && _config->Find("APT::Solver") == "dump")
52  return false;
53 
54  c1out <<
55  _("Some packages could not be installed. This may mean that you have\n"
56  "requested an impossible situation or if you are using the unstable\n"
57  "distribution that some required packages have not yet been created\n"
58  "or been moved out of Incoming.") << std::endl;
59  /*
60  if (Packages == 1)
61  {
62  c1out << std::endl;
63  c1out <<
64  _("Since you only requested a single operation it is extremely likely that\n"
65  "the package is simply not installable and a bug report against\n"
66  "that package should be filed.") << std::endl;
67  }
68  */
69 
70  c1out << _("The following information may help to resolve the situation:") << std::endl;
71  c1out << std::endl;
72  ShowBroken(c1out,Cache,false);
73  if (_error->PendingError() == true)
74  return false;
75  else
76  return _error->Error(_("Broken packages"));
77 }
78  /*}}}*/
79 // InstallPackages - Actually download and install the packages /*{{{*/
80 // ---------------------------------------------------------------------
81 /* This displays the informative messages describing what is going to
82  happen and then calls the download routines */
83 static void RemoveDownloadNeedingItemsFromFetcher(pkgAcquire &Fetcher, bool &Transient)
84 {
85  for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd();)
86  {
87  if ((*I)->Local == true)
88  {
89  ++I;
90  continue;
91  }
92 
93  // Close the item and check if it was found in cache
94  (*I)->Finished();
95  if ((*I)->Complete == false)
96  Transient = true;
97 
98  // Clear it out of the fetch list
99  delete *I;
100  I = Fetcher.ItemsBegin();
101  }
102 }
103 bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
104 {
105  if (not RunScripts("APT::Install::Pre-Invoke"))
106  return false;
107  if (_config->FindB("APT::Get::Purge", false) == true)
108  for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; ++I)
109  if (Cache[I].Delete() == true && Cache[I].Purge() == false)
110  Cache->MarkDelete(I,true);
111 
112  // Create the download object
113  auto const DownloadAllowed = _config->FindB("APT::Get::Download",true);
114  aptAcquireWithTextStatus Fetcher;
115  if (_config->FindB("APT::Get::Print-URIs", false) == true)
116  {
117  // force a hashsum for compatibility reasons
118  _config->CndSet("Acquire::ForceHash", "md5sum");
119  }
120  else if (_config->FindB("APT::Get::Simulate") == true)
121  ;
122  else if (Fetcher.GetLock(_config->FindDir("Dir::Cache::Archives")) == false)
123  return false;
124 
125  // Read the source list
126  if (Cache.BuildSourceList() == false)
127  return false;
128  pkgSourceList * const List = Cache.GetSourceList();
129 
130  // Create the text record parser
131  pkgRecords Recs(Cache);
132  if (_error->PendingError() == true)
133  return false;
134 
135  // Create the package manager and prepare to download
136  std::unique_ptr<pkgPackageManager> PM(_system->CreatePM(Cache));
137  if (PM->GetArchives(&Fetcher,List,&Recs) == false ||
138  _error->PendingError() == true)
139  return false;
140 
141  if (DownloadAllowed == false)
142  {
143  bool Missing = false;
144  RemoveDownloadNeedingItemsFromFetcher(Fetcher, Missing);
145  if (Missing)
146  {
147  if (_config->FindB("APT::Get::Fix-Missing",false))
148  PM->FixMissing();
149  else
150  return _error->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
151  }
152  Fetcher.Shutdown();
153  if (_error->PendingError() == true)
154  return false;
155  }
156 
157  // Show all the various warning indicators
158  ShowDel(c1out,Cache);
159  ShowNew(c1out,Cache);
160  if (ShwKept == true)
161  ShowKept(c1out,Cache);
162  bool const Hold = !ShowHold(c1out,Cache);
163  if (_config->FindB("APT::Get::Show-Upgraded",true) == true)
164  ShowUpgraded(c1out,Cache);
165  bool const Downgrade = !ShowDowngraded(c1out,Cache);
166 
167  bool Essential = false;
168  if (_config->FindB("APT::Get::Download-Only",false) == false)
169  Essential = !ShowEssential(c1out,Cache);
170 
171  Stats(c1out,Cache);
172 
173  // Sanity check
174  if (Cache->BrokenCount() != 0)
175  {
176  ShowBroken(c1out,Cache,false);
177  return _error->Error(_("Internal error, InstallPackages was called with broken packages!"));
178  }
179 
180  if (Cache->DelCount() == 0 && Cache->InstCount() == 0 &&
181  Cache->BadCount() == 0)
182  return RunScripts("APT::Install::Post-Invoke-Success");
183 
184  // No remove flag
185  if (Cache->DelCount() != 0 && _config->FindB("APT::Get::Remove",true) == false)
186  return _error->Error(_("Packages need to be removed but remove is disabled."));
187 
188  // Fail safe check
189  bool const Fail = (Essential || Downgrade || Hold);
190  if (_config->FindI("quiet",0) >= 2 ||
191  _config->FindB("APT::Get::Assume-Yes",false) == true)
192  {
193  if (Fail == true && _config->FindB("APT::Get::Force-Yes",false) == false) {
194  if (Essential == true && _config->FindB("APT::Get::allow-remove-essential", false) == false)
195  return _error->Error(_("Essential packages were removed and -y was used without --allow-remove-essential."));
196  if (Downgrade == true && _config->FindB("APT::Get::allow-downgrades", false) == false)
197  return _error->Error(_("Packages were downgraded and -y was used without --allow-downgrades."));
198  if (Hold == true && _config->FindB("APT::Get::allow-change-held-packages", false) == false)
199  return _error->Error(_("Held packages were changed and -y was used without --allow-change-held-packages."));
200  }
201  }
202 
203  // Run the simulator ..
204  if (_config->FindB("APT::Get::Simulate") == true)
205  {
206  pkgSimulate PM(Cache);
207 
209  pkgPackageManager::OrderResult Res = PM.DoInstall(progress);
210  delete progress;
211 
212  if (Res == pkgPackageManager::Failed)
213  return false;
214  if (Res != pkgPackageManager::Completed)
215  return _error->Error(_("Internal error, Ordering didn't finish"));
216  return true;
217  }
218 
219  auto const FetchBytes = DownloadAllowed ? Fetcher.FetchNeeded() : 0;
220  auto const FetchPBytes = DownloadAllowed ? Fetcher.PartialPresent() : 0;
221  if (DownloadAllowed)
222  {
223  // Display statistics
224  auto const DebBytes = Fetcher.TotalNeeded();
225  if (DebBytes != Cache->DebSize())
226  {
227  c0out << "E: " << DebBytes << ',' << Cache->DebSize() << std::endl;
228  c0out << "E: " << _("How odd... The sizes didn't match, email apt@packages.debian.org") << std::endl;
229  }
230 
231  // Number of bytes
232  if (DebBytes != FetchBytes)
233  //TRANSLATOR: The required space between number and unit is already included
234  // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
235  ioprintf(c1out,_("Need to get %sB/%sB of archives.\n"),
236  SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str());
237  else if (DebBytes != 0)
238  //TRANSLATOR: The required space between number and unit is already included
239  // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
240  ioprintf(c1out,_("Need to get %sB of archives.\n"),
241  SizeToStr(DebBytes).c_str());
242  }
243 
244  // Size delta
245  if (Cache->UsrSize() >= 0)
246  //TRANSLATOR: The required space between number and unit is already included
247  // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
248  ioprintf(c1out,_("After this operation, %sB of additional disk space will be used.\n"),
249  SizeToStr(Cache->UsrSize()).c_str());
250  else
251  //TRANSLATOR: The required space between number and unit is already included
252  // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
253  ioprintf(c1out,_("After this operation, %sB disk space will be freed.\n"),
254  SizeToStr(-1*Cache->UsrSize()).c_str());
255 
256  if (DownloadAllowed)
257  if (CheckFreeSpaceBeforeDownload(_config->FindDir("Dir::Cache::Archives"), (FetchBytes - FetchPBytes)) == false)
258  return false;
259 
260  if (_error->PendingError() == true)
261  return false;
262 
263  // Just print out the uris an exit if the --print-uris flag was used
264  if (_config->FindB("APT::Get::Print-URIs") == true)
265  {
266  pkgAcquire::UriIterator I = Fetcher.UriBegin();
267  for (; I != Fetcher.UriEnd(); ++I)
268  std::cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
269  std::to_string(I->Owner->FileSize) << ' ' << I->Owner->HashSum() << std::endl;
270  return true;
271  }
272 
273  if (Essential == true && Safety == true && _config->FindB("APT::Get::allow-remove-essential", false) == false)
274  {
275  if (_config->FindB("APT::Get::Trivial-Only",false) == true)
276  return _error->Error(_("Trivial Only specified but this is not a trivial operation."));
277 
278  // TRANSLATOR: This string needs to be typed by the user as a confirmation, so be
279  // careful with hard to type or special characters (like non-breaking spaces)
280  const char *Prompt = _("Yes, do as I say!");
281  std::string question;
282  strprintf(question,
283  _("You are about to do something potentially harmful.\n"
284  "To continue type in the phrase '%s'\n"
285  " ?] "),Prompt);
286  if (AnalPrompt(question, Prompt) == false)
287  {
288  c2out << _("Abort.") << std::endl;
289  exit(1);
290  }
291  }
292  else
293  {
294  // Prompt to continue
295  if (Ask == true || Fail == true)
296  {
297  if (_config->FindB("APT::Get::Trivial-Only",false) == true)
298  return _error->Error(_("Trivial Only specified but this is not a trivial operation."));
299 
300  if (_config->FindI("quiet",0) < 2 &&
301  _config->FindB("APT::Get::Assume-Yes",false) == false)
302  {
303  if (YnPrompt(_("Do you want to continue?")) == false)
304  {
305  c2out << _("Abort.") << std::endl;
306  exit(1);
307  }
308  }
309  }
310  }
311 
312  if (!CheckAuth(Fetcher, true))
313  return false;
314 
315  /* Unlock the dpkg lock if we are not going to be doing an install
316  after. */
317  if (_config->FindB("APT::Get::Download-Only",false) == true)
318  _system->UnLock();
319 
320  // Run it
321  bool Failed = false;
322  while (1)
323  {
324  bool Transient = false;
325  if (AcquireRun(Fetcher, 0, &Failed, &Transient) == false)
326  return false;
327 
328  if (_config->FindB("APT::Get::Download-Only",false) == true)
329  {
330  if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false)
331  return _error->Error(_("Some files failed to download"));
332  c1out << _("Download complete and in download only mode") << std::endl;
333  return true;
334  }
335 
336  if (Failed == true && _config->FindB("APT::Get::Fix-Missing",false) == false)
337  return _error->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
338 
339  if (Transient == true && Failed == true)
340  return _error->Error(_("--fix-missing and media swapping is not currently supported"));
341 
342  // Try to deal with missing package files
343  if (Failed == true && PM->FixMissing() == false)
344  {
345  c2out << _("Unable to correct missing packages.") << std::endl;
346  return _error->Error(_("Aborting install."));
347  }
348 
349  auto const progress = APT::Progress::PackageManagerProgressFactory();
350  _system->UnLockInner();
351  pkgPackageManager::OrderResult const Res = PM->DoInstall(progress);
352  delete progress;
353 
354  if (Res == pkgPackageManager::Failed || _error->PendingError() == true)
355  return false;
356  if (Res == pkgPackageManager::Completed)
357  break;
358 
359  _system->LockInner();
360 
361  // Reload the fetcher object and loop again for media swapping
362  Fetcher.Shutdown();
363  if (PM->GetArchives(&Fetcher,List,&Recs) == false)
364  return false;
365 
366  Failed = false;
367  if (DownloadAllowed == false)
368  RemoveDownloadNeedingItemsFromFetcher(Fetcher, Failed);
369  }
370 
371  std::set<std::string> const disappearedPkgs = PM->GetDisappearedPackages();
372  if (disappearedPkgs.empty() == false)
373  {
374  ShowList(c1out, P_("The following package disappeared from your system as\n"
375  "all files have been overwritten by other packages:",
376  "The following packages disappeared from your system as\n"
377  "all files have been overwritten by other packages:", disappearedPkgs.size()), disappearedPkgs,
378  [](std::string const &Pkg) { return Pkg.empty() == false; },
379  [](std::string const &Pkg) { return Pkg; },
380  [](std::string const &) { return std::string(); });
381  c0out << _("Note: This is done automatically and on purpose by dpkg.") << std::endl;
382  }
383 
384  // cleanup downloaded debs
385  if (_config->FindB("APT::Keep-Downloaded-Packages", true) == false)
386  {
387  std::string const archivedir = _config->FindDir("Dir::Cache::archives");
388  for (auto I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
389  {
390  if (flNotFile((*I)->DestFile) != archivedir || (*I)->Local)
391  continue;
392  RemoveFile("Keep-Downloaded-Packages=false", (*I)->DestFile);
393  }
394  }
395 
396  if (not RunScripts("APT::Install::Post-Invoke-Success"))
397  return false;
398 
399  return true;
400 }
401  /*}}}*/
402 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
403 // ---------------------------------------------------------------------
404 /* Remove unused automatic packages */
406 {
407  bool Debug = _config->FindB("Debug::pkgAutoRemove",false);
408  bool doAutoRemove = _config->FindB("APT::Get::AutomaticRemove", false);
409  bool doAutoRemoveKernels = _config->FindB("APT::Get::AutomaticRemove::Kernels", false);
410  bool hideAutoRemove = _config->FindB("APT::Get::HideAutoRemove");
411 
412  std::unique_ptr<APT::CacheFilter::Matcher> kernelAutoremovalMatcher;
413  if (doAutoRemoveKernels && !doAutoRemove)
414  {
415  kernelAutoremovalMatcher = APT::KernelAutoRemoveHelper::GetProtectedKernelsFilter(Cache, true);
416  }
417 
418  pkgDepCache::ActionGroup group(*Cache);
419  if(Debug)
420  std::cout << "DoAutomaticRemove()" << std::endl;
421 
422  if (doAutoRemove == true &&
423  _config->FindB("APT::Get::Remove",true) == false)
424  {
425  c1out << _("We are not supposed to delete stuff, can't start "
426  "AutoRemover") << std::endl;
427  return false;
428  }
429 
430  bool purgePkgs = _config->FindB("APT::Get::Purge", false);
431  bool smallList = (hideAutoRemove == false &&
432  strcasecmp(_config->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
433 
434  unsigned long autoRemoveCount = 0;
435  APT::PackageSet tooMuch;
436  SortedPackageUniverse Universe(Cache);
437  // look over the cache to see what can be removed
438  for (auto const &Pkg: Universe)
439  {
440  if (Cache[Pkg].Garbage)
441  {
442  if(Pkg.CurrentVer() != 0 || Cache[Pkg].Install())
443  if(Debug)
444  std::cout << "We could delete " << APT::PrettyPkg(Cache, Pkg) << std::endl;
445 
446  if (doAutoRemove || (kernelAutoremovalMatcher != nullptr && (*kernelAutoremovalMatcher)(Pkg)))
447  {
448  if(Pkg.CurrentVer() != 0 &&
449  Pkg->CurrentState != pkgCache::State::ConfigFiles)
450  Cache->MarkDelete(Pkg, purgePkgs, 0, false);
451  else
452  Cache->MarkKeep(Pkg, false, false);
453  }
454  else
455  {
456  // if the package is a new install and already garbage we don't need to
457  // install it in the first place, so nuke it instead of show it
458  if (Cache[Pkg].Install() == true && Pkg.CurrentVer() == 0)
459  {
460  tooMuch.insert(Pkg);
461  Cache->MarkDelete(Pkg, false, 0, false);
462  }
463  // only show stuff in the list that is not yet marked for removal
464  else if(hideAutoRemove == false && Cache[Pkg].Delete() == false)
465  ++autoRemoveCount;
466  }
467  }
468  }
469 
470  // we could have removed a new dependency of a garbage package,
471  // so check if a reverse depends is broken and if so install it again.
472  if (tooMuch.empty() == false && (Cache->BrokenCount() != 0 || Cache->PolicyBrokenCount() != 0))
473  {
474  bool Changed;
475  do {
476  Changed = false;
477  for (APT::PackageSet::iterator Pkg = tooMuch.begin();
478  Pkg != tooMuch.end(); ++Pkg)
479  {
480  APT::PackageSet too;
481  too.insert(*Pkg);
482  for (pkgCache::PrvIterator Prv = Cache[Pkg].CandidateVerIter(Cache).ProvidesList();
483  Prv.end() == false; ++Prv)
484  too.insert(Prv.ParentPkg());
485  for (APT::PackageSet::const_iterator P = too.begin(); P != too.end(); ++P)
486  {
487  for (pkgCache::DepIterator R = P.RevDependsList();
488  R.end() == false; ++R)
489  {
490  if (R.IsNegative() == true ||
491  Cache->IsImportantDep(R) == false)
492  continue;
493  auto const RV = R.ParentVer();
494  if (unlikely(RV.end() == true))
495  continue;
496  auto const RP = RV.ParentPkg();
497  // check if that dependency comes from an interesting version
498  if (RP.CurrentVer() == RV)
499  {
500  if ((*Cache)[RP].Keep() == false)
501  continue;
502  }
503  else if (Cache[RP].CandidateVerIter(Cache) == RV)
504  {
505  if ((*Cache)[RP].NewInstall() == false && (*Cache)[RP].Upgrade() == false)
506  continue;
507  }
508  else // ignore dependency from a non-candidate version
509  continue;
510  if (Debug == true)
511  std::clog << "Save " << APT::PrettyPkg(Cache, Pkg) << " as another installed package depends on it: " << APT::PrettyPkg(Cache, RP) << std::endl;
512  Cache->MarkInstall(Pkg, false, 0, false);
513  if (hideAutoRemove == false)
514  ++autoRemoveCount;
515  tooMuch.erase(Pkg);
516  Changed = true;
517  break;
518  }
519  if (Changed == true)
520  break;
521  }
522  if (Changed == true)
523  break;
524  }
525  } while (Changed == true);
526  }
527  // trigger marking now so that the package list below is correct
528  group.release();
529 
530  // Now see if we had destroyed anything (if we had done anything)
531  if (Cache->BrokenCount() != 0)
532  {
533  c1out << _("Hmm, seems like the AutoRemover destroyed something which really\n"
534  "shouldn't happen. Please file a bug report against apt.") << std::endl;
535  c1out << std::endl;
536  c1out << _("The following information may help to resolve the situation:") << std::endl;
537  c1out << std::endl;
538  ShowBroken(c1out,Cache,false);
539 
540  return _error->Error(_("Internal Error, AutoRemover broke stuff"));
541  }
542 
543  // if we don't remove them, we should show them!
544  if (doAutoRemove == false && autoRemoveCount != 0)
545  {
546  if (smallList == false)
547  {
548  SortedPackageUniverse Universe(Cache);
549  ShowList(c1out, P_("The following package was automatically installed and is no longer required:",
550  "The following packages were automatically installed and are no longer required:",
551  autoRemoveCount), Universe,
552  [&Cache](pkgCache::PkgIterator const &Pkg) { return (*Cache)[Pkg].Garbage == true && (*Cache)[Pkg].Delete() == false; },
553  &PrettyFullName, CandidateVersion(&Cache));
554  }
555  else
556  ioprintf(c1out, P_("%lu package was automatically installed and is no longer required.\n",
557  "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount), autoRemoveCount);
558  std::string autocmd = "apt autoremove";
559  if (getenv("SUDO_USER") != nullptr)
560  {
561  auto const envsudocmd = getenv("SUDO_COMMAND");
562  auto const envshell = getenv("SHELL");
563  if (envsudocmd == nullptr || envshell == nullptr || strcmp(envsudocmd, envshell) != 0)
564  autocmd = "sudo " + autocmd;
565  }
566  ioprintf(c1out, P_("Use '%s' to remove it.", "Use '%s' to remove them.", autoRemoveCount), autocmd.c_str());
567  c1out << std::endl;
568  }
569  return true;
570 }
571  /*}}}*/
572 // DoCacheManipulationFromCommandLine /*{{{*/
573 static const unsigned short MOD_REMOVE = 1;
574 static const unsigned short MOD_INSTALL = 2;
575 
577 {
578  std::vector<PseudoPkg> VolatileCmdL;
579  return DoCacheManipulationFromCommandLine(CmdL, VolatileCmdL, Cache, UpgradeMode);
580 }
581 bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg> &VolatileCmdL, CacheFile &Cache, int UpgradeMode)
582 {
583  std::map<unsigned short, APT::VersionSet> verset;
584  std::set<std::string> UnknownPackages;
585  return DoCacheManipulationFromCommandLine(CmdL, VolatileCmdL, Cache, verset, UpgradeMode, UnknownPackages);
586 }
587 bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg> &VolatileCmdL, CacheFile &Cache,
588  std::map<unsigned short, APT::VersionSet> &verset, int UpgradeMode, std::set<std::string> &UnknownPackages)
589 {
590  // Enter the special broken fixing mode if the user specified arguments
591  bool BrokenFix = false;
592  if (Cache->BrokenCount() != 0)
593  BrokenFix = true;
594 
595  std::unique_ptr<pkgProblemResolver> Fix(nullptr);
596  if (_config->FindB("APT::Get::CallResolver", true) == true)
597  Fix.reset(new pkgProblemResolver(Cache));
598 
599  unsigned short fallback = MOD_INSTALL;
600  if (strcasecmp(CmdL.FileList[0], "reinstall") == 0)
601  _config->Set("APT::Get::ReInstall", "true");
602  else if (strcasecmp(CmdL.FileList[0],"remove") == 0)
603  fallback = MOD_REMOVE;
604  else if (strcasecmp(CmdL.FileList[0], "purge") == 0)
605  {
606  _config->Set("APT::Get::Purge", true);
607  fallback = MOD_REMOVE;
608  }
609  else if (strcasecmp(CmdL.FileList[0], "autoremove") == 0 ||
610  strcasecmp(CmdL.FileList[0], "auto-remove") == 0)
611  {
612  _config->Set("APT::Get::AutomaticRemove", "true");
613  fallback = MOD_REMOVE;
614  }
615  else if (strcasecmp(CmdL.FileList[0], "autopurge") == 0)
616  {
617  _config->Set("APT::Get::AutomaticRemove", "true");
618  _config->Set("APT::Get::Purge", true);
619  fallback = MOD_REMOVE;
620  }
621 
622  std::list<APT::VersionSet::Modifier> mods;
623  mods.push_back(APT::VersionSet::Modifier(MOD_INSTALL, "+",
625  mods.push_back(APT::VersionSet::Modifier(MOD_REMOVE, "-",
627  CacheSetHelperAPTGet helper(c0out);
629  CmdL.FileList + 1, mods, fallback, helper);
630 
631  for (auto const &I: VolatileCmdL)
632  {
633  pkgCache::PkgIterator const P = Cache->FindPkg(I.name);
634  if (P.end())
635  continue;
636 
637  // Set any version providing the .deb as the candidate.
638  for (auto Prv = P.ProvidesList(); Prv.end() == false; Prv++)
639  {
640  if (I.release.empty())
641  Cache.GetDepCache()->SetCandidateVersion(Prv.OwnerVer());
642  else
643  Cache.GetDepCache()->SetCandidateRelease(Prv.OwnerVer(), I.release);
644  }
645 
646  // via cacheset to have our usual virtual handling
648  }
649 
650  UnknownPackages = helper.notFound;
651 
652  if (_error->PendingError() == true)
653  {
654  helper.showVirtualPackageErrors(Cache);
655  return false;
656  }
657 
658 
659  TryToInstall InstallAction(Cache, Fix.get(), BrokenFix);
660  TryToRemove RemoveAction(Cache, Fix.get());
661 
662  // new scope for the ActionGroup
663  {
664  pkgDepCache::ActionGroup group(Cache);
665  unsigned short const order[] = { MOD_REMOVE, MOD_INSTALL, 0 };
666 
667  for (unsigned short i = 0; order[i] != 0; ++i)
668  {
669  if (order[i] == MOD_INSTALL)
670  InstallAction = std::for_each(verset[MOD_INSTALL].begin(), verset[MOD_INSTALL].end(), InstallAction);
671  else if (order[i] == MOD_REMOVE)
672  RemoveAction = std::for_each(verset[MOD_REMOVE].begin(), verset[MOD_REMOVE].end(), RemoveAction);
673  }
674 
675  if (Fix != NULL && _config->FindB("APT::Get::AutoSolving", true) == true)
676  {
678  InstallAction.doAutoInstall();
679  }
680 
681  if (_error->PendingError() == true)
682  {
683  return false;
684  }
685 
686  /* If we are in the Broken fixing mode we do not attempt to fix the
687  problems. This is if the user invoked install without -f and gave
688  packages */
689  if (BrokenFix == true && Cache->BrokenCount() != 0)
690  {
691  c1out << _("You might want to run 'apt --fix-broken install' to correct these.") << std::endl;
692  ShowBroken(c1out,Cache,false);
693  return _error->Error(_("Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution)."));
694  }
695 
696  if (Fix != NULL)
697  {
698  // Call the scored problem resolver
699  OpTextProgress Progress(*_config);
700  bool const distUpgradeMode = strcmp(CmdL.FileList[0], "dist-upgrade") == 0 || strcmp(CmdL.FileList[0], "full-upgrade") == 0;
701 
702  if (distUpgradeMode && _config->Find("Binary") == "apt")
703  _config->CndSet("APT::Get::AutomaticRemove::Kernels", _config->FindB("APT::Get::AutomaticRemove", true));
704 
705  bool resolver_fail = false;
706  if (distUpgradeMode == true || UpgradeMode != APT::Upgrade::ALLOW_EVERYTHING)
707  resolver_fail = APT::Upgrade::Upgrade(Cache, UpgradeMode, &Progress);
708  else
709  resolver_fail = Fix->Resolve(true, &Progress);
710 
711  if (resolver_fail == false && Cache->BrokenCount() == 0)
712  return false;
713  }
714 
715  if (CheckNothingBroken(Cache) == false)
716  return false;
717  }
718  if (!DoAutomaticRemove(Cache))
719  return false;
720 
721  // if nothing changed in the cache, but only the automark information
722  // we write the StateFile here, otherwise it will be written in
723  // cache.commit()
724  if (InstallAction.AutoMarkChanged > 0 &&
725  Cache->DelCount() == 0 && Cache->InstCount() == 0 &&
726  Cache->BadCount() == 0 &&
727  _config->FindB("APT::Get::Simulate",false) == false)
728  Cache->writeStateFile(NULL);
729 
730  return true;
731 }
732  /*}}}*/
733 bool AddVolatileSourceFile(pkgSourceList *const SL, PseudoPkg &&pkg, std::vector<PseudoPkg> &VolatileCmdL)/*{{{*/
734 {
735  auto const ext = flExtension(pkg.name);
736  if (ext != "dsc" && FileExists(pkg.name + "/debian/control") == false)
737  return false;
738  std::vector<std::string> files;
739  SL->AddVolatileFile(pkg.name, &files);
740  std::transform(files.begin(), files.end(), std::back_inserter(VolatileCmdL), [&](auto &&f) { return PseudoPkg{std::move(f), pkg.arch, pkg.release, pkg.index}; });
741  return true;
742 
743 }
744  /*}}}*/
745 bool AddVolatileBinaryFile(pkgSourceList *const SL, PseudoPkg &&pkg, std::vector<PseudoPkg> &VolatileCmdL)/*{{{*/
746 {
747  auto const ext = flExtension(pkg.name);
748  if (ext != "deb" && ext != "ddeb" && ext != "changes")
749  return false;
750  std::vector<std::string> files;
751  SL->AddVolatileFile(pkg.name, &files);
752  std::transform(files.begin(), files.end(), std::back_inserter(VolatileCmdL), [&](auto &&f) { return PseudoPkg{std::move(f), pkg.arch, pkg.release, pkg.index}; });
753  return true;
754 }
755  /*}}}*/
756 static bool AddIfVolatile(pkgSourceList *const SL, std::vector<PseudoPkg> &VolatileCmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector<PseudoPkg> &), char const * const I, std::string const &pseudoArch)/*{{{*/
757 {
758  if (I != nullptr && (I[0] == '/' || (I[0] == '.' && (I[1] == '\0' || (I[1] == '.' && (I[2] == '\0' || I[2] == '/')) || I[1] == '/'))))
759  {
760  PseudoPkg pkg(I, pseudoArch, "", SL->GetVolatileFiles().size());
761  if (FileExists(I)) // this accepts directories and symlinks, too
762  {
763  if (Add(SL, std::move(pkg), VolatileCmdL))
764  ;
765  else
766  _error->Error(_("Unsupported file %s given on commandline"), I);
767  return true;
768  }
769  else
770  {
771  auto const found = pkg.name.rfind("/");
772  if (found == pkg.name.find("/"))
773  _error->Error(_("Unsupported file %s given on commandline"), I);
774  else
775  {
776  pkg.release = pkg.name.substr(found + 1);
777  pkg.name.erase(found);
778  if (Add(SL, std::move(pkg), VolatileCmdL))
779  ;
780  else
781  _error->Error(_("Unsupported file %s given on commandline"), I);
782  }
783  return true;
784  }
785  }
786  return false;
787 }
788  /*}}}*/
789 std::vector<PseudoPkg> GetAllPackagesAsPseudo(pkgSourceList *const SL, CommandLine &CmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector<PseudoPkg> &), std::string const &pseudoArch)/*{{{*/
790 {
791  std::vector<PseudoPkg> PkgCmdL;
792  std::for_each(CmdL.FileList + 1, CmdL.FileList + CmdL.FileSize(), [&](char const *const I) {
793  if (AddIfVolatile(SL, PkgCmdL, Add, I, pseudoArch) == false)
794  PkgCmdL.emplace_back(I, pseudoArch, "", -1);
795  });
796  return PkgCmdL;
797 }
798  /*}}}*/
799 std::vector<PseudoPkg> GetPseudoPackages(pkgSourceList *const SL, CommandLine &CmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector<PseudoPkg> &), std::string const &pseudoArch)/*{{{*/
800 {
801  std::vector<PseudoPkg> VolatileCmdL;
802  std::remove_if(CmdL.FileList + 1, CmdL.FileList + 1 + CmdL.FileSize(), [&](char const *const I) {
803  return AddIfVolatile(SL, VolatileCmdL, Add, I, pseudoArch);
804  });
805  return VolatileCmdL;
806 }
807  /*}}}*/
808 // DoInstall - Install packages from the command line /*{{{*/
809 // ---------------------------------------------------------------------
810 /* Install named packages */
813  APT::VersionSet const * const verset;
814  PkgIsExtraInstalled(pkgCacheFile * const Cache, APT::VersionSet const * const Container) : Cache(Cache), verset(Container) {}
816  {
817  if ((*Cache)[Pkg].Install() == false)
818  return false;
819  pkgCache::VerIterator const Cand = (*Cache)[Pkg].CandidateVerIter(*Cache);
820  return verset->find(Cand) == verset->end();
821  }
822 };
824 {
825  CacheFile Cache;
826  auto VolatileCmdL = GetPseudoPackages(Cache.GetSourceList(), CmdL, AddVolatileBinaryFile, "");
827 
828  // then open the cache
829  if (Cache.OpenForInstall() == false ||
830  Cache.CheckDeps(CmdL.FileSize() != 1) == false)
831  return false;
832 
833  std::map<unsigned short, APT::VersionSet> verset;
834  std::set<std::string> UnknownPackages;
835 
836  if (!DoCacheManipulationFromCommandLine(CmdL, VolatileCmdL, Cache, verset, 0, UnknownPackages))
837  {
838  RunJsonHook("AptCli::Hooks::Install", "org.debian.apt.hooks.install.fail", CmdL.FileList, Cache, UnknownPackages);
839  return false;
840  }
841 
842  /* Print out a list of packages that are going to be installed extra
843  to what the user asked */
844  SortedPackageUniverse Universe(Cache);
845  if (Cache->InstCount() != verset[MOD_INSTALL].size())
846  ShowList(c1out, _("The following additional packages will be installed:"), Universe,
847  PkgIsExtraInstalled(&Cache, &verset[MOD_INSTALL]),
848  &PrettyFullName, CandidateVersion(&Cache));
849 
850  /* Print out a list of suggested and recommended packages */
851  {
852  std::list<std::string> Recommends, Suggests, SingleRecommends, SingleSuggests;
853  for (auto const &Pkg: Universe)
854  {
855  /* Just look at the ones we want to install */
856  if ((*Cache)[Pkg].Install() == false)
857  continue;
858 
859  // get the recommends/suggests for the candidate ver
860  pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache);
861  for (pkgCache::DepIterator D = CV.DependsList(); D.end() == false; )
862  {
863  pkgCache::DepIterator Start;
865  D.GlobOr(Start,End); // advances D
866  if (Start->Type != pkgCache::Dep::Recommends && Start->Type != pkgCache::Dep::Suggests)
867  continue;
868 
869  {
870  // Skip if we already saw this
871  std::string target;
872  for (pkgCache::DepIterator I = Start; I != D; ++I)
873  {
874  if (target.empty() == false)
875  target.append(" | ");
876  target.append(I.TargetPkg().FullName(true));
877  }
878  std::list<std::string> &Type = Start->Type == pkgCache::Dep::Recommends ? SingleRecommends : SingleSuggests;
879  if (std::find(Type.begin(), Type.end(), target) != Type.end())
880  continue;
881  Type.push_back(target);
882  }
883 
884  std::list<std::string> OrList;
885  bool foundInstalledInOrGroup = false;
886  for (pkgCache::DepIterator I = Start; I != D; ++I)
887  {
888  {
889  // satisfying package is installed and not marked for deletion
891  if (std::find_if(installed.begin(), installed.end(),
892  [&Cache](pkgCache::VerIterator const &Ver) { return Cache[Ver.ParentPkg()].Delete() == false; }) != installed.end())
893  {
894  foundInstalledInOrGroup = true;
895  break;
896  }
897  }
898 
899  {
900  // satisfying package is upgraded to/new install
902  if (std::find_if(upgrades.begin(), upgrades.end(),
903  [&Cache](pkgCache::VerIterator const &Ver) { return Cache[Ver.ParentPkg()].Upgrade(); }) != upgrades.end())
904  {
905  foundInstalledInOrGroup = true;
906  break;
907  }
908  }
909 
910  if (OrList.empty())
911  OrList.push_back(I.TargetPkg().FullName(true));
912  else
913  OrList.push_back("| " + I.TargetPkg().FullName(true));
914  }
915 
916  if(foundInstalledInOrGroup == false)
917  {
918  std::list<std::string> &Type = Start->Type == pkgCache::Dep::Recommends ? Recommends : Suggests;
919  std::move(OrList.begin(), OrList.end(), std::back_inserter(Type));
920  }
921  }
922  }
923  auto always_true = [](std::string const&) { return true; };
924  auto string_ident = [](std::string const&str) { return str; };
925  auto verbose_show_candidate =
926  [&Cache](std::string str)
927  {
928  if (APT::String::Startswith(str, "| "))
929  str.erase(0, 2);
930  pkgCache::PkgIterator const Pkg = Cache->FindPkg(str);
931  if (Pkg.end() == true)
932  return "";
933  return (*Cache)[Pkg].CandVersion;
934  };
935  ShowList(c1out,_("Suggested packages:"), Suggests,
936  always_true, string_ident, verbose_show_candidate);
937  ShowList(c1out,_("Recommended packages:"), Recommends,
938  always_true, string_ident, verbose_show_candidate);
939  }
940 
941  RunJsonHook("AptCli::Hooks::Install", "org.debian.apt.hooks.install.pre-prompt", CmdL.FileList, Cache);
942 
943  bool result;
944  // See if we need to prompt
945  // FIXME: check if really the packages in the set are going to be installed
946  if (Cache->InstCount() == verset[MOD_INSTALL].size() && Cache->DelCount() == 0)
947  result = InstallPackages(Cache, false, false);
948  else
949  result = InstallPackages(Cache, false);
950 
951  if (result)
952  result = RunJsonHook("AptCli::Hooks::Install", "org.debian.apt.hooks.install.post", CmdL.FileList, Cache);
953  else
954  /* not a result */ RunJsonHook("AptCli::Hooks::Install", "org.debian.apt.hooks.install.fail", CmdL.FileList, Cache);
955 
956  return result;
957 }
958  /*}}}*/
959 
960 // TryToInstall - Mark a package for installation /*{{{*/
962  if (unlikely(Ver.end()))
963  {
964  _error->Fatal("The given version to TryToInstall is invalid!");
965  return;
966  }
967  pkgCache::PkgIterator Pkg = Ver.ParentPkg();
968  if (unlikely(Pkg.end()))
969  {
970  _error->Fatal("The given version to TryToInstall has an invalid parent package!");
971  return;
972  }
973 
974  Cache->GetDepCache()->SetCandidateVersion(Ver);
975  pkgDepCache::StateCache &State = (*Cache)[Pkg];
976 
977  // Handle the no-upgrade case
978  if (_config->FindB("APT::Get::upgrade",true) == false && Pkg->CurrentVer != 0)
979  ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"),
980  Pkg.FullName(true).c_str());
981  // Ignore request for install if package would be new
982  else if (_config->FindB("APT::Get::Only-Upgrade", false) == true && Pkg->CurrentVer == 0)
983  ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
984  Pkg.FullName(true).c_str());
985  else {
986  if (Fix != NULL) {
987  Fix->Clear(Pkg);
988  Fix->Protect(Pkg);
989  }
990  Cache->GetDepCache()->MarkInstall(Pkg,false);
991 
992  if (State.Install() == false) {
993  if (_config->FindB("APT::Get::ReInstall",false) == true) {
994  if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false)
995  ioprintf(c1out,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
996  Pkg.FullName(true).c_str());
997  else
998  Cache->GetDepCache()->SetReInstall(Pkg, true);
999  } else
1000  // TRANSLATORS: First string is package name, second is version
1001  ioprintf(c1out,_("%s is already the newest version (%s).\n"),
1002  Pkg.FullName(true).c_str(), Pkg.CurrentVer().VerStr());
1003  }
1004 
1005  // Install it with autoinstalling enabled (if we not respect the minial
1006  // required deps or the policy)
1007  if (FixBroken == false)
1009  }
1010 
1011  // see if we need to fix the auto-mark flag
1012  // e.g. apt-get install foo
1013  // where foo is marked automatic
1014  if (State.Install() == false &&
1015  (State.Flags & pkgCache::Flag::Auto) &&
1016  _config->FindB("APT::Get::ReInstall",false) == false &&
1017  _config->FindB("APT::Get::Only-Upgrade",false) == false &&
1018  _config->FindB("APT::Get::Download-Only",false) == false)
1019  {
1020  ioprintf(c1out,_("%s set to manually installed.\n"),
1021  Pkg.FullName(true).c_str());
1022  Cache->GetDepCache()->MarkAuto(Pkg,false);
1023  AutoMarkChanged++;
1024  }
1025 }
1026  /*}}}*/
1027 bool TryToInstall::propergateReleaseCandiateSwitching(std::list<std::pair<pkgCache::VerIterator, std::string> > const &start, std::ostream &out)/*{{{*/
1028 {
1029  for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
1030  s != start.end(); ++s)
1031  Cache->GetDepCache()->SetCandidateVersion(s->first);
1032 
1033  bool Success = true;
1034  // the Changed list contains:
1035  // first: "new version"
1036  // second: "what-caused the change"
1037  std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > Changed;
1038  for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
1039  s != start.end(); ++s)
1040  {
1041  Changed.push_back(std::make_pair(s->first, pkgCache::VerIterator(*Cache)));
1042  // We continue here even if it failed to enhance the ShowBroken output
1043  Success &= Cache->GetDepCache()->SetCandidateRelease(s->first, s->second, Changed);
1044  }
1045  for (std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::const_iterator c = Changed.begin();
1046  c != Changed.end(); ++c)
1047  {
1048  if (c->second.end() == true)
1049  {
1050  auto const pkgname = c->first.ParentPkg().FullName(true);
1051  if (APT::String::Startswith(pkgname, "builddeps:"))
1052  continue;
1053  ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"),
1054  c->first.VerStr(), c->first.RelStr().c_str(), pkgname.c_str());
1055  }
1056  else if (c->first.ParentPkg()->Group != c->second.ParentPkg()->Group)
1057  {
1058  auto pkgname = c->second.ParentPkg().FullName(true);
1059  if (APT::String::Startswith(pkgname, "builddeps:"))
1060  pkgname.replace(0, strlen("builddeps"), "src");
1061  pkgCache::VerIterator V = (*Cache)[c->first.ParentPkg()].CandidateVerIter(*Cache);
1062  ioprintf(out, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V.VerStr(),
1063  V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), pkgname.c_str());
1064  }
1065  }
1066  return Success;
1067 }
1068  /*}}}*/
1071  P != doAutoInstallLater.end(); ++P) {
1072  pkgDepCache::StateCache &State = (*Cache)[P];
1073  if (State.InstBroken() == false && State.InstPolicyBroken() == false)
1074  continue;
1075  Cache->GetDepCache()->MarkInstall(P, true);
1076  }
1078 }
1079  /*}}}*/
1080 // TryToRemove - Mark a package for removal /*{{{*/
1082 {
1083  pkgCache::PkgIterator Pkg = Ver.ParentPkg();
1084 
1085  if (Fix != NULL)
1086  {
1087  Fix->Clear(Pkg);
1088  Fix->Protect(Pkg);
1089  Fix->Remove(Pkg);
1090  }
1091 
1092  if ((Pkg->CurrentVer == 0 && PurgePkgs == false) ||
1093  (PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled))
1094  {
1095  pkgCache::GrpIterator Grp = Pkg.Group();
1096  pkgCache::PkgIterator P = Grp.PackageList();
1097  for (; P.end() != true; P = Grp.NextPkg(P))
1098  {
1099  if (P == Pkg)
1100  continue;
1101  if (P->CurrentVer != 0 || (PurgePkgs == true && P->CurrentState != pkgCache::State::NotInstalled))
1102  {
1103  // TRANSLATORS: Note, this is not an interactive question
1104  ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
1105  Pkg.FullName(true).c_str(), P.FullName(true).c_str());
1106  break;
1107  }
1108  }
1109  if (P.end() == true)
1110  ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str());
1111 
1112  // MarkInstall refuses to install packages on hold
1113  Pkg->SelectedState = pkgCache::State::Hold;
1114  }
1115  else
1116  Cache->GetDepCache()->MarkDelete(Pkg, PurgePkgs);
1117 }
1118  /*}}}*/
strprintf(m, msg, repo.c_str())
static bool std::string const metaIndex const *const pkgAcqMetaClearSig *const pkgAcquire::Item *const I
bool empty() const APT_OVERRIDE
Definition: cacheset.h:361
const_iterator begin() const
Definition: cacheset.h:371
void clear() APT_OVERRIDE
Definition: cacheset.h:362
bool insert(pkgCache::PkgIterator const &P) APT_OVERRIDE
Definition: cacheset.h:357
const_iterator end() const
Definition: cacheset.h:372
iterator erase(iterator pos)
Definition: cacheset.h:368
virtual void Error(std::string, unsigned int, unsigned int, std::string)
static bool FromPackage(VersionContainerInterface *const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper)
Definition: cacheset.cc:516
const_iterator begin() const
Definition: cacheset.h:825
static std::map< unsigned short, VersionContainer > GroupedFromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::list< Modifier > const &mods, unsigned short const fallback, CacheSetHelper &helper)
Definition: cacheset.h:922
static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, CacheSetHelper::VerSelector const selector, CacheSetHelper &helper)
Definition: cacheset.h:947
const_iterator find(pkgCache::VerIterator const &V) const
Definition: cacheset.h:839
const_iterator end() const
Definition: cacheset.h:826
bool OpenForInstall()
bool CheckDeps(bool AllowBroken=false)
std::set< std::string > notFound
bool showVirtualPackageErrors(pkgCacheFile &Cache)
std::list< std::pair< pkgCache::VerIterator, std::string > > selectedByRelease
const char ** FileList
Definition: cmndline.h:78
unsigned int FileSize() const APT_PURE
Definition: cmndline.cc:353
int FindI(const char *Name, int const &Default=0) const
void Set(const std::string &Name, const std::string &Value)
Definition: configuration.h:92
std::string Find(const char *Name, const char *Default=0) const
bool FindB(const char *Name, bool const &Default=false) const
std::string FindDir(const char *Name, const char *Default=0) const
void CndSet(const char *Name, const std::string &Value)
std::string URI
Definition: metaindex.h:39
Represents the process by which a pkgAcquire object should retrieve a file or a collection of files.
Definition: acquire-item.h:59
UriIterator UriBegin()
Get the head of the list of enqueued item URIs.
Definition: acquire.cc:872
ItemIterator ItemsEnd()
Get the end iterator of the list of items.
Definition: acquire.h:305
unsigned long long FetchNeeded()
Definition: acquire.cc:844
unsigned long long TotalNeeded()
Definition: acquire.cc:833
UriIterator UriEnd()
Get the end iterator of the list of enqueued item URIs.
Definition: acquire.cc:880
bool GetLock(std::string const &Lock)
acquire lock and perform directory setup
Definition: acquire.cc:136
void Shutdown()
Remove all items from this download process, terminate all download workers, and empty all queues.
Definition: acquire.cc:197
std::vector< Item * >::iterator ItemIterator
Definition: acquire.h:111
UriIterator(pkgAcquire::Queue *Q)
Create a new UriIterator.
ItemIterator ItemsBegin()
Get the head of the list of items.
Definition: acquire.h:301
unsigned long long PartialPresent()
Definition: acquire.cc:858
pkgDepCache * GetDepCache()
Definition: cachefile.h:74
bool BuildSourceList(OpProgress *Progress=NULL)
Definition: cachefile.cc:151
pkgSourceList * GetSourceList()
Definition: cachefile.h:76
Represents an active action group.
Definition: depcache.h:166
void release()
Clean up the action group before it is destroyed.
Definition: depcache.cc:90
void SetReInstall(PkgIterator const &Pkg, bool To)
Definition: depcache.cc:1826
void MarkAuto(const PkgIterator &Pkg, bool Auto)
Definition: depcache.cc:2066
void SetCandidateVersion(VerIterator TargetVer)
Definition: depcache.cc:1871
bool MarkInstall(PkgIterator const &Pkg, bool AutoInst=true, unsigned long Depth=0, bool FromUser=true, bool ForceImportantDeps=false)
Definition: depcache.cc:1560
bool SetCandidateRelease(pkgCache::VerIterator TargetVer, std::string const &TargetRel)
Definition: depcache.cc:1900
bool MarkDelete(PkgIterator const &Pkg, bool MarkPurge=false, unsigned long Depth=0, bool FromUser=true)
Definition: depcache.cc:991
OrderResult DoInstall(APT::Progress::PackageManager *progress)
void Clear(pkgCache::PkgIterator Pkg)
Definition: algorithms.h:132
void Remove(pkgCache::PkgIterator Pkg)
Definition: algorithms.h:131
void Protect(pkgCache::PkgIterator Pkg)
Definition: algorithms.h:130
std::vector< pkgIndexFile * > GetVolatileFiles() const
Definition: sourcelist.cc:530
const_iterator begin() const
Definition: sourcelist.h:97
const_iterator end() const
Definition: sourcelist.h:98
void AddVolatileFile(pkgIndexFile *const File)
add file for parsing, but not to the cache
Definition: sourcelist.cc:535
virtual pkgPackageManager * CreatePM(pkgDepCache *Cache) const =0
virtual bool UnLock(bool NoErrors=false)=0
virtual bool LockInner(OpProgress *const Progress=0, int timeOutSec=0)=0
virtual bool UnLockInner(bool NoErrors=false)=0
Configuration * _config
static int order(char c)
Definition: debversion.cc:39
string flNotFile(string File)
Definition: fileutl.cc:676
string flExtension(string File)
Definition: fileutl.cc:688
string flNotDir(string File)
Definition: fileutl.cc:664
bool FileExists(string File)
Definition: fileutl.cc:326
bool RemoveFile(char const *const Function, std::string const &FileName)
Definition: fileutl.cc:198
bool RunScripts(const char *Cnf)
Definition: fileutl.cc:91
std::unique_ptr< APT::CacheFilter::Matcher > GetProtectedKernelsFilter(pkgCache *cache, bool returnRemove)
Definition: algorithms.cc:1625
PackageManager * PackageManagerProgressFactory()
bool Startswith(const std::string &s, const std::string &start)
Definition: strutl.cc:84
@ ALLOW_EVERYTHING
Definition: upgrade.h:25
APT_PUBLIC bool Upgrade(pkgDepCache &Cache, int UpgradeMode, OpProgress *const Progress=NULL)
Definition: upgrade.cc:268
pkgCache - Structure definitions for the cache file
pkgSystem * _system
Definition: pkgsystem.cc:24
bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool *const Failure, bool *const TransientNetworkFailure)
bool CheckFreeSpaceBeforeDownload(std::string const &Dir, unsigned long long FetchBytes)
bool CheckAuth(pkgAcquire &Fetcher, bool const PromptUser)
static void RemoveDownloadNeedingItemsFromFetcher(pkgAcquire &Fetcher, bool &Transient)
std::vector< PseudoPkg > GetAllPackagesAsPseudo(pkgSourceList *const SL, CommandLine &CmdL, bool(*Add)(pkgSourceList *const, PseudoPkg &&, std::vector< PseudoPkg > &), std::string const &pseudoArch)
bool AddVolatileSourceFile(pkgSourceList *const SL, PseudoPkg &&pkg, std::vector< PseudoPkg > &VolatileCmdL)
static const unsigned short MOD_REMOVE
bool CheckNothingBroken(CacheFile &Cache)
bool DoAutomaticRemove(CacheFile &Cache)
bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, int UpgradeMode)
bool DoInstall(CommandLine &CmdL)
static bool AddIfVolatile(pkgSourceList *const SL, std::vector< PseudoPkg > &VolatileCmdL, bool(*Add)(pkgSourceList *const, PseudoPkg &&, std::vector< PseudoPkg > &), char const *const I, std::string const &pseudoArch)
bool AddVolatileBinaryFile(pkgSourceList *const SL, PseudoPkg &&pkg, std::vector< PseudoPkg > &VolatileCmdL)
bool InstallPackages(CacheFile &Cache, bool ShwKept, bool Ask, bool Safety)
static const unsigned short MOD_INSTALL
std::vector< PseudoPkg > GetPseudoPackages(pkgSourceList *const SL, CommandLine &CmdL, bool(*Add)(pkgSourceList *const, PseudoPkg &&, std::vector< PseudoPkg > &), std::string const &pseudoArch)
bool RunJsonHook(std::string const &option, std::string const &method, const char **FileList, CacheFile &Cache, std::set< std::string > const &UnknownPackages)
Run the Json hook processes in the given option.
bool ShowHold(ostream &out, CacheFile &Cache)
void Stats(ostream &out, pkgDepCache &Dep)
void ShowNew(ostream &out, CacheFile &Cache)
bool YnPrompt(char const *const Question, bool const Default, bool const ShowGlobalErrors, std::ostream &c1o, std::ostream &c2o)
void ShowKept(ostream &out, CacheFile &Cache)
std::string PrettyFullName(pkgCache::PkgIterator const &Pkg)
void ShowUpgraded(ostream &out, CacheFile &Cache)
std::string CandidateVersion(pkgCacheFile *const Cache, pkgCache::PkgIterator const &Pkg)
void ShowBroken(ostream &out, CacheFile &Cache, bool const Now)
bool AnalPrompt(std::string const &Question, const char *Text)
bool ShowDowngraded(ostream &out, CacheFile &Cache)
bool ShowEssential(ostream &out, CacheFile &Cache)
void ShowDel(ostream &out, CacheFile &Cache)
APT_PUBLIC std::ostream c1out
APT_PUBLIC std::ostream c0out
bool ShowList(std::ostream &out, std::string const &Title, Container const &cont, PredicateC Predicate, DisplayP PkgDisplay, DisplayV VerboseDisplay)
APT_PUBLIC std::ostream c2out
PkgIsExtraInstalled(pkgCacheFile *const Cache, APT::VersionSet const *const Container)
bool operator()(pkgCache::PkgIterator const &Pkg)
APT::VersionSet const *const verset
pkgCacheFile *const Cache
std::string name
std::string release
unsigned long AutoMarkChanged
pkgCacheFile * Cache
APT::PackageSet doAutoInstallLater
pkgProblemResolver * Fix
void operator()(pkgCache::VerIterator const &Ver)
bool propergateReleaseCandiateSwitching(std::list< std::pair< pkgCache::VerIterator, std::string > > const &start, std::ostream &out)
pkgCacheFile * Cache
pkgProblemResolver * Fix
void operator()(pkgCache::VerIterator const &Ver)
bool Install() const
Definition: depcache.h:260
bool InstPolicyBroken() const
Definition: depcache.h:259
unsigned short Flags
Definition: depcache.h:224
bool InstBroken() const
Definition: depcache.h:258
string SizeToStr(double Size)
Definition: strutl.cc:437
void ioprintf(ostream &out, const char *format,...)
Definition: strutl.cc:1433