private-install.h 6.9 KB

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