dpkgpm.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: dpkgpm.h,v 1.8 2001/05/07 05:05:13 jgg Exp $
  4. /* ######################################################################
  5. DPKG Package Manager - Provide an interface to dpkg
  6. ##################################################################### */
  7. /*}}}*/
  8. #ifndef PKGLIB_DPKGPM_H
  9. #define PKGLIB_DPKGPM_H
  10. #include <apt-pkg/packagemanager.h>
  11. #include <vector>
  12. #include <map>
  13. #include <stdio.h>
  14. #include <apt-pkg/macros.h>
  15. #include <apt-pkg/init.h>
  16. #ifndef APT_8_CLEANER_HEADERS
  17. using std::vector;
  18. using std::map;
  19. #endif
  20. class pkgDPkgPMPrivate;
  21. class pkgDPkgPM : public pkgPackageManager
  22. {
  23. private:
  24. pkgDPkgPMPrivate *d;
  25. /** \brief record the disappear action and handle accordingly
  26. dpkg let packages disappear then they have no files any longer and
  27. nothing depends on them. We need to collect this as dpkg as well as
  28. APT doesn't know beforehand that the package will disappear, so the
  29. only possible option is to tell the user afterwards about it.
  30. To enhance the experience we also try to forward the auto-install
  31. flag so the disappear-causer(s) are not autoremoved next time -
  32. for the transfer to happen the disappeared version needs to depend
  33. on the package the flag should be forwarded to and this package
  34. needs to declare a Replaces on the disappeared package.
  35. \param pkgname Name of the package that disappeared
  36. */
  37. void handleDisappearAction(std::string const &pkgname);
  38. protected:
  39. int pkgFailures;
  40. // progress reporting
  41. struct DpkgState
  42. {
  43. const char *state; // the dpkg state (e.g. "unpack")
  44. const char *str; // the human readable translation of the state
  45. };
  46. // the dpkg states that the pkg will run through, the string is
  47. // the package, the vector contains the dpkg states that the package
  48. // will go through
  49. std::map<std::string,std::vector<struct DpkgState> > PackageOps;
  50. // the dpkg states that are already done; the string is the package
  51. // the int is the state that is already done (e.g. a package that is
  52. // going to be install is already in state "half-installed")
  53. std::map<std::string,unsigned int> PackageOpsDone;
  54. // progress reporting
  55. unsigned int PackagesDone;
  56. unsigned int PackagesTotal;
  57. struct Item
  58. {
  59. enum Ops {Install, Configure, Remove, Purge, ConfigurePending, TriggersPending} Op;
  60. std::string File;
  61. PkgIterator Pkg;
  62. Item(Ops Op,PkgIterator Pkg,std::string File = "") : Op(Op),
  63. File(File), Pkg(Pkg) {};
  64. Item() {};
  65. };
  66. std::vector<Item> List;
  67. // Helpers
  68. bool RunScriptsWithPkgs(const char *Cnf);
  69. __deprecated bool SendV2Pkgs(FILE *F);
  70. bool SendPkgsInfo(FILE * const F, unsigned int const &Version);
  71. void WriteHistoryTag(std::string const &tag, std::string value);
  72. std::string ExpandShortPackageName(pkgDepCache &Cache,
  73. const std::string &short_pkgname);
  74. // Terminal progress
  75. void SendTerminalProgress(float percentage);
  76. // apport integration
  77. void WriteApportReport(const char *pkgpath, const char *errormsg);
  78. // dpkg log
  79. bool OpenLog();
  80. bool CloseLog();
  81. // helper
  82. void BuildPackagesProgressMap();
  83. void StartPtyMagic();
  84. void StopPtyMagic();
  85. // input processing
  86. void DoStdin(int master);
  87. void DoTerminalPty(int master);
  88. void DoDpkgStatusFd(int statusfd);
  89. void ProcessDpkgStatusLine(char *line);
  90. #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
  91. void DoDpkgStatusFd(int statusfd, int unused) {
  92. DoDpkgStatusFd(statusfd);
  93. }
  94. void ProcessDpkgStatusLine(int unused, char *line) {
  95. ProcessDpkgStatusLine(line);
  96. }
  97. #endif
  98. // The Actuall installation implementation
  99. virtual bool Install(PkgIterator Pkg,std::string File);
  100. virtual bool Configure(PkgIterator Pkg);
  101. virtual bool Remove(PkgIterator Pkg,bool Purge = false);
  102. #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
  103. virtual bool Go(APT::Progress::PackageManager *progress);
  104. #else
  105. virtual bool Go(int StatusFd=-1);
  106. bool GoNoABIBreak(APT::Progress::PackageManager *progress);
  107. #endif
  108. virtual void Reset();
  109. public:
  110. pkgDPkgPM(pkgDepCache *Cache);
  111. virtual ~pkgDPkgPM();
  112. };
  113. void SigINT(int sig);
  114. #endif