dpkgpm.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. using std::vector;
  15. using std::map;
  16. class pkgDPkgPM : public pkgPackageManager
  17. {
  18. private:
  19. bool stdin_is_dev_null;
  20. // the buffer we use for the dpkg status-fd reading
  21. char dpkgbuf[1024];
  22. int dpkgbuf_pos;
  23. FILE *term_out;
  24. FILE *history_out;
  25. string dpkg_error;
  26. /** \brief record the disappear action and handle accordingly
  27. dpkg let packages disappear then they have no files any longer and
  28. nothing depends on them. We need to collect this as dpkg as well as
  29. APT doesn't know beforehand that the package will disappear, so the
  30. only possible option is to tell the user afterwards about it.
  31. To enhance the experience we also try to forward the auto-install
  32. flag so the disappear-causer(s) are not autoremoved next time -
  33. for the transfer to happen the disappeared version needs to depend
  34. on the package the flag should be forwarded to and this package
  35. needs to declare a Replaces on the disappeared package.
  36. \param pkgname Name of the package that disappeared
  37. */
  38. void handleDisappearAction(string const &pkgname);
  39. protected:
  40. int pkgFailures;
  41. // progress reporting
  42. struct DpkgState
  43. {
  44. const char *state; // the dpkg state (e.g. "unpack")
  45. const char *str; // the human readable translation of the state
  46. };
  47. // the dpkg states that the pkg will run through, the string is
  48. // the package, the vector contains the dpkg states that the package
  49. // will go through
  50. map<string,vector<struct DpkgState> > PackageOps;
  51. // the dpkg states that are already done; the string is the package
  52. // the int is the state that is already done (e.g. a package that is
  53. // going to be install is already in state "half-installed")
  54. map<string,unsigned int> PackageOpsDone;
  55. // progress reporting
  56. unsigned int PackagesDone;
  57. unsigned int PackagesTotal;
  58. struct Item
  59. {
  60. enum Ops {Install, Configure, Remove, Purge, ConfigurePending, TriggersPending} Op;
  61. string File;
  62. PkgIterator Pkg;
  63. Item(Ops Op,PkgIterator Pkg,string File = "") : Op(Op),
  64. File(File), Pkg(Pkg) {};
  65. Item() {};
  66. };
  67. vector<Item> List;
  68. // Helpers
  69. bool RunScriptsWithPkgs(const char *Cnf);
  70. bool SendV2Pkgs(FILE *F);
  71. void WriteHistoryTag(string const &tag, string value);
  72. // apport integration
  73. void WriteApportReport(const char *pkgpath, const char *errormsg);
  74. // dpkg log
  75. bool OpenLog();
  76. bool CloseLog();
  77. // input processing
  78. void DoStdin(int master);
  79. void DoTerminalPty(int master);
  80. void DoDpkgStatusFd(int statusfd, int OutStatusFd);
  81. void ProcessDpkgStatusLine(int OutStatusFd, char *line);
  82. // The Actuall installation implementation
  83. virtual bool Install(PkgIterator Pkg,string File);
  84. virtual bool Configure(PkgIterator Pkg);
  85. virtual bool Remove(PkgIterator Pkg,bool Purge = false);
  86. virtual bool Go(int StatusFd=-1);
  87. virtual void Reset();
  88. public:
  89. pkgDPkgPM(pkgDepCache *Cache);
  90. virtual ~pkgDPkgPM();
  91. };
  92. #endif