packagemanager.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. virtual bool Go(APT::Progress::PackageManager * /*progress*/) {return true;};
  80. virtual bool Go(int /*statusFd*/=-1) {return true;};
  81. virtual void Reset() {};
  82. // the result of the operation
  83. OrderResult Res;
  84. public:
  85. // Main action members
  86. bool GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
  87. pkgRecords *Recs);
  88. // Do the installation
  89. OrderResult DoInstall(APT::Progress::PackageManager *progress);
  90. // compat
  91. APT_DEPRECATED OrderResult DoInstall(int statusFd=-1);
  92. // stuff that needs to be done before the fork() of a library that
  93. // uses apt
  94. OrderResult DoInstallPreFork() {
  95. Res = OrderInstall();
  96. return Res;
  97. };
  98. // stuff that needs to be done after the fork
  99. OrderResult DoInstallPostFork(APT::Progress::PackageManager *progress);
  100. // compat
  101. APT_DEPRECATED OrderResult DoInstallPostFork(int statusFd=-1);
  102. // ?
  103. bool FixMissing();
  104. /** \brief returns all packages dpkg let disappear */
  105. inline std::set<std::string> GetDisappearedPackages() { return disappearedPkgs; };
  106. explicit pkgPackageManager(pkgDepCache *Cache);
  107. virtual ~pkgPackageManager();
  108. private:
  109. void * const d;
  110. enum APT_HIDDEN SmartAction { UNPACK_IMMEDIATE, UNPACK, CONFIGURE };
  111. APT_HIDDEN bool NonLoopingSmart(SmartAction const action, pkgCache::PkgIterator &Pkg,
  112. pkgCache::PkgIterator DepPkg, int const Depth, bool const PkgLoop,
  113. bool * const Bad, bool * const Changed) APT_MUSTCHECK;
  114. };
  115. #endif