packagemanager.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/macros.h>
  22. #include <string>
  23. #include <set>
  24. #ifndef APT_10_CLEANER_HEADERS
  25. #include <apt-pkg/install-progress.h>
  26. #include <iostream>
  27. #endif
  28. #ifndef APT_8_CLEANER_HEADERS
  29. #include <apt-pkg/depcache.h>
  30. using std::string;
  31. #endif
  32. class pkgAcquire;
  33. class pkgDepCache;
  34. class pkgSourceList;
  35. class pkgOrderList;
  36. class pkgRecords;
  37. namespace APT {
  38. namespace Progress {
  39. class PackageManager;
  40. }
  41. }
  42. class pkgPackageManager : protected pkgCache::Namespace
  43. {
  44. public:
  45. enum OrderResult {Completed,Failed,Incomplete};
  46. static bool SigINTStop;
  47. protected:
  48. std::string *FileNames;
  49. pkgDepCache &Cache;
  50. pkgOrderList *List;
  51. bool Debug;
  52. bool NoImmConfigure;
  53. bool ImmConfigureAll;
  54. /** \brief saves packages dpkg let disappear
  55. This way APT can retreat from trying to configure these
  56. packages later on and a frontend can choose to display a
  57. notice to inform the user about these disappears.
  58. */
  59. std::set<std::string> disappearedPkgs;
  60. void ImmediateAdd(PkgIterator P, bool UseInstallVer, unsigned const int &Depth = 0);
  61. virtual OrderResult OrderInstall();
  62. bool CheckRConflicts(PkgIterator Pkg,DepIterator Dep,const char *Ver);
  63. bool CreateOrderList();
  64. // Analysis helpers
  65. bool DepAlwaysTrue(DepIterator D) APT_PURE;
  66. // Install helpers
  67. bool ConfigureAll();
  68. bool SmartConfigure(PkgIterator Pkg, int const Depth) APT_MUSTCHECK;
  69. //FIXME: merge on abi break
  70. bool SmartUnPack(PkgIterator Pkg) APT_MUSTCHECK;
  71. bool SmartUnPack(PkgIterator Pkg, bool const Immediate, int const Depth) APT_MUSTCHECK;
  72. bool SmartRemove(PkgIterator Pkg) APT_MUSTCHECK;
  73. bool EarlyRemove(PkgIterator Pkg, DepIterator const * const Dep) APT_MUSTCHECK;
  74. APT_DEPRECATED bool EarlyRemove(PkgIterator Pkg) APT_MUSTCHECK;
  75. // The Actual installation implementation
  76. virtual bool Install(PkgIterator /*Pkg*/,std::string /*File*/) {return false;};
  77. virtual bool Configure(PkgIterator /*Pkg*/) {return false;};
  78. virtual bool Remove(PkgIterator /*Pkg*/,bool /*Purge*/=false) {return false;};
  79. #if APT_PKG_ABI >= 413
  80. virtual bool Go(APT::Progress::PackageManager * /*progress*/) {return true;};
  81. #endif
  82. virtual bool Go(int /*statusFd*/=-1) {return true;};
  83. virtual void Reset() {};
  84. // the result of the operation
  85. OrderResult Res;
  86. public:
  87. // Main action members
  88. bool GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
  89. pkgRecords *Recs);
  90. // Do the installation
  91. #if APT_PKG_ABI >= 413
  92. OrderResult DoInstall(APT::Progress::PackageManager *progress);
  93. // compat
  94. APT_DEPRECATED OrderResult DoInstall(int statusFd=-1);
  95. #else
  96. OrderResult DoInstall(int statusFd=-1);
  97. #endif
  98. // stuff that needs to be done before the fork() of a library that
  99. // uses apt
  100. OrderResult DoInstallPreFork() {
  101. Res = OrderInstall();
  102. return Res;
  103. };
  104. #if APT_PKG_ABI >= 413
  105. // stuff that needs to be done after the fork
  106. OrderResult DoInstallPostFork(APT::Progress::PackageManager *progress);
  107. // compat
  108. APT_DEPRECATED OrderResult DoInstallPostFork(int statusFd=-1);
  109. #else
  110. OrderResult DoInstallPostFork(int statusFd=-1);
  111. #endif
  112. // ?
  113. bool FixMissing();
  114. /** \brief returns all packages dpkg let disappear */
  115. inline std::set<std::string> GetDisappearedPackages() { return disappearedPkgs; };
  116. explicit pkgPackageManager(pkgDepCache *Cache);
  117. virtual ~pkgPackageManager();
  118. private:
  119. void *d;
  120. enum APT_HIDDEN SmartAction { UNPACK_IMMEDIATE, UNPACK, CONFIGURE };
  121. APT_HIDDEN bool NonLoopingSmart(SmartAction const action, pkgCache::PkgIterator &Pkg,
  122. pkgCache::PkgIterator DepPkg, int const Depth, bool const PkgLoop,
  123. bool * const Bad, bool * const Changed) APT_MUSTCHECK;
  124. };
  125. #endif