policy.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Package Version Policy implementation
  5. This implements the more advanced 'Version 4' APT policy engine. The
  6. standard 'Version 0' engine is included inside the DepCache which is
  7. it's historical location.
  8. The V4 engine allows the user to completly control all aspects of
  9. version selection. There are three primary means to choose a version
  10. * Selection by version match
  11. * Selection by Release file match
  12. * Selection by origin server
  13. Each package may be 'pinned' with a single criteria, which will ultimately
  14. result in the selection of a single version, or no version, for each
  15. package.
  16. Furthermore, the default selection can be influenced by specifying
  17. the ordering of package files. The order is derived by reading the
  18. package file preferences and assigning a priority to each package
  19. file.
  20. A special flag may be set to indicate if no version should be returned
  21. if no matching versions are found, otherwise the default matching
  22. rules are used to locate a hit.
  23. ##################################################################### */
  24. /*}}}*/
  25. #ifndef PKGLIB_POLICY_H
  26. #define PKGLIB_POLICY_H
  27. #include <apt-pkg/depcache.h>
  28. #include <apt-pkg/pkgcache.h>
  29. #include <apt-pkg/cacheiterators.h>
  30. #include <apt-pkg/versionmatch.h>
  31. #include <vector>
  32. #include <string>
  33. #ifndef APT_8_CLEANER_HEADERS
  34. using std::vector;
  35. #endif
  36. class pkgPolicy : public pkgDepCache::Policy
  37. {
  38. protected:
  39. struct Pin
  40. {
  41. pkgVersionMatch::MatchType Type;
  42. std::string Data;
  43. signed short Priority;
  44. Pin() : Type(pkgVersionMatch::None), Priority(0) {};
  45. };
  46. struct PkgPin : Pin
  47. {
  48. std::string Pkg;
  49. explicit PkgPin(std::string const &Pkg) : Pin(), Pkg(Pkg) {};
  50. };
  51. Pin *Pins;
  52. Pin *VerPins;
  53. signed short *PFPriority;
  54. std::vector<Pin> Defaults;
  55. std::vector<PkgPin> Unmatched;
  56. pkgCache *Cache;
  57. bool StatusOverride;
  58. public:
  59. // Things for manipulating pins
  60. void CreatePin(pkgVersionMatch::MatchType Type,std::string Pkg,
  61. std::string Data,signed short Priority);
  62. pkgCache::VerIterator GetMatch(pkgCache::PkgIterator const &Pkg);
  63. // Things for the cache interface.
  64. virtual pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
  65. virtual signed short GetPriority(pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
  66. virtual signed short GetPriority(pkgCache::VerIterator const &Ver, bool ConsiderFiles = true) APT_OVERRIDE;
  67. virtual signed short GetPriority(pkgCache::PkgFileIterator const &File) APT_OVERRIDE;
  68. bool InitDefaults();
  69. explicit pkgPolicy(pkgCache *Owner);
  70. virtual ~pkgPolicy();
  71. private:
  72. void * const d;
  73. };
  74. bool ReadPinFile(pkgPolicy &Plcy, std::string File = "");
  75. bool ReadPinDir(pkgPolicy &Plcy, std::string Dir = "");
  76. #endif