dpkgpm.h 4.4 KB

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