edspindexfile.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. The scenario file is designed to work as an intermediate file between
  5. APT and the resolver. Its on propose very similar to a dpkg status file
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #include <config.h>
  10. #include <apt-pkg/edspindexfile.h>
  11. #include <apt-pkg/edsplistparser.h>
  12. #include <apt-pkg/error.h>
  13. #include <apt-pkg/fileutl.h>
  14. #include <apt-pkg/indexfile.h>
  15. #include <apt-pkg/pkgcache.h>
  16. #include <apt-pkg/pkgrecords.h>
  17. #include <stddef.h>
  18. #include <unistd.h>
  19. #include <string>
  20. /*}}}*/
  21. // EDSP-like Index /*{{{*/
  22. edspLikeIndex::edspLikeIndex(std::string const &File) : pkgDebianIndexRealFile(File, true)
  23. {
  24. }
  25. std::string edspLikeIndex::GetArchitecture() const
  26. {
  27. return std::string();
  28. }
  29. bool edspLikeIndex::HasPackages() const
  30. {
  31. return true;
  32. }
  33. bool edspLikeIndex::Exists() const
  34. {
  35. return true;
  36. }
  37. uint8_t edspLikeIndex::GetIndexFlags() const
  38. {
  39. return 0;
  40. }
  41. bool edspLikeIndex::OpenListFile(FileFd &Pkg, std::string const &FileName)
  42. {
  43. if (FileName.empty() == false && FileName != "/nonexistent/stdin")
  44. return pkgDebianIndexRealFile::OpenListFile(Pkg, FileName);
  45. if (Pkg.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly) == false)
  46. return _error->Error("Problem opening %s",FileName.c_str());
  47. return true;
  48. }
  49. /*}}}*/
  50. // EDSP Index /*{{{*/
  51. edspIndex::edspIndex(std::string const &File) : edspLikeIndex(File)
  52. {
  53. }
  54. std::string edspIndex::GetComponent() const
  55. {
  56. return "edsp";
  57. }
  58. pkgCacheListParser * edspIndex::CreateListParser(FileFd &Pkg)
  59. {
  60. if (Pkg.IsOpen() == false)
  61. return NULL;
  62. _error->PushToStack();
  63. pkgCacheListParser * const Parser = new edspListParser(&Pkg);
  64. bool const newError = _error->PendingError();
  65. _error->MergeWithStack();
  66. return newError ? NULL : Parser;
  67. }
  68. /*}}}*/
  69. // EIPP Index /*{{{*/
  70. eippIndex::eippIndex(std::string const &File) : edspLikeIndex(File)
  71. {
  72. }
  73. std::string eippIndex::GetComponent() const
  74. {
  75. return "eipp";
  76. }
  77. pkgCacheListParser * eippIndex::CreateListParser(FileFd &Pkg)
  78. {
  79. if (Pkg.IsOpen() == false)
  80. return NULL;
  81. _error->PushToStack();
  82. pkgCacheListParser * const Parser = new eippListParser(&Pkg);
  83. bool const newError = _error->PendingError();
  84. _error->MergeWithStack();
  85. return newError ? NULL : Parser;
  86. }
  87. /*}}}*/
  88. // Index File types for APT /*{{{*/
  89. class APT_HIDDEN edspIFType: public pkgIndexFile::Type
  90. {
  91. public:
  92. virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &) const APT_OVERRIDE
  93. {
  94. // we don't have a record parser for this type as the file is not presistent
  95. return NULL;
  96. };
  97. edspIFType() {Label = "EDSP scenario file";};
  98. };
  99. APT_HIDDEN edspIFType _apt_Edsp;
  100. const pkgIndexFile::Type *edspIndex::GetType() const
  101. {
  102. return &_apt_Edsp;
  103. }
  104. class APT_HIDDEN eippIFType: public pkgIndexFile::Type
  105. {
  106. public:
  107. virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &) const APT_OVERRIDE
  108. {
  109. // we don't have a record parser for this type as the file is not presistent
  110. return NULL;
  111. };
  112. eippIFType() {Label = "EIPP scenario file";};
  113. };
  114. APT_HIDDEN eippIFType _apt_Eipp;
  115. const pkgIndexFile::Type *eippIndex::GetType() const
  116. {
  117. return &_apt_Eipp;
  118. }
  119. /*}}}*/
  120. edspLikeIndex::~edspLikeIndex() {}
  121. edspIndex::~edspIndex() {}
  122. eippIndex::~eippIndex() {}