private-install.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #ifndef APT_PRIVATE_INSTALL_H
  2. #define APT_PRIVATE_INSTALL_H
  3. #include <apt-pkg/cacheset.h>
  4. #include <apt-pkg/cmndline.h>
  5. #include <apt-pkg/strutl.h>
  6. #include "private-cachefile.h"
  7. #include "private-output.h"
  8. #include <apti18n.h>
  9. #define RAMFS_MAGIC 0x858458f6
  10. bool DoInstall(CommandLine &Cmd);
  11. bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
  12. bool Safety = true);
  13. // TryToInstall - Mark a package for installation /*{{{*/
  14. struct TryToInstall {
  15. pkgCacheFile* Cache;
  16. pkgProblemResolver* Fix;
  17. bool FixBroken;
  18. unsigned long AutoMarkChanged;
  19. APT::PackageSet doAutoInstallLater;
  20. TryToInstall(pkgCacheFile &Cache, pkgProblemResolver *PM, bool const FixBroken) : Cache(&Cache), Fix(PM),
  21. FixBroken(FixBroken), AutoMarkChanged(0) {};
  22. void operator() (pkgCache::VerIterator const &Ver) {
  23. pkgCache::PkgIterator Pkg = Ver.ParentPkg();
  24. Cache->GetDepCache()->SetCandidateVersion(Ver);
  25. pkgDepCache::StateCache &State = (*Cache)[Pkg];
  26. // Handle the no-upgrade case
  27. if (_config->FindB("APT::Get::upgrade",true) == false && Pkg->CurrentVer != 0)
  28. ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"),
  29. Pkg.FullName(true).c_str());
  30. // Ignore request for install if package would be new
  31. else if (_config->FindB("APT::Get::Only-Upgrade", false) == true && Pkg->CurrentVer == 0)
  32. ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
  33. Pkg.FullName(true).c_str());
  34. else {
  35. if (Fix != NULL) {
  36. Fix->Clear(Pkg);
  37. Fix->Protect(Pkg);
  38. }
  39. Cache->GetDepCache()->MarkInstall(Pkg,false);
  40. if (State.Install() == false) {
  41. if (_config->FindB("APT::Get::ReInstall",false) == true) {
  42. if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false)
  43. ioprintf(c1out,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
  44. Pkg.FullName(true).c_str());
  45. else
  46. Cache->GetDepCache()->SetReInstall(Pkg, true);
  47. } else
  48. ioprintf(c1out,_("%s is already the newest version.\n"),
  49. Pkg.FullName(true).c_str());
  50. }
  51. // Install it with autoinstalling enabled (if we not respect the minial
  52. // required deps or the policy)
  53. if (FixBroken == false)
  54. doAutoInstallLater.insert(Pkg);
  55. }
  56. // see if we need to fix the auto-mark flag
  57. // e.g. apt-get install foo
  58. // where foo is marked automatic
  59. if (State.Install() == false &&
  60. (State.Flags & pkgCache::Flag::Auto) &&
  61. _config->FindB("APT::Get::ReInstall",false) == false &&
  62. _config->FindB("APT::Get::Only-Upgrade",false) == false &&
  63. _config->FindB("APT::Get::Download-Only",false) == false)
  64. {
  65. ioprintf(c1out,_("%s set to manually installed.\n"),
  66. Pkg.FullName(true).c_str());
  67. Cache->GetDepCache()->MarkAuto(Pkg,false);
  68. AutoMarkChanged++;
  69. }
  70. }
  71. bool propergateReleaseCandiateSwitching(std::list<std::pair<pkgCache::VerIterator, std::string> > start, std::ostream &out)
  72. {
  73. for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
  74. s != start.end(); ++s)
  75. Cache->GetDepCache()->SetCandidateVersion(s->first);
  76. bool Success = true;
  77. std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > Changed;
  78. for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
  79. s != start.end(); ++s)
  80. {
  81. Changed.push_back(std::make_pair(s->first, pkgCache::VerIterator(*Cache)));
  82. // We continue here even if it failed to enhance the ShowBroken output
  83. Success &= Cache->GetDepCache()->SetCandidateRelease(s->first, s->second, Changed);
  84. }
  85. for (std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::const_iterator c = Changed.begin();
  86. c != Changed.end(); ++c)
  87. {
  88. if (c->second.end() == true)
  89. ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"),
  90. c->first.VerStr(), c->first.RelStr().c_str(), c->first.ParentPkg().FullName(true).c_str());
  91. else if (c->first.ParentPkg()->Group != c->second.ParentPkg()->Group)
  92. {
  93. pkgCache::VerIterator V = (*Cache)[c->first.ParentPkg()].CandidateVerIter(*Cache);
  94. ioprintf(out, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V.VerStr(),
  95. V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), c->second.ParentPkg().FullName(true).c_str());
  96. }
  97. }
  98. return Success;
  99. }
  100. void doAutoInstall() {
  101. for (APT::PackageSet::const_iterator P = doAutoInstallLater.begin();
  102. P != doAutoInstallLater.end(); ++P) {
  103. pkgDepCache::StateCache &State = (*Cache)[P];
  104. if (State.InstBroken() == false && State.InstPolicyBroken() == false)
  105. continue;
  106. Cache->GetDepCache()->MarkInstall(P, true);
  107. }
  108. doAutoInstallLater.clear();
  109. }
  110. };
  111. /*}}}*/
  112. // TryToRemove - Mark a package for removal /*{{{*/
  113. struct TryToRemove {
  114. pkgCacheFile* Cache;
  115. pkgProblemResolver* Fix;
  116. bool PurgePkgs;
  117. TryToRemove(pkgCacheFile &Cache, pkgProblemResolver *PM) : Cache(&Cache), Fix(PM),
  118. PurgePkgs(_config->FindB("APT::Get::Purge", false)) {};
  119. void operator() (pkgCache::VerIterator const &Ver)
  120. {
  121. pkgCache::PkgIterator Pkg = Ver.ParentPkg();
  122. if (Fix != NULL)
  123. {
  124. Fix->Clear(Pkg);
  125. Fix->Protect(Pkg);
  126. Fix->Remove(Pkg);
  127. }
  128. if ((Pkg->CurrentVer == 0 && PurgePkgs == false) ||
  129. (PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled))
  130. {
  131. pkgCache::GrpIterator Grp = Pkg.Group();
  132. pkgCache::PkgIterator P = Grp.PackageList();
  133. for (; P.end() != true; P = Grp.NextPkg(P))
  134. {
  135. if (P == Pkg)
  136. continue;
  137. if (P->CurrentVer != 0 || (PurgePkgs == true && P->CurrentState != pkgCache::State::NotInstalled))
  138. {
  139. // TRANSLATORS: Note, this is not an interactive question
  140. ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
  141. Pkg.FullName(true).c_str(), P.FullName(true).c_str());
  142. break;
  143. }
  144. }
  145. if (P.end() == true)
  146. ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str());
  147. // MarkInstall refuses to install packages on hold
  148. Pkg->SelectedState = pkgCache::State::Hold;
  149. }
  150. else
  151. Cache->GetDepCache()->MarkDelete(Pkg, PurgePkgs);
  152. }
  153. };
  154. /*}}}*/
  155. #endif