dpkgpm.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. APT_HIDDEN void handleCrossUpgradeAction(std::string const &pkgname);
  45. protected:
  46. int pkgFailures;
  47. // progress reporting
  48. struct DpkgState
  49. {
  50. const char *state; // the dpkg state (e.g. "unpack")
  51. const char *str; // the human readable translation of the state
  52. };
  53. // the dpkg states that the pkg will run through, the string is
  54. // the package, the vector contains the dpkg states that the package
  55. // will go through
  56. std::map<std::string,std::vector<struct DpkgState> > PackageOps;
  57. // the dpkg states that are already done; the string is the package
  58. // the int is the state that is already done (e.g. a package that is
  59. // going to be install is already in state "half-installed")
  60. std::map<std::string,unsigned int> PackageOpsDone;
  61. // progress reporting
  62. unsigned int PackagesDone;
  63. unsigned int PackagesTotal;
  64. public:
  65. struct Item
  66. {
  67. enum Ops {Install, Configure, Remove, Purge, ConfigurePending, TriggersPending,
  68. RemovePending, PurgePending } Op;
  69. std::string File;
  70. PkgIterator Pkg;
  71. Item(Ops Op,PkgIterator Pkg,std::string File = "") : Op(Op),
  72. File(File), Pkg(Pkg) {};
  73. Item() {};
  74. };
  75. protected:
  76. std::vector<Item> List;
  77. // Helpers
  78. bool RunScriptsWithPkgs(const char *Cnf);
  79. APT_DEPRECATED_MSG("Use SendPkgInfo with the version as parameter instead") bool SendV2Pkgs(FILE *F);
  80. bool SendPkgsInfo(FILE * const F, unsigned int const &Version);
  81. void WriteHistoryTag(std::string const &tag, std::string value);
  82. std::string ExpandShortPackageName(pkgDepCache &Cache,
  83. const std::string &short_pkgname);
  84. // Terminal progress
  85. void SendTerminalProgress(float percentage);
  86. // apport integration
  87. void WriteApportReport(const char *pkgpath, const char *errormsg);
  88. // dpkg log
  89. bool OpenLog();
  90. bool CloseLog();
  91. // helper
  92. void BuildPackagesProgressMap();
  93. void StartPtyMagic();
  94. void SetupSlavePtyMagic();
  95. void StopPtyMagic();
  96. // input processing
  97. void DoStdin(int master);
  98. void DoTerminalPty(int master);
  99. void DoDpkgStatusFd(int statusfd);
  100. void ProcessDpkgStatusLine(char *line);
  101. // The Actual installation implementation
  102. virtual bool Install(PkgIterator Pkg,std::string File) APT_OVERRIDE;
  103. virtual bool Configure(PkgIterator Pkg) APT_OVERRIDE;
  104. virtual bool Remove(PkgIterator Pkg,bool Purge = false) APT_OVERRIDE;
  105. virtual bool Go(APT::Progress::PackageManager *progress) APT_OVERRIDE;
  106. APT_DEPRECATED_MSG("Use overload with explicit progress manager") virtual bool Go(int StatusFd=-1) APT_OVERRIDE;
  107. virtual void Reset() APT_OVERRIDE;
  108. public:
  109. pkgDPkgPM(pkgDepCache *Cache);
  110. virtual ~pkgDPkgPM();
  111. APT_HIDDEN static bool ExpandPendingCalls(std::vector<Item> &List, pkgDepCache &Cache);
  112. };
  113. void SigINT(int sig);
  114. #endif