You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

185 lines
6.5 KiB

  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. std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > Changed;
  81. for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
  82. s != start.end(); ++s)
  83. {
  84. Changed.push_back(std::make_pair(s->first, pkgCache::VerIterator(*Cache)));
  85. // We continue here even if it failed to enhance the ShowBroken output
  86. Success &= Cache->GetDepCache()->SetCandidateRelease(s->first, s->second, Changed);
  87. }
  88. for (std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::const_iterator c = Changed.begin();
  89. c != Changed.end(); ++c)
  90. {
  91. if (c->second.end() == true)
  92. ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"),
  93. c->first.VerStr(), c->first.RelStr().c_str(), c->first.ParentPkg().FullName(true).c_str());
  94. else if (c->first.ParentPkg()->Group != c->second.ParentPkg()->Group)
  95. {
  96. pkgCache::VerIterator V = (*Cache)[c->first.ParentPkg()].CandidateVerIter(*Cache);
  97. ioprintf(out, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V.VerStr(),
  98. V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), c->second.ParentPkg().FullName(true).c_str());
  99. }
  100. }
  101. return Success;
  102. }
  103. void doAutoInstall() {
  104. for (APT::PackageSet::const_iterator P = doAutoInstallLater.begin();
  105. P != doAutoInstallLater.end(); ++P) {
  106. pkgDepCache::StateCache &State = (*Cache)[P];
  107. if (State.InstBroken() == false && State.InstPolicyBroken() == false)
  108. continue;
  109. Cache->GetDepCache()->MarkInstall(P, true);
  110. }
  111. doAutoInstallLater.clear();
  112. }
  113. };
  114. /*}}}*/
  115. // TryToRemove - Mark a package for removal /*{{{*/
  116. struct TryToRemove {
  117. pkgCacheFile* Cache;
  118. pkgProblemResolver* Fix;
  119. bool PurgePkgs;
  120. TryToRemove(pkgCacheFile &Cache, pkgProblemResolver *PM) : Cache(&Cache), Fix(PM),
  121. PurgePkgs(_config->FindB("APT::Get::Purge", false)) {};
  122. void operator() (pkgCache::VerIterator const &Ver)
  123. {
  124. pkgCache::PkgIterator Pkg = Ver.ParentPkg();
  125. if (Fix != NULL)
  126. {
  127. Fix->Clear(Pkg);
  128. Fix->Protect(Pkg);
  129. Fix->Remove(Pkg);
  130. }
  131. if ((Pkg->CurrentVer == 0 && PurgePkgs == false) ||
  132. (PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled))
  133. {
  134. pkgCache::GrpIterator Grp = Pkg.Group();
  135. pkgCache::PkgIterator P = Grp.PackageList();
  136. for (; P.end() != true; P = Grp.NextPkg(P))
  137. {
  138. if (P == Pkg)
  139. continue;
  140. if (P->CurrentVer != 0 || (PurgePkgs == true && P->CurrentState != pkgCache::State::NotInstalled))
  141. {
  142. // TRANSLATORS: Note, this is not an interactive question
  143. ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
  144. Pkg.FullName(true).c_str(), P.FullName(true).c_str());
  145. break;
  146. }
  147. }
  148. if (P.end() == true)
  149. ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str());
  150. // MarkInstall refuses to install packages on hold
  151. Pkg->SelectedState = pkgCache::State::Hold;
  152. }
  153. else
  154. Cache->GetDepCache()->MarkDelete(Pkg, PurgePkgs);
  155. }
  156. };
  157. /*}}}*/
  158. #endif