private-install.h 6.8 KB

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