private-install.h 6.6 KB

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