packagemanager.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Package Manager - Abstacts the package manager
  5. Three steps are
  6. - Aquiration of archives (stores the list of final file names)
  7. - Sorting of operations
  8. - Invokation of package manager
  9. This is the final stage when the package cache entities get converted
  10. into file names and the state stored in a DepCache is transformed
  11. into a series of operations.
  12. In the final scheme of things this may serve as a director class to
  13. access the actual install methods based on the file type being
  14. installed.
  15. ##################################################################### */
  16. /*}}}*/
  17. #ifndef PKGLIB_PACKAGEMANAGER_H
  18. #define PKGLIB_PACKAGEMANAGER_H
  19. #include <apt-pkg/pkgcache.h>
  20. #include <apt-pkg/init.h>
  21. #include <apt-pkg/edsp.h>
  22. #include <apt-pkg/macros.h>
  23. #include <string>
  24. #include <set>
  25. #ifndef APT_10_CLEANER_HEADERS
  26. #include <apt-pkg/install-progress.h>
  27. #include <iostream>
  28. #endif
  29. #ifndef APT_8_CLEANER_HEADERS
  30. #include <apt-pkg/depcache.h>
  31. using std::string;
  32. #endif
  33. class pkgAcquire;
  34. class pkgDepCache;
  35. class pkgSourceList;
  36. class pkgOrderList;
  37. class pkgRecords;
  38. class OpProgress;
  39. class pkgPackageManager;
  40. namespace APT {
  41. namespace Progress {
  42. class PackageManager;
  43. }
  44. }
  45. class pkgPackageManager : protected pkgCache::Namespace
  46. {
  47. public:
  48. enum OrderResult {Completed,Failed,Incomplete};
  49. static bool SigINTStop;
  50. protected:
  51. std::string *FileNames;
  52. pkgDepCache &Cache;
  53. pkgOrderList *List;
  54. bool Debug;
  55. bool NoImmConfigure;
  56. bool ImmConfigureAll;
  57. /** \brief saves packages dpkg let disappear
  58. This way APT can retreat from trying to configure these
  59. packages later on and a front-end can choose to display a
  60. notice to inform the user about these disappears.
  61. */
  62. std::set<std::string> disappearedPkgs;
  63. void ImmediateAdd(PkgIterator P, bool UseInstallVer, unsigned const int &Depth = 0);
  64. virtual OrderResult OrderInstall();
  65. bool CheckRConflicts(PkgIterator Pkg,DepIterator Dep,const char *Ver);
  66. bool CheckRBreaks(PkgIterator const &Pkg,DepIterator Dep,const char * const Ver);
  67. bool CreateOrderList();
  68. // Analysis helpers
  69. bool DepAlwaysTrue(DepIterator D) APT_PURE;
  70. // Install helpers
  71. bool ConfigureAll();
  72. bool SmartConfigure(PkgIterator Pkg, int const Depth) APT_MUSTCHECK;
  73. //FIXME: merge on abi break
  74. bool SmartUnPack(PkgIterator Pkg) APT_MUSTCHECK;
  75. bool SmartUnPack(PkgIterator Pkg, bool const Immediate, int const Depth) APT_MUSTCHECK;
  76. bool SmartRemove(PkgIterator Pkg) APT_MUSTCHECK;
  77. bool EarlyRemove(PkgIterator Pkg, DepIterator const * const Dep) APT_MUSTCHECK;
  78. APT_DEPRECATED bool EarlyRemove(PkgIterator Pkg) APT_MUSTCHECK;
  79. // The Actual installation implementation
  80. virtual bool Install(PkgIterator /*Pkg*/,std::string /*File*/) {return false;};
  81. virtual bool Configure(PkgIterator /*Pkg*/) {return false;};
  82. virtual bool Remove(PkgIterator /*Pkg*/,bool /*Purge*/=false) {return false;};
  83. virtual bool Go(APT::Progress::PackageManager * /*progress*/) {return true;};
  84. APT_DEPRECATED_MSG("Use overload with explicit progress manager") virtual bool Go(int /*statusFd*/=-1) {return true;};
  85. virtual void Reset() {};
  86. // the result of the operation
  87. OrderResult Res;
  88. public:
  89. // Main action members
  90. bool GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
  91. pkgRecords *Recs);
  92. // Do the installation
  93. OrderResult DoInstall(APT::Progress::PackageManager *progress);
  94. // compat
  95. APT_DEPRECATED_MSG("Use APT::Progress::PackageManager subclass instead of fd") OrderResult DoInstall(int statusFd=-1);
  96. friend bool EIPP::OrderInstall(char const * const planner, pkgPackageManager * const PM,
  97. unsigned int const version, OpProgress * const Progress);
  98. friend bool EIPP::ReadResponse(int const input, pkgPackageManager * const PM,
  99. OpProgress * const Progress);
  100. // stuff that needs to be done before the fork() of a library that
  101. // uses apt
  102. OrderResult DoInstallPreFork() {
  103. Res = OrderInstall();
  104. return Res;
  105. };
  106. // stuff that needs to be done after the fork
  107. OrderResult DoInstallPostFork(APT::Progress::PackageManager *progress);
  108. // compat
  109. APT_DEPRECATED_MSG("Use APT::Progress::PackageManager subclass instead of fd") OrderResult DoInstallPostFork(int statusFd=-1);
  110. // ?
  111. bool FixMissing();
  112. /** \brief returns all packages dpkg let disappear */
  113. inline std::set<std::string> GetDisappearedPackages() { return disappearedPkgs; };
  114. explicit pkgPackageManager(pkgDepCache *Cache);
  115. virtual ~pkgPackageManager();
  116. private:
  117. void * const d;
  118. enum APT_HIDDEN SmartAction { UNPACK_IMMEDIATE, UNPACK, CONFIGURE };
  119. APT_HIDDEN bool NonLoopingSmart(SmartAction const action, pkgCache::PkgIterator &Pkg,
  120. pkgCache::PkgIterator DepPkg, int const Depth, bool const PkgLoop,
  121. bool * const Bad, bool * const Changed) APT_MUSTCHECK;
  122. };
  123. #endif